Fix remote clustering after moving local addr code to interface

The code to retrieve the cluster local address has moved to the
ovsdb-cluster interface and there was some fallout from that.

Also clean up some residue after the charm name change.

Add functional test to Travis.
This commit is contained in:
Frode Nordahl 2019-10-11 10:52:44 +02:00
parent 3d7fcaca0f
commit 8e0ac64d6a
No known key found for this signature in database
GPG Key ID: 6A5D59A3BA48373F
11 changed files with 72 additions and 30 deletions

View File

@ -1,7 +1,8 @@
sudo: true sudo: true
dist: xenial dist: xenial
language: python language: python
install: pip install tox-travis install:
- pip install tox-travis
matrix: matrix:
include: include:
- name: "Python 3.6" - name: "Python 3.6"
@ -10,5 +11,26 @@ matrix:
- name: "Python 3.7" - name: "Python 3.7"
python: 3.7 python: 3.7
env: ENV=pep8,py3 env: ENV=pep8,py3
- name: "Functional test"
env: ENV=func-smoke
script: script:
- tox -c tox.ini -e $ENV - if [ $ENV = 'func-smoke' ]; then
sudo apt update;
sudo apt install -y distro-info;
sudo apt remove -y --purge lxd lxd-client;
sudo snap install lxd;
sudo snap install juju --classic;
sudo sh -c 'echo PATH=/snap/bin:$PATH >> /etc/environment';
sudo lxd waitready;
sudo lxd init --auto;
sudo usermod -a -G lxd travis;
sudo su travis -c 'juju bootstrap --no-gui localhost';
echo "export PATH=$PATH;cd $(pwd)" > $HOME/saved_path;
sudo su - travis -c "source $HOME/saved_path; tox -e build";
sudo su - travis -c "source $HOME/saved_path; tox -c build/builds/ovn-central/tox.ini -e $ENV -- --log DEBUG";
else
tox -c tox.ini -e $ENV;
fi
- if [ $ENV = 'func-smoke' ]; then
sudo su travis -c 'juju status -m $(juju models --format yaml|grep "^- name:.*zaza"|cut -f2 -d/)';
fi

View File

@ -49,7 +49,7 @@ def ovn_ca_cert(cls):
class OVNCentralCharm(charms_openstack.charm.OpenStackCharm): class OVNCentralCharm(charms_openstack.charm.OpenStackCharm):
release = 'stein' release = 'stein'
name = 'ovn' name = 'ovn-central'
packages = ['ovn-central'] packages = ['ovn-central']
services = ['ovn-central'] services = ['ovn-central']
required_relations = ['certificates'] required_relations = ['certificates']

View File

@ -46,7 +46,8 @@ def certificates_in_config_tls():
@reactive.when('config.rendered', @reactive.when('config.rendered',
'certificates.connected', 'certificates.connected',
'certificates.available', 'certificates.available',
'leadership.is_leader') 'leadership.is_leader',
'ovsdb-peer.connected',)
def announce_leader_ready(): def announce_leader_ready():
"""Announce leader is ready. """Announce leader is ready.
@ -57,18 +58,27 @@ def announce_leader_ready():
Signal to our peers that they should render configurations and start their Signal to our peers that they should render configurations and start their
database processes. database processes.
""" """
# although this is done in the interface, explicitly do it in the same
# breath as updating the leader settings as our peers will immediately
# look for it
ovsdb_peer = reactive.endpoint_from_flag('ovsdb-peer.connected')
ovsdb_peer.publish_cluster_local_addr()
# FIXME use the OVSDB cluster and/or server IDs here? # FIXME use the OVSDB cluster and/or server IDs here?
leadership.leader_set({'ready': True}) leadership.leader_set({'ready': True})
@reactive.when_not('leadership.set.ready') @reactive.when_not('leadership.set.ready')
@reactive.when('charm.installed', 'leadership.is_leader') @reactive.when('charm.installed', 'leadership.is_leader',
'ovsdb-peer.connected')
def initialize_ovsdbs(): def initialize_ovsdbs():
ovsdb_peer = reactive.endpoint_from_flag('ovsdb-peer.connected')
with charm.provide_charm_instance() as ovn_charm: with charm.provide_charm_instance() as ovn_charm:
# this will render the ``/etc/default/ovn-central`` file without # ovsdb_peer at connected state will not provide remote addresses
# configuration for the cluster remote addresses which in turn # for the cluster. this will render the ``/etc/default/ovn-central``
# leads ``ovn-ctl`` on the path to initializing a new cluster # file without configuration for the cluster remote addresses which
ovn_charm.render_with_interfaces([]) # in turn leads ``ovn-ctl`` on the path to initializing a new cluster
ovn_charm.render_with_interfaces([ovsdb_peer])
if ovn_charm.enable_services(): if ovn_charm.enable_services():
# belated enablement of default certificates handler due to the # belated enablement of default certificates handler due to the
# ``ovsdb-server`` processes must have finished database # ``ovsdb-server`` processes must have finished database

