]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Support 'infinite' dhcp_lease_duration
authorErik Colnick <erik.colnick@hp.com>
Tue, 6 May 2014 13:56:31 +0000 (07:56 -0600)
committerErik Colnick <erik.colnick@hp.com>
Wed, 28 May 2014 13:33:20 +0000 (07:33 -0600)
Process a dhcp_lease_duration value of -1 as 'infinite'
when setting the dnsmasq dhcp-range values to support
cases where it is undesirable for instance dhcp leases
to expire.

DocImpact

Closes-Bug: #1315430
Change-Id: I1cc3cfebfec355014e6d5b5cbd656a1300c43c0b

etc/neutron.conf
neutron/agent/linux/dhcp.py
neutron/tests/unit/test_linux_dhcp.py

index 984e93c0ef32e2a479a83ff4481e5270b81cba2f..8da95c97028733831b774d80d83aa6d1b6958522 100644 (file)
@@ -80,7 +80,8 @@ lock_path = $state_path/lock
 # Maximum amount of retries to generate a unique MAC address
 # mac_generation_retries = 16
 
-# DHCP Lease duration (in seconds)
+# DHCP Lease duration (in seconds).  Use -1 to
+# tell dnsmasq to use infinite lease times.
 # dhcp_lease_duration = 86400
 
 # Allow sending resource operation notification to DHCP agent
index c6153027a5255260b69ccc78e4cf7f1c135a301a..eb7d3ec7ad6285649a04124e1f5373910017b7d7 100644 (file)
@@ -347,11 +347,15 @@ class Dnsmasq(DhcpLocalProcess):
 
             cidr = netaddr.IPNetwork(subnet.cidr)
 
-            cmd.append('--dhcp-range=%s%s,%s,%s,%ss' %
+            if self.conf.dhcp_lease_duration == -1:
+                lease = 'infinite'
+            else:
+                lease = '%ss' % self.conf.dhcp_lease_duration
+
+            cmd.append('--dhcp-range=%s%s,%s,%s,%s' %
                        (set_tag, self._TAG_PREFIX % i,
-                        cidr.network,
-                        mode,
-                        self.conf.dhcp_lease_duration))
+                        cidr.network, mode, lease))
+
             possible_leases += cidr.size
 
         # Cap the limit because creating lots of subnets can inflate
index 137b07557445e874f97b5e607cb61603b6a05bc4..76bce4042dbecceb4995c5d0981e21b0f0c146e6 100644 (file)
@@ -648,7 +648,7 @@ class TestDhcpLocalProcess(TestBase):
 
 class TestDnsmasq(TestBase):
     def _test_spawn(self, extra_options, network=FakeDualNetwork(),
-                    max_leases=16777216):
+                    max_leases=16777216, lease_duration=86400):
         def mock_get_conf_file_name(kind, ensure_conf_dir=False):
             return '/dhcp/%s/%s' % (network.id, kind)
 
@@ -678,11 +678,15 @@ class TestDnsmasq(TestBase):
             '--dhcp-optsfile=/dhcp/%s/opts' % network.id,
             '--leasefile-ro']
 
-        expected.extend(
-            '--dhcp-range=set:tag%d,%s,static,86400s' %
-            (i, s.cidr.split('/')[0])
-            for i, s in enumerate(network.subnets)
-        )
+        seconds = ''
+        if lease_duration == -1:
+            lease_duration = 'infinite'
+        else:
+            seconds = 's'
+        expected.extend('--dhcp-range=set:tag%d,%s,static,%s%s' %
+                        (i, s.cidr.split('/')[0], lease_duration, seconds)
+                        for i, s in enumerate(network.subnets))
+
         expected.append('--dhcp-lease-max=%d' % max_leases)
         expected.extend(extra_options)
 
@@ -712,6 +716,11 @@ class TestDnsmasq(TestBase):
     def test_spawn(self):
         self._test_spawn(['--conf-file=', '--domain=openstacklocal'])
 
+    def test_spawn_infinite_lease_duration(self):
+        self.conf.set_override('dhcp_lease_duration', -1)
+        self._test_spawn(['--conf-file=', '--domain=openstacklocal'],
+                         FakeDualNetwork(), 16777216, -1)
+
     def test_spawn_cfg_config_file(self):
         self.conf.set_override('dnsmasq_config_file', '/foo')
         self._test_spawn(['--conf-file=/foo', '--domain=openstacklocal'])