From d09ed28af0fb2a3761452d6afa2f30bd6020249e Mon Sep 17 00:00:00 2001 From: Felipe Reyes Date: Fri, 21 Apr 2023 19:36:01 -0400 Subject: [PATCH] Update nova relations data on ha-relation-changed When taking the nova-cloud-controller from single unit to full HA by increasing the number of units from 1 to 3 and relating it to hacluster, the data set on the cloud-compute relation is not updated, because the update_nova_relation() function is only called on cloud-compute-relation-joined and config-changed, none of these hooks are executed when scaling out the application. This patch introduces a call to update_nova_relation() on ha-relation-changed. Test case on an environment deployed with a single unit of nova-cloud-controller: export NOVA_CC_VIP=10.0.0.11 juju config nova-cloud-controller vip=$NOVA_CC_VIP juju deploy --series jammy --channel 2.4/stable hacluster \ nova-cloud-controller-hacluster juju add-unit -n 2 nova-cloud-controller juju deploy --series jammy memcached juju add-relation memcached nova-cloud-controller juju add-relation nova-cloud-controller nova-cloud-controller-hacluster Change-Id: Ib08bf9b6e1ce2b69be4d99ffe0726b59d81f4bc9 Closes-Bug: #2002154 --- hooks/nova_cc_hooks.py | 2 ++ unit_tests/test_nova_cc_hooks.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/hooks/nova_cc_hooks.py b/hooks/nova_cc_hooks.py index 34d14c83..dccbaec1 100755 --- a/hooks/nova_cc_hooks.py +++ b/hooks/nova_cc_hooks.py @@ -1091,6 +1091,8 @@ def ha_changed(): 'keystone endpoint configuration') for rid in hookenv.relation_ids('identity-service'): identity_joined(rid=rid) + hookenv.log('Updating nova relations data') + update_nova_relation() @hooks.hook('shared-db-relation-broken') diff --git a/unit_tests/test_nova_cc_hooks.py b/unit_tests/test_nova_cc_hooks.py index 6d0bfa93..d44cec98 100644 --- a/unit_tests/test_nova_cc_hooks.py +++ b/unit_tests/test_nova_cc_hooks.py @@ -1204,6 +1204,38 @@ class NovaCCHooksTests(CharmTestCase): ha='settings', relation_id=None) + @patch('charmhelpers.contrib.openstack.context.relation_ids') + def test_ha_relation_changed_not_clustered(self, ctxt_relation_ids): + self.relation_get.return_value = '' + self.os_release.return_value = 'ussuri' + ctxt_relation_ids.return_value = [] + hooks.resolve_CONFIGS() + with patch.object(hooks.CONFIGS, 'write') as configs_write: + hooks.ha_changed() + configs_write.assert_not_called() + + @patch.object(hooks, 'update_nova_relation') + @patch.object(hooks, 'identity_joined') + @patch('charmhelpers.contrib.openstack.context.relation_get') + @patch('charmhelpers.contrib.openstack.context.related_units') + @patch('charmhelpers.contrib.openstack.context.relation_ids') + def test_ha_relation_changed_clustered(self, ctxt_relation_ids, + ctxt_related_units, + ctxt_relation_get, + identity_joined, + update_nova_relation): + ctxt_relation_get.return_value = None + self.test_relation.set({'clustered': True}) + self.os_release.return_value = 'ussuri' + self.relation_ids.return_value = ['identity-service:1'] + ctxt_related_units.return_value = ['keystone/0'] + hooks.resolve_CONFIGS() + with patch.object(hooks.CONFIGS, 'write') as configs_write: + hooks.ha_changed() + configs_write.assert_called_with(utils.NOVA_CONF) + identity_joined.assert_called_with(rid='identity-service:1') + update_nova_relation.assert_called_with() + @patch('hooks.nova_cc_utils.disable_deprecated_nova_placement_apache_site') def test_placement_joined(self, disable_nova_placement): hooks.placement_relation_joined()