]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
DHCP agent: add 'bridged' property to interface driver
authorNeil Jerram <Neil.Jerram@metaswitch.com>
Mon, 27 Jul 2015 13:26:59 +0000 (14:26 +0100)
committerNeil Jerram <Neil.Jerram@metaswitch.com>
Wed, 26 Aug 2015 15:55:26 +0000 (16:55 +0100)
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

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

index e7159893b1bfcf42a8f1a21df76c34fd9a5f3170..12f9815888dc0471414c39cb59d50d6a7d125f69 100644 (file)
@@ -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):
index 9207503e7ac4dfcd79038d88f9d109b20747ac7b..a9dd3d2b83305a2efa07fa14f71f9f54b6bbd2cd 100644 (file)
@@ -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,
index 9a6115df8e89bd9f29e1ebe49dd7dd0ac3ba7ad1..b9d85c22823ecc9bc42411ef07519172da16b13c 100644 (file)
@@ -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: