From: Neil Jerram Date: Mon, 27 Jul 2015 13:26:59 +0000 (+0100) Subject: DHCP agent: add 'bridged' property to interface driver X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=298d225e2962d41ae08f2777facc938a84bf4ef9;p=openstack-build%2Fneutron-build.git DHCP agent: add 'bridged' property to interface driver This allows a custom interface driver to use the reference DHCP agent to provide DHCP service to unbridged TAP interfaces, by overriding the definition of the property as follows. @property def bridged(self): return False Partial-Bug: #1486649 Change-Id: I2c6bbd9df6833a65088173b021790eb23e64616b --- diff --git a/neutron/agent/linux/dhcp.py b/neutron/agent/linux/dhcp.py index e7159893b..12f981588 100644 --- a/neutron/agent/linux/dhcp.py +++ b/neutron/agent/linux/dhcp.py @@ -307,8 +307,6 @@ class Dnsmasq(DhcpLocalProcess): '--no-hosts', '--no-resolv', '--strict-order', - '--bind-interfaces', - '--interface=%s' % self.interface_name, '--except-interface=lo', '--pid-file=%s' % pid_file, '--dhcp-hostsfile=%s' % self.get_conf_file_name('host'), @@ -317,6 +315,18 @@ class Dnsmasq(DhcpLocalProcess): '--dhcp-leasefile=%s' % self.get_conf_file_name('leases'), '--dhcp-match=set:ipxe,175', ] + if self.device_manager.driver.bridged: + cmd += [ + '--bind-interfaces', + '--interface=%s' % self.interface_name, + ] + else: + cmd += [ + '--bind-dynamic', + '--interface=%s' % self.interface_name, + '--interface=tap*', + '--bridge-interface=%s,tap*' % self.interface_name, + ] possible_leases = 0 for i, subnet in enumerate(self.network.subnets): diff --git a/neutron/agent/linux/interface.py b/neutron/agent/linux/interface.py index 9207503e7..a9dd3d2b8 100644 --- a/neutron/agent/linux/interface.py +++ b/neutron/agent/linux/interface.py @@ -170,6 +170,23 @@ class LinuxInterfaceDriver(object): def unplug(self, device_name, bridge=None, namespace=None, prefix=None): """Unplug the interface.""" + @property + def bridged(self): + """Whether the DHCP port is bridged to the VM TAP interfaces. + + When the DHCP port is bridged to the TAP interfaces for the + VMs for which it is providing DHCP service - as is the case + for most Neutron network implementations - the DHCP server + only needs to listen on the DHCP port, and will still receive + DHCP requests from all the relevant VMs. + + If the DHCP port is not bridged to the relevant VM TAP + interfaces, the DHCP server needs to listen explicitly on + those TAP interfaces, and to treat those as aliases of the + DHCP port where the IP subnet is defined. + """ + return True + class NullDriver(LinuxInterfaceDriver): def plug_new(self, network_id, port_id, device_name, mac_address, diff --git a/neutron/tests/unit/agent/linux/test_dhcp.py b/neutron/tests/unit/agent/linux/test_dhcp.py index 9a6115df8..b9d85c228 100644 --- a/neutron/tests/unit/agent/linux/test_dhcp.py +++ b/neutron/tests/unit/agent/linux/test_dhcp.py @@ -725,6 +725,8 @@ class TestBase(base.BaseTestCase): self.external_process = mock.patch( 'neutron.agent.linux.external_process.ProcessManager').start() + self.mock_mgr.return_value.driver.bridged = True + class TestDhcpBase(TestBase): @@ -923,15 +925,16 @@ class TestDnsmasq(TestBase): '--no-hosts', '--no-resolv', '--strict-order', - '--bind-interfaces', - '--interface=tap0', '--except-interface=lo', '--pid-file=%s' % expected_pid_file, '--dhcp-hostsfile=/dhcp/%s/host' % network.id, '--addn-hosts=/dhcp/%s/addn_hosts' % network.id, '--dhcp-optsfile=/dhcp/%s/opts' % network.id, '--dhcp-leasefile=/dhcp/%s/leases' % network.id, - '--dhcp-match=set:ipxe,175'] + '--dhcp-match=set:ipxe,175', + '--bind-interfaces', + '--interface=tap0', + ] seconds = '' if lease_duration == -1: