]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
read_hosts_file_leases shouldn't parse stateless IPv6
authorvenkata anil <anil.venkata@enovance.com>
Thu, 18 Jun 2015 10:03:12 +0000 (10:03 +0000)
committervenkata anil <anil.venkata@enovance.com>
Thu, 18 Jun 2015 10:03:44 +0000 (10:03 +0000)
Error when _read_hosts_file_leases tries to parse stateless IPv6 entry
in hosts file
TRACE neutron.agent.dhcp.agent ip = host[2].strip('[]')
TRACE neutron.agent.dhcp.agent IndexError: list index out of range

Neutron creates entries in dhcp host file for each subnet of a port.
Each of these entries will have same mac address as first field,
and may have client_id, fqdn, ipv4/ipv6 address for dhcp/dhcpv6 stateful,
or tag as other fields.

For dhcpv6 stateless subnet with extra_dhcp_opts,
host file will have only mac address and tag. So _read_hosts_file_leases
shouldn't check for ip address for this entry in host file.

Closes-bug: #1465330
Change-Id: Iad6605ac5c7bcd6ec9204352037ed021f5007738

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

index 7650c3ebbf6536b13dbaa85feaaad47476c3445b..a1e9d15277ecb541076a4c6ab97c1adedfe47d51 100644 (file)
@@ -598,6 +598,8 @@ class Dnsmasq(DhcpLocalProcess):
                     host = l.strip().split(',')
                     mac = host[0]
                     client_id = None
+                    if host[1].startswith('set:'):
+                        continue
                     if host[1].startswith(self._ID):
                         ip = host[3].strip('[]')
                         client_id = host[1][len(self._ID):]
index 483680326a4df3f80a49cc6d2688d885011eefe1..4185f391d2782bbb279b920bc00bd75420b5d5f8 100644 (file)
@@ -1506,6 +1506,23 @@ class TestDnsmasq(TestBase):
                                'client2')]), leases)
         mock_open.assert_called_once_with(filename)
 
+    def test_read_hosts_file_leases_with_stateless_IPv6_tag(self):
+        filename = self.get_temp_file_path('leases')
+        with open(filename, "w") as leasesfile:
+            lines = [
+                "00:00:80:aa:bb:cc,id:client1,inst-name,192.168.0.1\n",
+                "00:00:80:aa:bb:cc,set:ccccccccc-cccc-cccc-cccc-cccccccc\n",
+                "00:00:80:aa:bb:cc,id:client2,inst-name,[fdca:3ba5:a17a::1]\n"]
+            for line in lines:
+                leasesfile.write(line)
+
+        dnsmasq = self._get_dnsmasq(FakeDualNetwork())
+        leases = dnsmasq._read_hosts_file_leases(filename)
+
+        self.assertEqual(set([("192.168.0.1", "00:00:80:aa:bb:cc", 'client1'),
+                              ("fdca:3ba5:a17a::1", "00:00:80:aa:bb:cc",
+                              'client2')]), leases)
+
     def test_make_subnet_interface_ip_map(self):
         with mock.patch('neutron.agent.linux.ip_lib.IPDevice') as ip_dev:
             ip_dev.return_value.addr.list.return_value = [