From 32d7c17b7f3de919276bdc0dd1a104149d81af2b Mon Sep 17 00:00:00 2001 From: Frode Nordahl Date: Tue, 1 Oct 2019 07:46:55 +0200 Subject: [PATCH] Provide configured hostname over subordinate relation Change-Id: I75cbc5eb97cf3603ffa5a9a49670411288d90520 Closes-Bug: #1845303 --- hooks/neutron_ovs_hooks.py | 5 +++++ unit_tests/test_neutron_ovs_hooks.py | 15 ++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/hooks/neutron_ovs_hooks.py b/hooks/neutron_ovs_hooks.py index 554a535e..d935a2c1 100755 --- a/hooks/neutron_ovs_hooks.py +++ b/hooks/neutron_ovs_hooks.py @@ -72,6 +72,8 @@ from neutron_ovs_utils import ( enable_sriov, ) +import neutron_ovs_context + hooks = Hooks() CONFIGS = register_configs() @@ -197,6 +199,9 @@ def neutron_plugin_joined(relation_id=None, request_restart=False): rel_data = { 'metadata-shared-secret': secret, } + host = neutron_ovs_context.HostIPContext()().get('host') + if host: + rel_data.update({'host': host}) 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 ea3f0d01..c285c06c 100644 --- a/unit_tests/test_neutron_ovs_hooks.py +++ b/unit_tests/test_neutron_ovs_hooks.py @@ -178,14 +178,17 @@ class NeutronOVSHooksTests(CharmTestCase): 'libnetfilter-log1', 'keepalived']) - def test_neutron_plugin_joined_dvr_dhcp(self): + @patch.object(hooks.neutron_ovs_context, 'HostIPContext') + def test_neutron_plugin_joined_dvr_dhcp(self, _HostIPContext): self.enable_nova_metadata.return_value = True self.enable_local_dhcp.return_value = True self.use_dvr.return_value = True self.get_shared_secret.return_value = 'secret' + _HostIPContext()().get.return_value = 'fq.dn' self._call_hook('neutron-plugin-relation-joined') rel_data = { 'metadata-shared-secret': 'secret', + 'host': 'fq.dn', } self.relation_set.assert_called_with( relation_id=None, @@ -193,14 +196,17 @@ class NeutronOVSHooksTests(CharmTestCase): ) self.assertTrue(self.install_packages.called) - def test_neutron_plugin_joined_dvr_nodhcp(self): + @patch.object(hooks.neutron_ovs_context, 'HostIPContext') + def test_neutron_plugin_joined_dvr_nodhcp(self, _HostIPContext): self.enable_nova_metadata.return_value = True self.enable_local_dhcp.return_value = False self.use_dvr.return_value = True self.get_shared_secret.return_value = 'secret' + _HostIPContext()().get.return_value = 'fq.dn' self._call_hook('neutron-plugin-relation-joined') rel_data = { 'metadata-shared-secret': 'secret', + 'host': 'fq.dn', } self.relation_set.assert_called_with( relation_id=None, @@ -209,14 +215,17 @@ class NeutronOVSHooksTests(CharmTestCase): self.purge_packages.assert_called_with(['neutron-dhcp-agent']) self.assertFalse(self.install_packages.called) - def test_neutron_plugin_joined_nodvr_nodhcp(self): + @patch.object(hooks.neutron_ovs_context, 'HostIPContext') + def test_neutron_plugin_joined_nodvr_nodhcp(self, _HostIPContext): self.enable_nova_metadata.return_value = False self.enable_local_dhcp.return_value = False self.use_dvr.return_value = False self.get_shared_secret.return_value = 'secret' + _HostIPContext()().get.return_value = 'fq.dn' self._call_hook('neutron-plugin-relation-joined') rel_data = { 'metadata-shared-secret': None, + 'host': 'fq.dn', } self.relation_set.assert_called_with( relation_id=None,