View File

@ -3,7 +3,7 @@
############################################################################### ###############################################################################
# [ WARNING ] # [ WARNING ]
# Configuration file maintained by Juju. Local changes may be overwritten. # Configuration file maintained by Juju. Local changes may be overwritten.
# Configuration managed by neutron-openvswitch charm # Configuration managed by ovn-central charm
############################################################################### ###############################################################################
# FORCE_COREFILES: If 'yes' then core files will be enabled. # FORCE_COREFILES: If 'yes' then core files will be enabled.
@ -16,7 +16,7 @@ OVN_CTL_OPTS="
--db-nb-cluster-local-addr={{ ovsdb_peer.cluster_local_addr }} --db-nb-cluster-local-addr={{ ovsdb_peer.cluster_local_addr }}
--db-nb-cluster-local-port={{ ovsdb_peer.db_nb_cluster_port }} --db-nb-cluster-local-port={{ ovsdb_peer.db_nb_cluster_port }}
--db-nb-cluster-local-proto=ssl --db-nb-cluster-local-proto=ssl
{%if ovsdb_peer %} {%if ovsdb_peer and ovsdb_peer.cluster_remote_addrs %}
--ovn-nb-db-ssl-key={{ options.ovn_key }} --ovn-nb-db-ssl-key={{ options.ovn_key }}
--ovn-nb-db-ssl-cert={{ options.ovn_cert }} --ovn-nb-db-ssl-cert={{ options.ovn_cert }}
--ovn-nb-db-ssl-ca-cert={{ options.ovn_ca_cert }} --ovn-nb-db-ssl-ca-cert={{ options.ovn_ca_cert }}
@ -28,7 +28,7 @@ OVN_CTL_OPTS="
--db-sb-cluster-local-addr={{ ovsdb_peer.cluster_local_addr }} --db-sb-cluster-local-addr={{ ovsdb_peer.cluster_local_addr }}
--db-sb-cluster-local-port={{ ovsdb_peer.db_sb_cluster_port }} --db-sb-cluster-local-port={{ ovsdb_peer.db_sb_cluster_port }}
--db-sb-cluster-local-proto=ssl --db-sb-cluster-local-proto=ssl
{%if ovsdb_peer %} {%if ovsdb_peer and ovsdb_peer.cluster_remote_addrs %}
--ovn-sb-db-ssl-key={{ options.ovn_key }} --ovn-sb-db-ssl-key={{ options.ovn_key }}
--ovn-sb-db-ssl-cert={{ options.ovn_cert }} --ovn-sb-db-ssl-cert={{ options.ovn_cert }}
--ovn-sb-db-ssl-ca-cert={{ options.ovn_ca_cert }} --ovn-sb-db-ssl-ca-cert={{ options.ovn_ca_cert }}

View File

