]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
dhcp: handle advertise_mtu=True when plugin does not set mtu values
authorIhar Hrachyshka <ihrachys@redhat.com>
Thu, 14 Jan 2016 15:06:20 +0000 (16:06 +0100)
committerIhar Hrachyshka <ihrachys@redhat.com>
Fri, 15 Jan 2016 08:40:41 +0000 (08:40 +0000)
DHCP agent may be used by plugins that don't set mtu value for networks.
Handle the case by not passing the DHCP option when network does not
have the value set.

Most plugins do set the value though, since it's enforced in base db
plugin class.

Closes-Bug: #1534197
Change-Id: I282b3d6b81f91eb8cea901d955cbcca6ecb2a95d

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

index 4ccb7f6593ba9ca578915294689e1c780379a14c..77b3c7de57b46dd725a499bc9b931aaa60a6dc0e 100644 (file)
@@ -368,7 +368,7 @@ class Dnsmasq(DhcpLocalProcess):
                 possible_leases += cidr.size
 
         if cfg.CONF.advertise_mtu:
-            mtu = self.network.mtu
+            mtu = getattr(self.network, 'mtu', 0)
             # Do not advertise unknown mtu
             if mtu > 0:
                 cmd.append('--dhcp-option-force=option:mtu,%d' % mtu)
index fe4016dc20390d736b8a8251b13aaa4b1a2f95f6..53ecd6033e4c0be6ef14be64990619ee35c185f7 100644 (file)
@@ -1037,7 +1037,9 @@ class TestDnsmasq(TestBase):
                 possible_leases += netaddr.IPNetwork(s.cidr).size
 
         if cfg.CONF.advertise_mtu:
-            expected.append('--dhcp-option-force=option:mtu,%s' % network.mtu)
+            if hasattr(network, 'mtu'):
+                expected.append(
+                    '--dhcp-option-force=option:mtu,%s' % network.mtu)
 
         expected.append('--dhcp-lease-max=%d' % min(
             possible_leases, max_leases))
@@ -1152,6 +1154,12 @@ class TestDnsmasq(TestBase):
         self._test_spawn(['--conf-file=', '--domain=openstacklocal'],
                          network)
 
+    def test_spawn_cfg_advertise_mtu_plugin_doesnt_pass_mtu_value(self):
+        cfg.CONF.set_override('advertise_mtu', True)
+        network = FakeV4Network()
+        self._test_spawn(['--conf-file=', '--domain=openstacklocal'],
+                         network)
+
     def _test_output_init_lease_file(self, timestamp):
         expected = [
             '00:00:80:aa:bb:cc 192.168.0.2 * *',