Merge "Omit mode keyword when spawning dnsmasq with some ipv6 subnets"

This commit is contained in:
Jenkins 2014-07-08 11:32:49 +00:00 committed by Gerrit Code Review
commit 8e600ec5b1
2 changed files with 26 additions and 5 deletions

View File

@ -359,6 +359,7 @@ class Dnsmasq(DhcpLocalProcess):
possible_leases = 0 possible_leases = 0
for i, subnet in enumerate(self.network.subnets): for i, subnet in enumerate(self.network.subnets):
mode = None
# if a subnet is specified to have dhcp disabled # if a subnet is specified to have dhcp disabled
if not subnet.enable_dhcp: if not subnet.enable_dhcp:
continue continue
@ -373,6 +374,7 @@ class Dnsmasq(DhcpLocalProcess):
elif getattr(subnet, 'ipv6_ra_mode', None) is None: elif getattr(subnet, 'ipv6_ra_mode', None) is None:
# RA mode is not set - do not launch dnsmasq # RA mode is not set - do not launch dnsmasq
continue continue
if self.version >= self.MINIMUM_VERSION: if self.version >= self.MINIMUM_VERSION:
set_tag = 'set:' set_tag = 'set:'
else: else:
@ -385,9 +387,15 @@ class Dnsmasq(DhcpLocalProcess):
else: else:
lease = '%ss' % self.conf.dhcp_lease_duration lease = '%ss' % self.conf.dhcp_lease_duration
cmd.append('--dhcp-range=%s%s,%s,%s,%s' % # mode is optional and is not set - skip it
(set_tag, self._TAG_PREFIX % i, if mode:
cidr.network, mode, lease)) cmd.append('--dhcp-range=%s%s,%s,%s,%s' %
(set_tag, self._TAG_PREFIX % i,
cidr.network, mode, lease))
else:
cmd.append('--dhcp-range=%s%s,%s,%s' %
(set_tag, self._TAG_PREFIX % i,
cidr.network, lease))
possible_leases += cidr.size possible_leases += cidr.size

View File

@ -684,7 +684,8 @@ class TestDhcpLocalProcess(TestBase):
class TestDnsmasq(TestBase): class TestDnsmasq(TestBase):
def _test_spawn(self, extra_options, network=FakeDualNetwork(), def _test_spawn(self, extra_options, network=FakeDualNetwork(),
max_leases=16777216, lease_duration=86400): max_leases=16777216, lease_duration=86400,
has_static=True):
def mock_get_conf_file_name(kind, ensure_conf_dir=False): def mock_get_conf_file_name(kind, ensure_conf_dir=False):
return '/dhcp/%s/%s' % (network.id, kind) return '/dhcp/%s/%s' % (network.id, kind)
@ -719,7 +720,11 @@ class TestDnsmasq(TestBase):
lease_duration = 'infinite' lease_duration = 'infinite'
else: else:
seconds = 's' seconds = 's'
expected.extend('--dhcp-range=set:tag%d,%s,static,%s%s' % if has_static:
prefix = '--dhcp-range=set:tag%d,%s,static,%s%s'
else:
prefix = '--dhcp-range=set:tag%d,%s,%s%s'
expected.extend(prefix %
(i, s.cidr.split('/')[0], lease_duration, seconds) (i, s.cidr.split('/')[0], lease_duration, seconds)
for i, s in enumerate(network.subnets)) for i, s in enumerate(network.subnets))
@ -765,6 +770,14 @@ class TestDnsmasq(TestBase):
self.conf.set_override('dhcp_domain', '') self.conf.set_override('dhcp_domain', '')
self._test_spawn(['--conf-file=']) self._test_spawn(['--conf-file='])
def test_spawn_no_dnsmasq_ipv6_mode(self):
network = FakeV6Network()
subnet = FakeV6Subnet()
subnet.ipv6_ra_mode = True
network.subnets = [subnet]
self._test_spawn(['--conf-file=', '--domain=openstacklocal'],
network, has_static=False)
def test_spawn_cfg_dns_server(self): def test_spawn_cfg_dns_server(self):
self.conf.set_override('dnsmasq_dns_servers', ['8.8.8.8']) self.conf.set_override('dnsmasq_dns_servers', ['8.8.8.8'])
self._test_spawn(['--conf-file=', self._test_spawn(['--conf-file=',