From: Ihar Hrachyshka Date: Thu, 14 Jan 2016 15:06:20 +0000 (+0100) Subject: dhcp: handle advertise_mtu=True when plugin does not set mtu values X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=36effd66006aaf078cf652de146f35f19f56bdca;p=openstack-build%2Fneutron-build.git dhcp: handle advertise_mtu=True when plugin does not set mtu values 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 --- diff --git a/neutron/agent/linux/dhcp.py b/neutron/agent/linux/dhcp.py index 4ccb7f659..77b3c7de5 100644 --- a/neutron/agent/linux/dhcp.py +++ b/neutron/agent/linux/dhcp.py @@ -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) diff --git a/neutron/tests/unit/agent/linux/test_dhcp.py b/neutron/tests/unit/agent/linux/test_dhcp.py index fe4016dc2..53ecd6033 100644 --- a/neutron/tests/unit/agent/linux/test_dhcp.py +++ b/neutron/tests/unit/agent/linux/test_dhcp.py @@ -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 * *',