From 71b5196b5b6d7758d80c3559719ce0366055bf04 Mon Sep 17 00:00:00 2001 From: Liam Young Date: Thu, 8 Nov 2018 16:59:19 +0000 Subject: [PATCH] Restart nova-compute if packages have been purged. If packages have been purged off the system then trigger a restart of nova-compute by sending a restart trigger via the neutron-plugin relation. Change-Id: I5c8272d8c83b5112b6d8cebbbf3c485b87b7ef31 Closes-Bug: 1802304 --- hooks/neutron_ovs_hooks.py | 15 ++++++++++++--- unit_tests/test_neutron_ovs_hooks.py | 7 ++++++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/hooks/neutron_ovs_hooks.py b/hooks/neutron_ovs_hooks.py index 35fc9287..4df3340b 100755 --- a/hooks/neutron_ovs_hooks.py +++ b/hooks/neutron_ovs_hooks.py @@ -15,6 +15,7 @@ # limitations under the License. import sys +import uuid from copy import deepcopy @@ -105,7 +106,11 @@ def config_changed(): # NOTE(jamespage): purge any packages as a result of py3 switch # at rocky. - purge_packages(determine_purge_packages()) + packages_to_purge = determine_purge_packages() + request_nova_compute_restart = False + if packages_to_purge: + purge_packages(packages_to_purge) + request_nova_compute_restart = True configure_ovs() CONFIGS.write_all() @@ -113,7 +118,9 @@ def config_changed(): # to allow us to enable boot time execution of init script configure_sriov() for rid in relation_ids('neutron-plugin'): - neutron_plugin_joined(relation_id=rid) + neutron_plugin_joined( + relation_id=rid, + request_restart=request_nova_compute_restart) @hooks.hook('neutron-plugin-api-relation-changed') @@ -131,7 +138,7 @@ def neutron_plugin_api_changed(): @hooks.hook('neutron-plugin-relation-joined') -def neutron_plugin_joined(relation_id=None): +def neutron_plugin_joined(relation_id=None, request_restart=False): if enable_local_dhcp(): install_packages() else: @@ -146,6 +153,8 @@ def neutron_plugin_joined(relation_id=None): rel_data = { 'metadata-shared-secret': secret, } + if request_restart: + rel_data['restart-nonce'] = str(uuid.uuid4()) relation_set(relation_id=relation_id, **rel_data) diff --git a/unit_tests/test_neutron_ovs_hooks.py b/unit_tests/test_neutron_ovs_hooks.py index f778fbe6..3f7bbc34 100644 --- a/unit_tests/test_neutron_ovs_hooks.py +++ b/unit_tests/test_neutron_ovs_hooks.py @@ -109,13 +109,18 @@ class NeutronOVSHooksTests(CharmTestCase): self.assertTrue(self.CONFIGS.write_all.called) self.configure_ovs.assert_called_with() - def test_config_changed_rocky_upgrade(self): + @patch.object(hooks, 'neutron_plugin_joined') + def test_config_changed_rocky_upgrade(self, _plugin_joined): self.determine_purge_packages.return_value = ['python-neutron'] + self.relation_ids.return_value = ['neutron-plugin:42'] self._call_hook('config-changed') self.install_packages.assert_called_with() self.assertTrue(self.CONFIGS.write_all.called) self.configure_ovs.assert_called_with() self.purge_packages.assert_called_with(['python-neutron']) + _plugin_joined.assert_called_with( + relation_id='neutron-plugin:42', + request_restart=True) @patch.object(hooks, 'neutron_plugin_joined') def test_neutron_plugin_api(self, _plugin_joined):