diff --git a/src/lib/charm/openstack/neutron_api_plugin_ovn.py b/src/lib/charm/openstack/neutron_api_plugin_ovn.py index 96bf99a..b865dfa 100644 --- a/src/lib/charm/openstack/neutron_api_plugin_ovn.py +++ b/src/lib/charm/openstack/neutron_api_plugin_ovn.py @@ -18,6 +18,7 @@ import charms_openstack.adapters import charms_openstack.charm +CERT_RELATION = 'certificates' NEUTRON_PLUGIN_ML2_DIR = '/etc/neutron/plugins/ml2' @@ -64,7 +65,7 @@ def ovn_ca_cert(cls): class BaseNeutronAPIPluginCharm(charms_openstack.charm.OpenStackCharm): abstract_class = True name = 'neutron-api-plugin-ovn' - required_relations = ['neutron-plugin', 'ovsdb-cms'] + required_relations = [CERT_RELATION, 'neutron-plugin', 'ovsdb-cms'] python_version = 3 release_pkg = version_package = 'neutron-common' # make sure we can write secrets readable by the ``neutron-server`` process @@ -120,6 +121,42 @@ class BaseNeutronAPIPluginCharm(charms_openstack.charm.OpenStackCharm): tls_object['key'], cn='host') + def states_to_check(self, required_relations=None): + """Override parent method to add custom messaging. + + Note that this method will only override the messaging for certain + relations, any relations we don't know about will get the default + treatment from the parent method. + + :param required_relations: Override `required_relations` class instance + variable. + :type required_relations: Optional[List[str]] + :returns: Map of relation name to flags to check presence of + accompanied by status and message. + :rtype: collections.OrderedDict[str, List[Tuple[str, str, str]]] + """ + # Retrieve default state map + states_to_check = super().states_to_check( + required_relations=required_relations) + + # The parent method will always return a OrderedDict + if CERT_RELATION in states_to_check: + # for the certificates relation we want to replace all messaging + states_to_check[CERT_RELATION] = [ + # the certificates relation has no connected state + ('{}.available'.format(CERT_RELATION), + 'blocked', + "'{}' missing".format(CERT_RELATION)), + # we cannot proceed until Vault have provided server + # certificates + ('{}.server.certs.available'.format(CERT_RELATION), + 'waiting', + "'{}' awaiting server certificate data" + .format(CERT_RELATION)), + ] + + return states_to_check + @property def db_migration_needed(self): """Determine whether DB migration is needed. diff --git a/src/tests/tests.yaml b/src/tests/tests.yaml index 2545f11..dec29b2 100644 --- a/src/tests/tests.yaml +++ b/src/tests/tests.yaml @@ -8,13 +8,13 @@ gate_bundles: target_deploy_status: neutron-api-plugin-ovn: workload-status: waiting - workload-status-message: "'ovsdb-cms' incomplete" + workload-status-message: "'certificates' awaiting server certificate data, 'ovsdb-cms' incomplete" ovn-central: - workload-status: blocked - workload-status-message: "'certificates' missing" + workload-status: waiting + workload-status-message: "'ovsdb-peer' incomplete, 'certificates' awaiting server certificate data" ovn-chassis: - workload-status: blocked - workload-status-message: "'certificates' missing" + workload-status: waiting + workload-status-message: "'certificates' awaiting server certificate data" vault: workload-status: blocked workload-status-message: Vault needs to be initialized diff --git a/unit_tests/test_lib_charm_openstack_ovn.py b/unit_tests/test_lib_charm_openstack_ovn.py index c0a5224..f7a9873 100644 --- a/unit_tests/test_lib_charm_openstack_ovn.py +++ b/unit_tests/test_lib_charm_openstack_ovn.py @@ -12,9 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. +import collections import io -import mock import os +import unittest.mock as mock import charms_openstack.test_utils as test_utils @@ -88,6 +89,30 @@ class TestNeutronAPIPluginOvnCharm(Helper): cn='host', ) + def test_states_to_check(self): + self.maxDiff = None + c = neutron_api_plugin_ovn.UssuriNeutronAPIPluginCharm() + expect = collections.OrderedDict([ + ('certificates', [ + ('certificates.available', 'blocked', + "'certificates' missing"), + ('certificates.server.certs.available', + 'waiting', + "'certificates' awaiting server certificate data")]), + ('neutron-plugin', [ + ('neutron-plugin.connected', + 'blocked', + "'neutron-plugin' missing"), + ('neutron-plugin.available', + 'waiting', + "'neutron-plugin' incomplete")]), + ('ovsdb-cms', [ + ('ovsdb-cms.connected', 'blocked', "'ovsdb-cms' missing"), + ('ovsdb-cms.available', 'waiting', "'ovsdb-cms' incomplete")]), + + ]) + self.assertDictEqual(c.states_to_check(), expect) + def test_service_plugins(self): c = neutron_api_plugin_ovn.UssuriNeutronAPIPluginCharm() svc_plugins = (