From 85b1a9656ab5d796af63fc2f3ed5ae6c9d2f108e Mon Sep 17 00:00:00 2001 From: James Page Date: Wed, 25 Sep 2019 14:07:03 +0100 Subject: [PATCH] Ensure availability_zone set globally for agents Inline with the neutron-gateway charm, move availability_zone configuration to the neutron.conf configuration file to ensure that its set consistently for all neutron agents that may be running on the unit. Change-Id: If9438302f8f889a1cbaf93f8a460e190e551241b Closes-Bug: 1829537 --- hooks/neutron_ovs_context.py | 19 +++++++++++-- hooks/neutron_ovs_utils.py | 1 + templates/mitaka/dhcp_agent.ini | 5 ---- templates/mitaka/neutron.conf | 2 ++ templates/ocata/dhcp_agent.ini | 5 ---- templates/ocata/neutron.conf | 2 ++ templates/parts/agent | 3 ++ templates/stein/neutron.conf | 2 ++ unit_tests/test_neutron_ovs_context.py | 38 ++++++++++++++++++++++++++ 9 files changed, 64 insertions(+), 13 deletions(-) create mode 100644 templates/parts/agent diff --git a/hooks/neutron_ovs_context.py b/hooks/neutron_ovs_context.py index 900bfb67..6ba80f5c 100644 --- a/hooks/neutron_ovs_context.py +++ b/hooks/neutron_ovs_context.py @@ -258,12 +258,11 @@ class OVSPluginContext(context.NeutronContext): return ovs_ctxt -class DHCPAgentContext(OSContextGenerator): +class ZoneContext(OSContextGenerator): def __call__(self): """Return the 'default_availability_zone' from the principal that this - ovs unit is attached to (as a subordinate) and the 'dns_domain' from - the neutron-plugin-api relations (if one is set). + ovs unit is attached to (as a subordinate) :returns: {} if no relation set, or {'availability_zone': availability_zone from principal relation} @@ -283,6 +282,20 @@ class DHCPAgentContext(OSContextGenerator): unit=units[0]) if availability_zone: ctxt['availability_zone'] = availability_zone + return ctxt + + +class DHCPAgentContext(ZoneContext): + + def __call__(self): + """Return the 'default_availability_zone' from the principal that this + ovs unit is attached to (as a subordinate) and the 'dns_domain' from + the neutron-plugin-api relations (if one is set). + + :returns: {} if no relation set, or + {'availability_zone': availability_zone from principal relation} + """ + ctxt = super(DHCPAgentContext, self).__call__() dnsmasq_flags = config('dnsmasq-flags') if dnsmasq_flags: diff --git a/hooks/neutron_ovs_utils.py b/hooks/neutron_ovs_utils.py index 49795be0..c1281cac 100644 --- a/hooks/neutron_ovs_utils.py +++ b/hooks/neutron_ovs_utils.py @@ -164,6 +164,7 @@ BASE_RESOURCE_MAP = OrderedDict([ context.ZeroMQContext(), context.NotificationDriverContext(), neutron_ovs_context.HostIPContext(), + neutron_ovs_context.ZoneContext(), ], }), (ML2_CONF, { diff --git a/templates/mitaka/dhcp_agent.ini b/templates/mitaka/dhcp_agent.ini index 224d2c2e..41caf556 100644 --- a/templates/mitaka/dhcp_agent.ini +++ b/templates/mitaka/dhcp_agent.ini @@ -31,8 +31,3 @@ enable_metadata_network = True enable_isolated_metadata = True ovs_use_veth = True - -[AGENT] -{% if availability_zone -%} -availability_zone = {{ availability_zone }} -{% endif -%} diff --git a/templates/mitaka/neutron.conf b/templates/mitaka/neutron.conf index 48199253..dcec07cb 100644 --- a/templates/mitaka/neutron.conf +++ b/templates/mitaka/neutron.conf @@ -38,6 +38,8 @@ rpc_response_timeout = {{ rpc_response_timeout }} root_helper = sudo neutron-rootwrap /etc/neutron/rootwrap.conf report_interval = {{ report_interval }} +{% include "parts/agent" %} + [keystone_authtoken] signing_dir = /var/lib/neutron/keystone-signing diff --git a/templates/ocata/dhcp_agent.ini b/templates/ocata/dhcp_agent.ini index 1c3cd3b7..796a61a4 100644 --- a/templates/ocata/dhcp_agent.ini +++ b/templates/ocata/dhcp_agent.ini @@ -32,8 +32,3 @@ force_metadata = True enable_isolated_metadata = True ovs_use_veth = True - -[AGENT] -{% if availability_zone -%} -availability_zone = {{ availability_zone }} -{% endif -%} diff --git a/templates/ocata/neutron.conf b/templates/ocata/neutron.conf index 299a7c67..67375aae 100644 --- a/templates/ocata/neutron.conf +++ b/templates/ocata/neutron.conf @@ -41,6 +41,8 @@ rpc_response_timeout = {{ rpc_response_timeout }} root_helper = sudo neutron-rootwrap /etc/neutron/rootwrap.conf report_interval = {{ report_interval }} +{% include "parts/agent" %} + [keystone_authtoken] signing_dir = /var/lib/neutron/keystone-signing diff --git a/templates/parts/agent b/templates/parts/agent new file mode 100644 index 00000000..4ab7ace6 --- /dev/null +++ b/templates/parts/agent @@ -0,0 +1,3 @@ +{% if availability_zone -%} +availability_zone = {{ availability_zone }} +{% endif -%} diff --git a/templates/stein/neutron.conf b/templates/stein/neutron.conf index ec9aad2e..b9b31868 100644 --- a/templates/stein/neutron.conf +++ b/templates/stein/neutron.conf @@ -45,6 +45,8 @@ rpc_response_timeout = {{ rpc_response_timeout }} root_helper = sudo neutron-rootwrap /etc/neutron/rootwrap.conf report_interval = {{ report_interval }} +{% include "parts/agent" %} + [keystone_authtoken] signing_dir = /var/lib/neutron/keystone-signing diff --git a/unit_tests/test_neutron_ovs_context.py b/unit_tests/test_neutron_ovs_context.py index fdff28b0..02bce021 100644 --- a/unit_tests/test_neutron_ovs_context.py +++ b/unit_tests/test_neutron_ovs_context.py @@ -275,6 +275,44 @@ class OVSPluginContextTest(CharmTestCase): self.assertEqual(expect, napi_ctxt()) +class ZoneContextTest(CharmTestCase): + + def setUp(self): + super(ZoneContextTest, self).setUp(context, TO_PATCH) + self.config.side_effect = self.test_config.get + + def tearDown(self): + super(ZoneContextTest, self).tearDown() + + def test_default_availability_zone_not_provided(self): + self.relation_ids.return_value = ['rid1'] + self.related_units.return_value = ['nova-compute/0'] + self.relation_get.return_value = None + self.assertEqual( + context.ZoneContext()(), + {} + ) + self.relation_ids.assert_called_with('neutron-plugin') + self.relation_get.assert_called_once_with( + 'default_availability_zone', + rid='rid1', + unit='nova-compute/0') + + def test_default_availability_zone_provided(self): + self.relation_ids.return_value = ['rid1'] + self.related_units.return_value = ['nova-compute/0'] + self.relation_get.return_value = 'nova' + self.assertEqual( + context.ZoneContext()(), + {'availability_zone': 'nova'} + ) + self.relation_ids.assert_called_with('neutron-plugin') + self.relation_get.assert_called_once_with( + 'default_availability_zone', + rid='rid1', + unit='nova-compute/0') + + class DHCPAgentContextTest(CharmTestCase): def setUp(self):