@ -8,4 +8,4 @@ flake8>=2.2.4,<=2.4.1
stestr>=2.2.0 stestr>=2.2.0
requests>=2.18.4 requests>=2.18.4
git+https://github.com/openstack-charmers/zaza.git#egg=zaza git+https://github.com/openstack-charmers/zaza.git#egg=zaza
git+file:///home/frode/Projects/OpenStack/openstack-charmers/zaza-openstack-tests@add-ovn#egg=zaza.openstack git+https://github.com/openstack-charmers/zaza-openstack-tests.git@add-ovn#egg=zaza.openstack

View File

@ -2,7 +2,7 @@ series: bionic
relations: relations:
- - vault:shared-db - - vault:shared-db
- mysql:shared-db - mysql:shared-db
- - ovn:certificates - - ovn-central:certificates
- vault:certificates - vault:certificates
applications: applications:
mysql: mysql:
@ -11,9 +11,9 @@ applications:
vault: vault:
charm: cs:~openstack-charmers-next/vault charm: cs:~openstack-charmers-next/vault
num_units: 1 num_units: 1
ovn: ovn-central:
series: bionic series: bionic
charm: cs:~openstack-charmers-next/ovn charm: cs:~openstack-charmers-next/ovn-central
num_units: 3 num_units: 3
options: options:
source: cloud:bionic-stein source: cloud:bionic-stein

View File

@ -2,7 +2,7 @@ series: disco
relations: relations:
- - vault:shared-db - - vault:shared-db
- mysql:shared-db - mysql:shared-db
- - ovn:certificates - - ovn-central:certificates
- vault:certificates - vault:certificates
applications: applications:
mysql: mysql:
@ -11,7 +11,7 @@ applications:
vault: vault:
charm: cs:~openstack-charmers-next/vault charm: cs:~openstack-charmers-next/vault
num_units: 1 num_units: 1
ovn: ovn-central:
series: disco series: disco
charm: cs:~openstack-charmers-next/ovn charm: cs:~openstack-charmers-next/ovn-central
num_units: 1 num_units: 3

View File

@ -1,11 +1,11 @@
charm_name: ovn charm_name: ovn-central
gate_bundles: gate_bundles:
- disco - disco
- bionic - bionic
smoke_bundles: smoke_bundles:
- bionic - bionic
target_deploy_status: target_deploy_status:
ovn: ovn-central:
workload-status: blocked workload-status: blocked
workload-status-message: "'certificates' missing" workload-status-message: "'certificates' missing"
vault: vault:

View File

@ -3,6 +3,7 @@ envlist = pep8
skipsdist = True skipsdist = True
[testenv] [testenv]
download = true
setenv = VIRTUAL_ENV={envdir} setenv = VIRTUAL_ENV={envdir}
PYTHONHASHSEED=0 PYTHONHASHSEED=0
whitelist_externals = juju whitelist_externals = juju
@ -24,12 +25,12 @@ commands =
[testenv:func] [testenv:func]
basepython = python3 basepython = python3
commands = commands =
functest-run-suite --keep-model functest-run-suite {posargs} --keep-model
[testenv:func-smoke] [testenv:func-smoke]
basepython = python3 basepython = python3
commands = commands =
functest-run-suite --keep-model --smoke functest-run-suite {posargs} --keep-model --smoke
[testenv:venv] [testenv:venv]
commands = {posargs} commands = {posargs}

View File

