# 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
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
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)
'--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)
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'])