From e55f7f690a35654b0ec7f180b371fc7844de2724 Mon Sep 17 00:00:00 2001 From: "Alexey I. Froloff" Date: Tue, 2 Dec 2014 15:43:25 +0300 Subject: [PATCH] Strip square brackets from IPv6 addresses When releasing old DHCP leases, square brackets around IPv6 addresses should be stripped while reading dnsmasq hosts file. Change-Id: Ia1e6d3a3cba30c94a1faa157d1d83da7beb523c4 Closes-bug: #1398380 --- neutron/agent/linux/dhcp.py | 2 +- neutron/tests/unit/test_linux_dhcp.py | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/neutron/agent/linux/dhcp.py b/neutron/agent/linux/dhcp.py index cc57c78061..d4426abbff 100644 --- a/neutron/agent/linux/dhcp.py +++ b/neutron/agent/linux/dhcp.py @@ -532,7 +532,7 @@ class Dnsmasq(DhcpLocalProcess): with open(filename) as f: for l in f.readlines(): host = l.strip().split(',') - leases.add((host[2], host[0])) + leases.add((host[2].strip('[]'), host[0])) return leases def _release_unused_leases(self): diff --git a/neutron/tests/unit/test_linux_dhcp.py b/neutron/tests/unit/test_linux_dhcp.py index 39edd30a8f..35ddd286c0 100644 --- a/neutron/tests/unit/test_linux_dhcp.py +++ b/neutron/tests/unit/test_linux_dhcp.py @@ -1274,13 +1274,16 @@ tag:tag0,option:router""".lstrip() with mock.patch('__builtin__.open') as mock_open: mock_open.return_value.__enter__ = lambda s: s mock_open.return_value.__exit__ = mock.Mock() - lines = ["00:00:80:aa:bb:cc,inst-name,192.168.0.1"] + lines = ["00:00:80:aa:bb:cc,inst-name,192.168.0.1", + "00:00:80:aa:bb:cc,inst-name,[fdca:3ba5:a17a::1]"] mock_open.return_value.readlines.return_value = lines dnsmasq = dhcp.Dnsmasq(self.conf, FakeDualNetwork()) leases = dnsmasq._read_hosts_file_leases(filename) - self.assertEqual(set([("192.168.0.1", "00:00:80:aa:bb:cc")]), leases) + self.assertEqual(set([("192.168.0.1", "00:00:80:aa:bb:cc"), + ("fdca:3ba5:a17a::1", "00:00:80:aa:bb:cc")]), + leases) mock_exists.assert_called_once_with(filename) mock_open.assert_called_once_with(filename)