From e7f0a8ad65eecffad9c7a23ff7aac2bef1eea477 Mon Sep 17 00:00:00 2001 From: David Ames Date: Fri, 15 Mar 2019 09:55:44 -0700 Subject: [PATCH] Ensure HA resources are configured The barbican charm was missing a configure_ha_resources call when the ha relation is connected. This led to HA deploys missing a VIP resources. This change enables barbican to run configure_ha_resources when the ha relation is connected as the other OpenStack reactive charms do. Change-Id: I92121af2621b9f7d9a7b2eb993abe522d4b0f1a5 Closes-Bug: #1820290 --- src/lib/charm/openstack/barbican.py | 2 +- src/reactive/barbican_handlers.py | 9 +++++++++ unit_tests/test_barbican_handlers.py | 18 +++++++++++++++++- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/lib/charm/openstack/barbican.py b/src/lib/charm/openstack/barbican.py index 1e9e2bd..ffa7d61 100644 --- a/src/lib/charm/openstack/barbican.py +++ b/src/lib/charm/openstack/barbican.py @@ -123,7 +123,7 @@ class BarbicanCharm(charms_openstack.charm.HAOpenStackCharm): BARBICAN_WSGI_CONF: services, } - ha_resources = ['vips', 'haproxy'] + ha_resources = ['vips', 'haproxy', 'dnsha'] # Package for release version detection release_pkg = 'barbican-common' diff --git a/src/reactive/barbican_handlers.py b/src/reactive/barbican_handlers.py index 94f9003..29257da 100644 --- a/src/reactive/barbican_handlers.py +++ b/src/reactive/barbican_handlers.py @@ -68,3 +68,12 @@ def secrets_plugin_configure(): reactive.clear_flag('secrets.new-plugin') reactive.set_flag('secrets.available') reactive.set_flag('config.changed') + + +@reactive.when('ha.connected') +@reactive.when_not('ha.available') +def cluster_connected(hacluster): + """Configure HA resources in corosync.""" + with charm.provide_charm_instance() as barbican_charm: + barbican_charm.configure_ha_resources(hacluster) + barbican_charm.assess_status() diff --git a/unit_tests/test_barbican_handlers.py b/unit_tests/test_barbican_handlers.py index b263f4d..d6a7c5f 100644 --- a/unit_tests/test_barbican_handlers.py +++ b/unit_tests/test_barbican_handlers.py @@ -39,7 +39,11 @@ class TestRegisteredHooks(test_utils.TestRegisteredHooks): 'identity-service.available', 'amqp.available',), 'secrets_plugin_configure': ('secrets.new-plugin',), - } + 'cluster_connected': ('ha.connected',), + }, + 'when_not': { + 'cluster_connected': ('ha.available',), + }, } # test that the hooks were registered via the # reactive.barbican_handlers @@ -77,3 +81,15 @@ class TestBarbicanHandlers(test_utils.PatchHelper): mock.call('secrets.available'), mock.call('config.changed'), ]) + + def test_cluster_connected(self): + hacluster = mock.MagicMock() + barbican_charm = mock.MagicMock() + self.patch_object(handlers.charm, 'provide_charm_instance', + new=mock.MagicMock()) + self.provide_charm_instance().__enter__.return_value = barbican_charm + self.provide_charm_instance().__exit__.return_value = None + handlers.cluster_connected(hacluster) + barbican_charm.configure_ha_resources.assert_called_once_with( + hacluster) + barbican_charm.assess_status.assert_called_once_with()