]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Linuxbridge support for L3 agent
authorGary Kotton <gkotton@redhat.com>
Sun, 19 Aug 2012 14:20:49 +0000 (10:20 -0400)
committerGary Kotton <gkotton@redhat.com>
Sun, 19 Aug 2012 15:02:06 +0000 (11:02 -0400)
Fixes bug 1037245

For the linux bridge this changes the generic interface name prefix
from "dhc" to "ns-".

Change-Id: I37078dadcbffa7e0b45d1523e7a03bb7c0d36919

quantum/agent/l3_agent.py
quantum/agent/linux/interface.py
quantum/plugins/linuxbridge/lb_quantum_plugin.py
quantum/tests/unit/test_linux_interface.py

index 098db3b3e09cc39aa6ba6b9ef7e5a7a669f9c9e5..ac43d9df114db224e5dbff56dbba5e68f42b1e10 100644 (file)
@@ -276,7 +276,8 @@ class L3NATAgent(object):
             self.driver.plug(None, ex_gw_port['id'], interface_name,
                              ex_gw_port['mac_address'],
                              bridge=self.conf.external_network_bridge,
-                             namespace=ri.ns_name())
+                             namespace=ri.ns_name(),
+                             prefix=EXTERNAL_DEV_PREFIX)
         self.driver.init_l3(interface_name, [ex_gw_port['ip_cidr']],
                             namespace=ri.ns_name())
 
@@ -331,7 +332,8 @@ class L3NATAgent(object):
                                     root_helper=self.conf.root_helper,
                                     namespace=ri.ns_name()):
             self.driver.plug(None, port_id, interface_name, mac_address,
-                             namespace=ri.ns_name())
+                             namespace=ri.ns_name(),
+                             prefix=INTERNAL_DEV_PREFIX)
 
         self.driver.init_l3(interface_name, [internal_cidr],
                             namespace=ri.ns_name())
index af9193c67e752c6ff22f41ee28703169d8c97f7d..a8e5eeb833862d8d4d29da4cb520295aa77cf8bb 100644 (file)
@@ -86,7 +86,7 @@ class LinuxInterfaceDriver(object):
 
     @abc.abstractmethod
     def plug(self, network_id, port_id, device_name, mac_address,
-             bridge=None, namespace=None):
+             bridge=None, namespace=None, prefix=None):
         """Plug in the interface."""
 
     @abc.abstractmethod
@@ -96,7 +96,7 @@ class LinuxInterfaceDriver(object):
 
 class NullDriver(LinuxInterfaceDriver):
     def plug(self, network_id, port_id, device_name, mac_address,
-             bridge=None, namespace=None):
+             bridge=None, namespace=None, prefix=None):
         pass
 
     def unplug(self, device_name, bridge=None, namespace=None):
@@ -107,7 +107,7 @@ class OVSInterfaceDriver(LinuxInterfaceDriver):
     """Driver for creating an internal interface on an OVS bridge."""
 
     def plug(self, network_id, port_id, device_name, mac_address,
-             bridge=None, namespace=None):
+             bridge=None, namespace=None, prefix=None):
         """Plug in the interface."""
         if not bridge:
             bridge = self.conf.ovs_integration_bridge
@@ -156,17 +156,21 @@ class OVSInterfaceDriver(LinuxInterfaceDriver):
 class BridgeInterfaceDriver(LinuxInterfaceDriver):
     """Driver for creating bridge interfaces."""
 
-    DEV_NAME_PREFIX = 'dhc'
+    DEV_NAME_PREFIX = 'ns-'
 
     def plug(self, network_id, port_id, device_name, mac_address,
-             bridge=None, namespace=None):
+             bridge=None, namespace=None, prefix=None):
         """Plugin the interface."""
         if not ip_lib.device_exists(device_name,
                                     self.conf.root_helper,
                                     namespace=namespace):
             ip = ip_lib.IPWrapper(self.conf.root_helper)
 
-            tap_name = device_name.replace(self.DEV_NAME_PREFIX, 'tap')
+            # Enable agent to define the prefix
+            if prefix:
+                tap_name = device_name.replace(prefix, 'tap')
+            else:
+                tap_name = device_name.replace(self.DEV_NAME_PREFIX, 'tap')
             root_veth, dhcp_veth = ip.add_veth(tap_name, device_name)
             root_veth.link.set_address(mac_address)
 
