]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Avoid dhcp_release for ipv6 addresses
authorsridhargaddam <sridhar.gaddam@enovance.com>
Wed, 5 Aug 2015 10:49:33 +0000 (10:49 +0000)
committersridhargaddam <sridhar.gaddam@enovance.com>
Mon, 10 Aug 2015 08:31:48 +0000 (08:31 +0000)
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
neutron/tests/unit/agent/linux/test_dhcp.py

index 597f460b58a0fb8a6a78247133bad4a4f2bc1309..0ac27b241a372021d8fbbb66fc7b18fbcbf4ac96 100644 (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)
index 61f4ea66ef8d471d8e7b2e8c262a95e76ce17dee..1e2631dae4d70decf7cdf8684139369d51cc765e 100644 (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'