From 633c52cca1b383af2c900e1663c8682114acd177 Mon Sep 17 00:00:00 2001 From: sridhargaddam Date: Wed, 5 Aug 2015 10:49:33 +0000 Subject: [PATCH] Avoid dhcp_release for ipv6 addresses dhcp_release is only supported for IPv4 addresses [1] and not for IPv6 addresses [2]. There will be no effect when it is called with IPv6 address. This patch adds a corresponding note and avoids calling dhcp_release for IPv6 addresses. [1] http://manpages.ubuntu.com/manpages/trusty/man1/dhcp_release.1.html [2] http://lists.thekelleys.org.uk/pipermail/dnsmasq-discuss/2013q2/007084.html Change-Id: I8b8316c9d3d011c2a687a3a1e2a4da5cf1b5d604 --- neutron/agent/linux/dhcp.py | 5 +++++ neutron/tests/unit/agent/linux/test_dhcp.py | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/neutron/agent/linux/dhcp.py b/neutron/agent/linux/dhcp.py index 597f460b5..0ac27b241 100644 --- a/neutron/agent/linux/dhcp.py +++ b/neutron/agent/linux/dhcp.py @@ -422,6 +422,11 @@ class Dnsmasq(DhcpLocalProcess): def _release_lease(self, mac_address, ip, client_id): """Release a DHCP lease.""" + if netaddr.IPAddress(ip).version == constants.IP_VERSION_6: + # Note(SridharG) dhcp_release is only supported for IPv4 + # addresses. For more details, please refer to man page. + return + cmd = ['dhcp_release', self.interface_name, ip, mac_address] if client_id: cmd.append(client_id) diff --git a/neutron/tests/unit/agent/linux/test_dhcp.py b/neutron/tests/unit/agent/linux/test_dhcp.py index 61f4ea66e..1e2631dae 100644 --- a/neutron/tests/unit/agent/linux/test_dhcp.py +++ b/neutron/tests/unit/agent/linux/test_dhcp.py @@ -1514,6 +1514,24 @@ class TestDnsmasq(TestBase): [mock.call(dnsmasq.interface_name, namespace=dnsmasq.network.namespace)]) + def test_release_for_ipv6_lease(self): + dnsmasq = self._get_dnsmasq(FakeDualNetwork()) + + ip1 = 'fdca:3ba5:a17a::1' + mac1 = '00:00:80:aa:bb:cc' + ip2 = '192.168.1.3' + mac2 = '00:00:80:cc:bb:aa' + + old_leases = set([(ip1, mac1, None), (ip2, mac2, None)]) + dnsmasq._read_hosts_file_leases = mock.Mock(return_value=old_leases) + ipw = mock.patch( + 'neutron.agent.linux.ip_lib.IpNetnsCommand.execute').start() + dnsmasq._release_unused_leases() + # Verify that dhcp_release is called only for ipv4 addresses. + self.assertEqual(1, ipw.call_count) + ipw.assert_has_calls([mock.call(['dhcp_release', None, ip2, mac2], + run_as_root=True)]) + def test_release_unused_leases_with_dhcp_port(self): dnsmasq = self._get_dnsmasq(FakeNetworkDhcpPort()) ip1 = '192.168.1.2' -- 2.45.2