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
This commit is contained in:
sridhargaddam 2015-08-05 10:49:33 +00:00
parent bbfd5cf486
commit 633c52cca1
2 changed files with 23 additions and 0 deletions

View File

@ -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)

View File

@ -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'