From 8b5c08b35e75de6e09b75ed01120b6fdedb9125f Mon Sep 17 00:00:00 2001 From: Xu Han Peng Date: Fri, 14 Nov 2014 10:53:59 +0800 Subject: [PATCH] Fix metadata proxy start problem for v6-v4 network Commit 1b66e11b5d8c0b3de0610ca02c3e10b6f64ae375 introduces a new problem that metadata proxy will not be started when an isolated network contains ipv6 subnet with dhcp enabled and a ipv4 subnet. This fix separates the checks to enable dhcp and enable metadata so metadata proxy can be started if there is ipv4 subnet exists in the network with metadata enabled. Change-Id: If26806083db225e9ab30d75fa6c728ce99a7cafe Closes-Bug: 1392564 (cherry picked from commit 4c128c351589ef9f2fc1e084c655a97bdbbda7ce) --- neutron/agent/dhcp_agent.py | 12 ++++++++---- neutron/tests/unit/test_dhcp_agent.py | 27 +++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/neutron/agent/dhcp_agent.py b/neutron/agent/dhcp_agent.py index c8ea89b02..c174367cb 100644 --- a/neutron/agent/dhcp_agent.py +++ b/neutron/agent/dhcp_agent.py @@ -225,17 +225,21 @@ class DhcpAgent(manager.Manager): enable_metadata = self.dhcp_driver_cls.should_enable_metadata( self.conf, network) + dhcp_network_enabled = False for subnet in network.subnets: if subnet.enable_dhcp: if self.call_driver('enable', network): - if (subnet.ip_version == 4 and self.conf.use_namespaces - and enable_metadata): - self.enable_isolated_metadata_proxy(network) - enable_metadata = False # Don't trigger twice + dhcp_network_enabled = True self.cache.put(network) break + if enable_metadata and dhcp_network_enabled: + for subnet in network.subnets: + if subnet.ip_version == 4 and subnet.enable_dhcp: + self.enable_isolated_metadata_proxy(network) + break + def disable_dhcp_helper(self, network_id): """Disable DHCP for a network known to the agent.""" network = self.cache.get_network_by_id(network_id) diff --git a/neutron/tests/unit/test_dhcp_agent.py b/neutron/tests/unit/test_dhcp_agent.py index 5e02428b0..c9c1d2876 100644 --- a/neutron/tests/unit/test_dhcp_agent.py +++ b/neutron/tests/unit/test_dhcp_agent.py @@ -116,6 +116,13 @@ fake_network_ipv6 = dhcp.NetModel(True, dict( admin_state_up=True, subnets=[fake_ipv6_subnet])) +fake_network_ipv6_ipv4 = dhcp.NetModel(True, dict( + id='12345678-1234-5678-1234567890ab', + tenant_id='aaaaaaaa-aaaa-aaaa-aaaaaaaaaaaa', + admin_state_up=True, + subnets=[fake_ipv6_subnet, fake_subnet1], + ports=[fake_port1])) + isolated_network = dhcp.NetModel( True, dict( id='12345678-1234-5678-1234567890ab', @@ -564,6 +571,26 @@ class TestDhcpAgentEventHandler(base.BaseTestCase): enable_isolated_metadata=True, is_isolated_network=True) + def test_enable_dhcp_helper_enable_metadata_ipv6_ipv4_network(self): + self._enable_dhcp_helper(fake_network_ipv6_ipv4, + enable_isolated_metadata=True, + is_isolated_network=True) + + def test_enable_dhcp_helper_driver_failure_ipv6_ipv4_network(self): + self.plugin.get_network_info.return_value = fake_network_ipv6_ipv4 + self.call_driver.return_value = False + cfg.CONF.set_override('enable_isolated_metadata', True) + with mock.patch.object( + self.dhcp, 'enable_isolated_metadata_proxy') as enable_metadata: + self.dhcp.enable_dhcp_helper(fake_network_ipv6_ipv4.id) + self.plugin.assert_has_calls( + [mock.call.get_network_info(fake_network_ipv6_ipv4.id)]) + self.call_driver.assert_called_once_with('enable', + fake_network_ipv6_ipv4) + self.assertFalse(self.cache.called) + self.assertFalse(enable_metadata.called) + self.assertFalse(self.external_process.called) + def test_enable_dhcp_helper(self): self._enable_dhcp_helper(fake_network) -- 2.45.2