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
This commit is contained in:
Ihar Hrachyshka 2016-01-14 16:06:20 +01:00
parent 2c599814fb
commit 36effd6600
2 changed files with 10 additions and 2 deletions

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

View 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 * *',