diff --git a/hooks/neutron_ovs_context.py b/hooks/neutron_ovs_context.py index f8948a39..56b5863d 100644 --- a/hooks/neutron_ovs_context.py +++ b/hooks/neutron_ovs_context.py @@ -114,6 +114,32 @@ class OVSPluginContext(context.NeutronContext): return ovs_ctxt +class DHCPAgentContext(OSContextGenerator): + + def __call__(self): + """Return the 'default_availability_zone' from the principal that this + ovs unit is attached to (as a subordinate). + + :returns: {} if no relation set, or + {'availability_zone': availability_zone from principal relation} + """ + # as ovs is a subordinate charm, it should only have one relation to + # its principal charm. Thus we can take the 1st (only) element in each + # list. + rids = relation_ids('neutron-plugin') + if rids: + rid = rids[0] + units = related_units(rid) + if units: + availability_zone = relation_get( + 'default_availability_zone', + rid=rid, + unit=units[0]) + if availability_zone: + return {'availability_zone': availability_zone} + return {} + + class L3AgentContext(OSContextGenerator): def __call__(self): diff --git a/hooks/neutron_ovs_utils.py b/hooks/neutron_ovs_utils.py index 4e820f31..6f03fd95 100644 --- a/hooks/neutron_ovs_utils.py +++ b/hooks/neutron_ovs_utils.py @@ -178,7 +178,7 @@ METADATA_RESOURCE_MAP = OrderedDict([ DHCP_RESOURCE_MAP = OrderedDict([ (NEUTRON_DHCP_AGENT_CONF, { 'services': ['neutron-dhcp-agent'], - 'contexts': [], + 'contexts': [neutron_ovs_context.DHCPAgentContext()], }), ]) DVR_RESOURCE_MAP = OrderedDict([ diff --git a/templates/mitaka/dhcp_agent.ini b/templates/mitaka/dhcp_agent.ini new file mode 100644 index 00000000..24a1ab41 --- /dev/null +++ b/templates/mitaka/dhcp_agent.ini @@ -0,0 +1,22 @@ +# mitaka +############################################################################### +# [ WARNING ] +# Configuration file maintained by Juju. Local changes may be overwritten. +# +############################################################################### + +[DEFAULT] +state_path = /var/lib/neutron +interface_driver = neutron.agent.linux.interface.OVSInterfaceDriver +dhcp_driver = neutron.agent.linux.dhcp.Dnsmasq +root_helper = sudo /usr/bin/neutron-rootwrap /etc/neutron/rootwrap.conf + +enable_metadata_network = True +enable_isolated_metadata = True + +ovs_use_veth = True + +[AGENT] +{% if availability_zone -%} +availability_zone = {{ availability_zone }} +{% endif -%} diff --git a/unit_tests/test_neutron_ovs_context.py b/unit_tests/test_neutron_ovs_context.py index cfce9c62..3fbe9fb2 100644 --- a/unit_tests/test_neutron_ovs_context.py +++ b/unit_tests/test_neutron_ovs_context.py @@ -234,6 +234,44 @@ class OVSPluginContextTest(CharmTestCase): self.assertEquals(expect, napi_ctxt()) +class DHCPAgentContextTest(CharmTestCase): + + def setUp(self): + super(DHCPAgentContextTest, self).setUp(context, TO_PATCH) + self.config.side_effect = self.test_config.get + + def tearDown(self): + super(DHCPAgentContextTest, 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.DHCPAgentContext()(), + {} + ) + 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.DHCPAgentContext()(), + {'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 L3AgentContextTest(CharmTestCase): def setUp(self):