]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Omit mode keyword when spawning dnsmasq with some ipv6 subnets
authorAlexander Ignatov <aignatov@mirantis.com>
Thu, 3 Jul 2014 09:51:14 +0000 (13:51 +0400)
committerAlexander Ignatov <aignatov@mirantis.com>
Thu, 3 Jul 2014 14:19:27 +0000 (18:19 +0400)
Fix UnboundLocalError for certain cases of ipv6 subnets

Closes-Bug: #1335959
Change-Id: I5e4b94d9ba1b13b72e2300b53d5638968e0d3401

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

index f0b0ec05e90674fe87d2b27ec8d91def9f56ecab..7ea1cdb938171743681adaf20ca3aee70195ca62 100644 (file)
@@ -359,6 +359,7 @@ class Dnsmasq(DhcpLocalProcess):
 
         possible_leases = 0
         for i, subnet in enumerate(self.network.subnets):
+            mode = None
             # if a subnet is specified to have dhcp disabled
             if not subnet.enable_dhcp:
                 continue
@@ -373,6 +374,7 @@ class Dnsmasq(DhcpLocalProcess):
                 elif getattr(subnet, 'ipv6_ra_mode', None) is None:
                     # RA mode is not set - do not launch dnsmasq
                     continue
+
             if self.version >= self.MINIMUM_VERSION:
                 set_tag = 'set:'
             else:
@@ -385,9 +387,15 @@ class Dnsmasq(DhcpLocalProcess):
             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, lease))
+            # mode is optional and is not set - skip it
+            if mode:
+                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
 
index e3479c5b144d4502bce0145db1fb444c40a20a25..14b80c792192bc119257fb10618fd73230786037 100644 (file)
@@ -684,7 +684,8 @@ class TestDhcpLocalProcess(TestBase):
 
 class TestDnsmasq(TestBase):
     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):
             return '/dhcp/%s/%s' % (network.id, kind)
 
@@ -719,7 +720,11 @@ class TestDnsmasq(TestBase):
             lease_duration = 'infinite'
         else:
             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)
                         for i, s in enumerate(network.subnets))
 
@@ -765,6 +770,14 @@ class TestDnsmasq(TestBase):
         self.conf.set_override('dhcp_domain', '')
         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):
         self.conf.set_override('dnsmasq_dns_servers', ['8.8.8.8'])
         self._test_spawn(['--conf-file=',