@@ -202,11 +206,12 @@ class RyuInterfaceDriver(OVSInterfaceDriver):
         self.ryu_client = OFPClient(self.conf.ryu_api_host)
 
     def plug(self, network_id, port_id, device_name, mac_address,
-             bridge=None, namespace=None):
+             bridge=None, namespace=None, prefix=None):
         """Plug in the interface."""
         super(RyuInterfaceDriver, self).plug(network_id, port_id, device_name,
                                              mac_address, bridge=bridge,
-                                             namespace=namespace)
+                                             namespace=namespace,
+                                             prefix=prefix)
         if not bridge:
             bridge = self.conf.ovs_integration_bridge
 
@@ -254,9 +259,11 @@ class MetaInterfaceDriver(LinuxInterfaceDriver):
         driver = self._get_driver_by_network_id(port.network_id)
         return driver.get_device_name(port)
 
-    def plug(self, network_id, port_id, device_name, mac_address):
+    def plug(self, network_id, port_id, device_name, mac_address,
+             bridge=None, namespace=None, prefix=None):
         driver = self._get_driver_by_network_id(network_id)
-        return driver.plug(network_id, port_id, device_name, mac_address)
+        return driver.plug(network_id, port_id, device_name, mac_address,
+                           bridge=bridge, namespace=namespace, prefix=prefix)
 
     def unplug(self, device_name):
         driver = self._get_driver_by_device_name(device_name)
index d657ce951b9a8f83d044233fbb4ad33d07fe74d0..a60f9e02de2e8b4d2abda364ece105575b8446a8 100644 (file)
@@ -23,6 +23,7 @@ from quantum.common import topics
 from quantum.db import api as db_api
 from quantum.db import db_base_plugin_v2
 from quantum.db import dhcp_rpc_base
+from quantum.db import l3_db
 from quantum.db import models_v2
 from quantum.openstack.common import context
 from quantum.openstack.common import cfg
@@ -131,7 +132,8 @@ class AgentNotifierApi(proxy.RpcProxy):
                          topic=self.topic_port_update)
 
 
-class LinuxBridgePluginV2(db_base_plugin_v2.QuantumDbPluginV2):
+class LinuxBridgePluginV2(db_base_plugin_v2.QuantumDbPluginV2,
+                          l3_db.L3_NAT_db_mixin):
     """Implement the Quantum abstractions using Linux bridging.
 
     A new VLAN is created for each network.  An agent is relied upon
@@ -150,7 +152,7 @@ class LinuxBridgePluginV2(db_base_plugin_v2.QuantumDbPluginV2):
     # is qualified by class
     __native_bulk_support = True
 
-    supported_extension_aliases = ["provider"]
+    supported_extension_aliases = ["provider", "os-quantum-router"]
 
     def __init__(self):
         db.initialize()
@@ -356,3 +358,7 @@ class LinuxBridgePluginV2(db_base_plugin_v2.QuantumDbPluginV2):
                                           binding.physical_network,
                                           binding.vlan_id)
         return port
+
+    def delete_port(self, context, id):
+        self.disassociate_floatingips(context, id)
+        return super(LinuxBridgePluginV2, self).delete_port(context, id)
index 61dd2be1fd2f1957b260fe4d5a9d5073649a75a5..f7dfaa1873f8b684c76aaeea901ff01c27c0127d 100644 (file)
@@ -174,7 +174,7 @@ class TestBridgeInterfaceDriver(TestBase):
     def test_get_device_name(self):
         br = interface.BridgeInterfaceDriver(self.conf)
         device_name = br.get_device_name(FakePort())
-        self.assertEqual('dhcabcdef01-12', device_name)
+        self.assertEqual('ns-abcdef01-12', device_name)
 
     def test_plug_no_ns(self):
         self._test_plug()
@@ -201,11 +201,11 @@ class TestBridgeInterfaceDriver(TestBase):
         br = interface.BridgeInterfaceDriver(self.conf)
         br.plug('01234567-1234-1234-99',
                 'port-1234',
-                'dhc0',
+                'ns-0',
                 'aa:bb:cc:dd:ee:ff',
                 namespace=namespace)
 
-        ip_calls = [mock.call('sudo'), mock.call().add_veth('tap0', 'dhc0')]
+        ip_calls = [mock.call('sudo'), mock.call().add_veth('tap0', 'ns-0')]
         if namespace:
             ip_calls.extend([
                 mock.call().ensure_namespace('01234567-1234-1234-99'),