@ -132,7 +132,7 @@ class TestOVNCentralCharm(Helper):
self.is_flag_set.return_value = True self.is_flag_set.return_value = True
self.target.configure_tls() self.target.configure_tls()
mocked_open.assert_called_once_with( mocked_open.assert_called_once_with(
'/etc/openvswitch/ovn.crt', 'w') '/etc/openvswitch/ovn-central.crt', 'w')
mocked_file.__enter__().write.assert_called_once_with( mocked_file.__enter__().write.assert_called_once_with(
'fakeca\nfakechain') 'fakeca\nfakechain')
self.target.configure_cert.assert_called_once_with( self.target.configure_cert.assert_called_once_with(
@ -145,7 +145,7 @@ class TestOVNCentralCharm(Helper):
'set-ssl', 'set-ssl',
'/etc/openvswitch/key_host', '/etc/openvswitch/key_host',
'/etc/openvswitch/cert_host', '/etc/openvswitch/cert_host',
'/etc/openvswitch/ovn.crt'), '/etc/openvswitch/ovn-central.crt'),
mock.call('ovs-vsctl', mock.call('ovs-vsctl',
'set', 'set',
'open', 'open',
@ -166,7 +166,7 @@ class TestOVNCentralCharm(Helper):
'set-ssl', 'set-ssl',
'/etc/openvswitch/key_host', '/etc/openvswitch/key_host',
'/etc/openvswitch/cert_host', '/etc/openvswitch/cert_host',
'/etc/openvswitch/ovn.crt'), '/etc/openvswitch/ovn-central.crt'),
mock.call('ovs-vsctl', mock.call('ovs-vsctl',
'set', 'set',
'open', 'open',

View File

@ -42,12 +42,14 @@ class TestRegisteredHooks(test_utils.TestRegisteredHooks):
'announce_leader_ready': ('config.rendered', 'announce_leader_ready': ('config.rendered',
'certificates.connected', 'certificates.connected',
'certificates.available', 'certificates.available',
'leadership.is_leader',), 'leadership.is_leader',
'ovsdb-peer.connected',),
'certificates_in_config_tls': ('config.rendered', 'certificates_in_config_tls': ('config.rendered',
'config.changed',), 'config.changed',),
'enable_default_certificates': ('charm.installed',), 'enable_default_certificates': ('charm.installed',),
'initialize_ovsdbs': ('charm.installed', 'initialize_ovsdbs': ('charm.installed',
'leadership.is_leader',), 'leadership.is_leader',
'ovsdb-peer.connected',),
'publish_addr_to_clients': ('ovsdb-peer.available', 'publish_addr_to_clients': ('ovsdb-peer.available',
'leadership.set.ready', 'leadership.set.ready',
'certificates.connected', 'certificates.connected',
@ -76,15 +78,22 @@ class TestOvnCentralHandlers(test_utils.PatchHelper):
self.provide_charm_instance().__exit__.return_value = None self.provide_charm_instance().__exit__.return_value = None
def test_announce_leader_ready(self): def test_announce_leader_ready(self):
self.patch_object(handlers.reactive, 'endpoint_from_flag')
self.patch_object(handlers.leadership, 'leader_set') self.patch_object(handlers.leadership, 'leader_set')
ovsdb_peer = mock.MagicMock()
self.endpoint_from_flag.return_value = ovsdb_peer
handlers.announce_leader_ready() handlers.announce_leader_ready()
ovsdb_peer.publish_cluster_local_addr.assert_called_once_with()
self.leader_set.assert_called_once_with({'ready': True}) self.leader_set.assert_called_once_with({'ready': True})
def test_initialize_ovsdbs(self): def test_initialize_ovsdbs(self):
self.patch_object(handlers.reactive, 'endpoint_from_flag')
self.patch_object(handlers.charm, 'use_defaults') self.patch_object(handlers.charm, 'use_defaults')
self.patch_object(handlers.reactive, 'set_flag') self.patch_object(handlers.reactive, 'set_flag')
ovsdb_peer = mock.MagicMock()
self.endpoint_from_flag.return_value = ovsdb_peer
handlers.initialize_ovsdbs() handlers.initialize_ovsdbs()
self.charm.render_with_interfaces.assert_called_once_with([]) self.charm.render_with_interfaces.assert_called_once_with([ovsdb_peer])
self.charm.enable_services.assert_called_once_with() self.charm.enable_services.assert_called_once_with()
self.use_defaults.assert_called_once_with('certificates.available') self.use_defaults.assert_called_once_with('certificates.available')
self.set_flag.assert_called_once_with('config.rendered') self.set_flag.assert_called_once_with('config.rendered')