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
This commit is contained in:
Felipe Reyes 2023-04-21 19:36:01 -04:00
parent 09928ae295
commit 366df4c07e
2 changed files with 34 additions and 0 deletions

View File

@ -1096,6 +1096,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')

View File

@ -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()