Support 'infinite' dhcp_lease_duration

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
This commit is contained in:
Erik Colnick 2014-05-06 07:56:31 -06:00
parent 3b9c1bd97f
commit 624353b2a5
3 changed files with 25 additions and 11 deletions

View 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

View 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

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