]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Fix metadata proxy start problem for v6-v4 network
authorXu Han Peng <xuhanp@cn.ibm.com>
Fri, 14 Nov 2014 02:53:59 +0000 (10:53 +0800)
committerAlan Pevec <alan.pevec@redhat.com>
Tue, 25 Nov 2014 23:07:33 +0000 (00:07 +0100)
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
neutron/tests/unit/test_dhcp_agent.py

index c8ea89b0219e6f99680d924f3760a655cf154f76..c174367cbc8fc664db5daff688a6e5b1119ad066 100644 (file)
@@ -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)
index 5e02428b0d6152bfdcdd0752187313592a4cc8d7..c9c1d287691f2ba54f385efb758de40f0f15fcc1 100644 (file)
@@ -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)