]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
The option force_metadata=True breaks the dhcp agent
authorNir Magnezi <nmagnezi@redhat.com>
Thu, 24 Sep 2015 14:49:15 +0000 (17:49 +0300)
committerJakub Libosvar <libosvar@redhat.com>
Mon, 5 Oct 2015 10:54:23 +0000 (10:54 +0000)
Patch I5f6ee9788717c3d4f1f2e2a4b9734fdd8dd92b40 has an issue with
force_metadata = True.

Using the option force_metadata=True while
enable_isolated_metadata=False (which is the default), will break the
dhcp agent because the variable subnet_to_interface_ip is being
referenced before assignment.

Co-Authored-By: Jakub Libosvar <jlibosva@redhat.com>
Change-Id: I4e1d918e3a24dd483ee134021f587ae4520bf431
Closes-Bug: #1499406
(cherry picked from commit 473c338ff8c5526157d297b7e90d5e4f5e94cbb9)

neutron/agent/linux/dhcp.py
neutron/tests/unit/agent/linux/test_dhcp.py

index d47abfca1ec7a984de6dd370298f582c6b9c736f..9e8b53f20dc724a8203d12f9f9572aaca38d6dc7 100644 (file)
@@ -752,7 +752,7 @@ class Dnsmasq(DhcpLocalProcess):
     def _generate_opts_per_subnet(self):
         options = []
         subnet_index_map = {}
-        if self.conf.enable_isolated_metadata:
+        if self.conf.enable_isolated_metadata or self.conf.force_metadata:
             subnet_to_interface_ip = self._make_subnet_interface_ip_map()
         isolated_subnets = self.get_isolated_subnets(self.network)
         for i, subnet in enumerate(self.network.subnets):
index c28c51c9233e5a5af9c8a2bba3c2e3fa158494aa..1a25247837cc130cf04585eb6f1e999ed41dc39e 100644 (file)
@@ -1933,6 +1933,36 @@ class TestDnsmasq(TestBase):
         self.assertTrue(dhcp.Dnsmasq.should_enable_metadata(self.conf,
                                                             mock.ANY))
 
+    def _test__generate_opts_per_subnet_helper(self, config_opts,
+                                               expected_mdt_ip):
+        for key, value in config_opts.items():
+            self.conf.set_override(key, value)
+        dm = self._get_dnsmasq(FakeNetworkDhcpPort)
+        with mock.patch('neutron.agent.linux.ip_lib.IPDevice') as ipdev_mock:
+            list_addr = ipdev_mock.return_value.addr.list
+            list_addr.return_value = [{'cidr': alloc.ip_address + '/24'}
+                                      for alloc in FakeDhcpPort.fixed_ips]
+            options, idx_map = dm._generate_opts_per_subnet()
+
+        contains_metadata_ip = any(['%s/32' % dhcp.METADATA_DEFAULT_IP in line
+                                    for line in options])
+        self.assertEqual(expected_mdt_ip, contains_metadata_ip)
+
+    def test__generate_opts_per_subnet_no_metadata(self):
+        config = {'enable_isolated_metadata': False,
+                  'force_metadata': False}
+        self._test__generate_opts_per_subnet_helper(config, False)
+
+    def test__generate_opts_per_subnet_isolated_metadata_with_router(self):
+        config = {'enable_isolated_metadata': True,
+                  'force_metadata': False}
+        self._test__generate_opts_per_subnet_helper(config, True)
+
+    def test__generate_opts_per_subnet_forced_metadata(self):
+        config = {'enable_isolated_metadata': False,
+                  'force_metadata': True}
+        self._test__generate_opts_per_subnet_helper(config, True)
+
 
 class TestDeviceManager(TestConfBase):