From 9ed18eb0e1aeb87a43ab44f8b5f6979f084f2845 Mon Sep 17 00:00:00 2001 From: Gary Kotton Date: Sun, 19 Aug 2012 10:20:49 -0400 Subject: [PATCH] Linuxbridge support for L3 agent 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 | 6 +++-- quantum/agent/linux/interface.py | 27 ++++++++++++------- .../plugins/linuxbridge/lb_quantum_plugin.py | 10 +++++-- quantum/tests/unit/test_linux_interface.py | 6 ++--- 4 files changed, 32 insertions(+), 17 deletions(-) diff --git a/quantum/agent/l3_agent.py b/quantum/agent/l3_agent.py index 098db3b3e..ac43d9df1 100644 --- a/quantum/agent/l3_agent.py +++ b/quantum/agent/l3_agent.py @@ -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()) diff --git a/quantum/agent/linux/interface.py b/quantum/agent/linux/interface.py index af9193c67..a8e5eeb83 100644 --- a/quantum/agent/linux/interface.py +++ b/quantum/agent/linux/interface.py @@ -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) diff --git a/quantum/plugins/linuxbridge/lb_quantum_plugin.py b/quantum/plugins/linuxbridge/lb_quantum_plugin.py index d657ce951..a60f9e02d 100644 --- a/quantum/plugins/linuxbridge/lb_quantum_plugin.py +++ b/quantum/plugins/linuxbridge/lb_quantum_plugin.py @@ -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) diff --git a/quantum/tests/unit/test_linux_interface.py b/quantum/tests/unit/test_linux_interface.py index 61dd2be1f..f7dfaa187 100644 --- a/quantum/tests/unit/test_linux_interface.py +++ b/quantum/tests/unit/test_linux_interface.py @@ -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'), -- 2.45.2