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
This commit is contained in:
James Page 2019-09-25 14:07:03 +01:00
parent 31e2aabb03
commit 85b1a9656a
9 changed files with 64 additions and 13 deletions

View File

@ -258,12 +258,11 @@ class OVSPluginContext(context.NeutronContext):
return ovs_ctxt return ovs_ctxt
class DHCPAgentContext(OSContextGenerator): class ZoneContext(OSContextGenerator):
def __call__(self): def __call__(self):
"""Return the 'default_availability_zone' from the principal that this """Return the 'default_availability_zone' from the principal that this
ovs unit is attached to (as a subordinate) and the 'dns_domain' from ovs unit is attached to (as a subordinate)
the neutron-plugin-api relations (if one is set).
:returns: {} if no relation set, or :returns: {} if no relation set, or
{'availability_zone': availability_zone from principal relation} {'availability_zone': availability_zone from principal relation}
@ -283,6 +282,20 @@ class DHCPAgentContext(OSContextGenerator):
unit=units[0]) unit=units[0])
if availability_zone: if availability_zone:
ctxt['availability_zone'] = 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') dnsmasq_flags = config('dnsmasq-flags')
if dnsmasq_flags: if dnsmasq_flags:

View File

@ -164,6 +164,7 @@ BASE_RESOURCE_MAP = OrderedDict([
context.ZeroMQContext(), context.ZeroMQContext(),
context.NotificationDriverContext(), context.NotificationDriverContext(),
neutron_ovs_context.HostIPContext(), neutron_ovs_context.HostIPContext(),
neutron_ovs_context.ZoneContext(),
], ],
}), }),
(ML2_CONF, { (ML2_CONF, {

View File

@ -31,8 +31,3 @@ enable_metadata_network = True
enable_isolated_metadata = True enable_isolated_metadata = True
ovs_use_veth = True ovs_use_veth = True
[AGENT]
{% if availability_zone -%}
availability_zone = {{ availability_zone }}
{% endif -%}

View File

@ -38,6 +38,8 @@ rpc_response_timeout = {{ rpc_response_timeout }}
root_helper = sudo neutron-rootwrap /etc/neutron/rootwrap.conf root_helper = sudo neutron-rootwrap /etc/neutron/rootwrap.conf
report_interval = {{ report_interval }} report_interval = {{ report_interval }}
{% include "parts/agent" %}
[keystone_authtoken] [keystone_authtoken]
signing_dir = /var/lib/neutron/keystone-signing signing_dir = /var/lib/neutron/keystone-signing

View File

@ -32,8 +32,3 @@ force_metadata = True
enable_isolated_metadata = True enable_isolated_metadata = True
ovs_use_veth = True ovs_use_veth = True
[AGENT]
{% if availability_zone -%}
availability_zone = {{ availability_zone }}
{% endif -%}

View File

@ -41,6 +41,8 @@ rpc_response_timeout = {{ rpc_response_timeout }}
root_helper = sudo neutron-rootwrap /etc/neutron/rootwrap.conf root_helper = sudo neutron-rootwrap /etc/neutron/rootwrap.conf
report_interval = {{ report_interval }} report_interval = {{ report_interval }}
{% include "parts/agent" %}
[keystone_authtoken] [keystone_authtoken]
signing_dir = /var/lib/neutron/keystone-signing signing_dir = /var/lib/neutron/keystone-signing

3
templates/parts/agent Normal file
View File

@ -0,0 +1,3 @@
{% if availability_zone -%}
availability_zone = {{ availability_zone }}
{% endif -%}

View File

@ -45,6 +45,8 @@ rpc_response_timeout = {{ rpc_response_timeout }}
root_helper = sudo neutron-rootwrap /etc/neutron/rootwrap.conf root_helper = sudo neutron-rootwrap /etc/neutron/rootwrap.conf
report_interval = {{ report_interval }} report_interval = {{ report_interval }}
{% include "parts/agent" %}
[keystone_authtoken] [keystone_authtoken]
signing_dir = /var/lib/neutron/keystone-signing signing_dir = /var/lib/neutron/keystone-signing

View File

@ -275,6 +275,44 @@ class OVSPluginContextTest(CharmTestCase):
self.assertEqual(expect, napi_ctxt()) 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): class DHCPAgentContextTest(CharmTestCase):
def setUp(self): def setUp(self):