]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Skip adding ips from non dhcp enabled subnets to hosts file
authorItsuro Oda <oda@valinux.co.jp>
Tue, 6 Jan 2015 00:35:25 +0000 (09:35 +0900)
committerItsuro Oda <oda@valinux.co.jp>
Tue, 6 Jan 2015 00:41:01 +0000 (09:41 +0900)
If a network had a mix of dhcp and non dhcp enabled subnets,
then ips from all subnets were added to the hosts file.
This fix ensures only ips from dhcp enabled subnets are added.

Closes-Bug: #1316444
Change-Id: I673088f7be0fb16a27b09e07f8ac41d21d1ea4d4

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

index d6ee68c1c74b49dee22a64ed36f13b494462bc8f..b59392df11ca9f5d2105f5022afa8edb9823c5bd 100644 (file)
@@ -502,7 +502,13 @@ class Dnsmasq(DhcpLocalProcess):
         filename = self.get_conf_file_name('host')
 
         LOG.debug('Building host file: %s', filename)
+        dhcp_enabled_subnet_ids = [s.id for s in self.network.subnets
+                                   if s.enable_dhcp]
         for (port, alloc, hostname, name) in self._iter_hosts():
+            # don't write ip address which belongs to a dhcp disabled subnet.
+            if alloc.subnet_id not in dhcp_enabled_subnet_ids:
+                continue
+
             # (dzyu) Check if it is legal ipv6 address, if so, need wrap
             # it with '[]' to let dnsmasq to distinguish MAC address from
             # IPv6 address.
index 27b6f3d3ec5cd32e06f7b1f88b00c9d83d767b35..d326154bae346eda3a38bfc90369dbb898c02342 100644 (file)
@@ -89,7 +89,9 @@ class FakePort4:
     admin_state_up = False
     device_owner = 'foo3'
     fixed_ips = [FakeIPAllocation('192.168.0.4',
-                                  'ffda:3ba5:a17a:4ba3:0216:3eff:fec2:771d')]
+                                  'dddddddd-dddd-dddd-dddd-dddddddddddd'),
+                 FakeIPAllocation('ffda:3ba5:a17a:4ba3:0216:3eff:fec2:771d',
+                                  'eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee')]
     mac_address = '00:16:3E:C2:77:1D'
 
     def __init__(self):
@@ -1338,6 +1340,22 @@ class TestDnsmasq(TestBase):
         self.safe.assert_has_calls([mock.call(exp_host_name,
                                               exp_host_data)])
 
+    def test_only_populates_dhcp_enabled_subnet_on_a_network(self):
+        exp_host_name = '/dhcp/cccccccc-cccc-cccc-cccc-cccccccccccc/host'
+        exp_host_data = ('00:00:80:aa:bb:cc,host-192-168-0-2.openstacklocal,'
+                         '192.168.0.2\n'
+                         '00:00:f3:aa:bb:cc,host-192-168-0-3.openstacklocal,'
+                         '192.168.0.3\n'
+                         '00:00:0f:aa:bb:cc,host-192-168-0-4.openstacklocal,'
+                         '192.168.0.4\n'
+                         '00:00:0f:rr:rr:rr,host-192-168-0-1.openstacklocal,'
+                         '192.168.0.1\n').lstrip()
+        dm = dhcp.Dnsmasq(self.conf, FakeDualNetworkSingleDHCP(),
+                          version=dhcp.Dnsmasq.MINIMUM_VERSION)
+        dm._output_hosts_file()
+        self.safe.assert_has_calls([mock.call(exp_host_name,
+                                              exp_host_data)])
+
     def test_should_enable_metadata_namespaces_disabled_returns_false(self):
         self.conf.set_override('use_namespaces', False)
         self.assertFalse(dhcp.Dnsmasq.should_enable_metadata(self.conf,