From: Sam Betts Date: Tue, 26 Aug 2014 17:35:36 +0000 (+0100) Subject: Added TAP_DEVICE_PREFIX info to common/constants X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=5e4c14e850e2757bf74a806aaaab4c053bab741d;p=openstack-build%2Fneutron-build.git Added TAP_DEVICE_PREFIX info to common/constants Change-Id: Ia84629732490585164237ca4f7d1db90bde9fbf2 Closes-Bug: 1361573 --- diff --git a/neutron/agent/linux/interface.py b/neutron/agent/linux/interface.py index c6677c114..3a99c1a2e 100644 --- a/neutron/agent/linux/interface.py +++ b/neutron/agent/linux/interface.py @@ -23,6 +23,7 @@ from neutron.agent.common import config from neutron.agent.linux import ip_lib from neutron.agent.linux import ovs_lib from neutron.agent.linux import utils +from neutron.common import constants as n_const from neutron.common import exceptions from neutron.extensions import flavor from neutron.openstack.common import importutils @@ -63,7 +64,7 @@ class LinuxInterfaceDriver(object): # from linux IF_NAMESIZE DEV_NAME_LEN = 14 - DEV_NAME_PREFIX = 'tap' + DEV_NAME_PREFIX = n_const.TAP_DEVICE_PREFIX def __init__(self, conf): self.conf = conf @@ -142,7 +143,7 @@ class NullDriver(LinuxInterfaceDriver): class OVSInterfaceDriver(LinuxInterfaceDriver): """Driver for creating an internal interface on an OVS bridge.""" - DEV_NAME_PREFIX = 'tap' + DEV_NAME_PREFIX = n_const.TAP_DEVICE_PREFIX def __init__(self, conf): super(OVSInterfaceDriver, self).__init__(conf) @@ -151,7 +152,8 @@ class OVSInterfaceDriver(LinuxInterfaceDriver): def _get_tap_name(self, dev_name, prefix=None): if self.conf.ovs_use_veth: - dev_name = dev_name.replace(prefix or self.DEV_NAME_PREFIX, 'tap') + dev_name = dev_name.replace(prefix or self.DEV_NAME_PREFIX, + n_const.TAP_DEVICE_PREFIX) return dev_name def _ovs_add_port(self, bridge, device_name, port_id, mac_address, @@ -246,7 +248,8 @@ class MidonetInterfaceDriver(LinuxInterfaceDriver): self.root_helper, namespace=namespace): ip = ip_lib.IPWrapper(self.root_helper) - tap_name = device_name.replace(prefix or 'tap', 'tap') + tap_name = device_name.replace(prefix or n_const.TAP_DEVICE_PREFIX, + n_const.TAP_DEVICE_PREFIX) # Create ns_dev in a namespace if one is configured. root_dev, ns_dev = ip.add_veth(tap_name, device_name, @@ -285,14 +288,15 @@ class MidonetInterfaceDriver(LinuxInterfaceDriver): class IVSInterfaceDriver(LinuxInterfaceDriver): """Driver for creating an internal interface on an IVS bridge.""" - DEV_NAME_PREFIX = 'tap' + DEV_NAME_PREFIX = n_const.TAP_DEVICE_PREFIX def __init__(self, conf): super(IVSInterfaceDriver, self).__init__(conf) self.DEV_NAME_PREFIX = 'ns-' def _get_tap_name(self, dev_name, prefix=None): - dev_name = dev_name.replace(prefix or self.DEV_NAME_PREFIX, 'tap') + dev_name = dev_name.replace(prefix or self.DEV_NAME_PREFIX, + n_const.TAP_DEVICE_PREFIX) return dev_name def _ivs_add_port(self, device_name, port_id, mac_address): @@ -359,10 +363,8 @@ class BridgeInterfaceDriver(LinuxInterfaceDriver): ip = ip_lib.IPWrapper(self.root_helper) # 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') + tap_name = device_name.replace(prefix or self.DEV_NAME_PREFIX, + n_const.TAP_DEVICE_PREFIX) # Create ns_veth in a namespace if one is configured. root_veth, ns_veth = ip.add_veth(tap_name, device_name, namespace2=namespace) diff --git a/neutron/agent/linux/iptables_firewall.py b/neutron/agent/linux/iptables_firewall.py index ec37306a5..c7cafc0d0 100644 --- a/neutron/agent/linux/iptables_firewall.py +++ b/neutron/agent/linux/iptables_firewall.py @@ -439,7 +439,7 @@ class IptablesFirewallDriver(firewall.FirewallDriver): class OVSHybridIptablesFirewallDriver(IptablesFirewallDriver): - OVS_HYBRID_TAP_PREFIX = 'tap' + OVS_HYBRID_TAP_PREFIX = constants.TAP_DEVICE_PREFIX def _port_chain_name(self, port, direction): return iptables_manager.get_chain_name( diff --git a/neutron/common/constants.py b/neutron/common/constants.py index f1c15c535..1d85e0f86 100644 --- a/neutron/common/constants.py +++ b/neutron/common/constants.py @@ -130,3 +130,6 @@ IPV6_LLA_PREFIX = 'fe80::/64' # Linux interface max length DEVICE_NAME_MAX_LEN = 15 + +# Device names start with "tap" +TAP_DEVICE_PREFIX = 'tap' diff --git a/neutron/plugins/bigswitch/plugin.py b/neutron/plugins/bigswitch/plugin.py index 728a5dd0c..9ecc0140e 100644 --- a/neutron/plugins/bigswitch/plugin.py +++ b/neutron/plugins/bigswitch/plugin.py @@ -115,7 +115,7 @@ class AgentNotifierApi(n_rpc.RpcProxy, class SecurityGroupServerRpcMixin(sg_db_rpc.SecurityGroupServerRpcMixin): def get_port_from_device(self, device): - port_id = re.sub(r"^tap", "", device) + port_id = re.sub(r"^%s" % const.TAP_DEVICE_PREFIX, "", device) port = self.get_port_and_sgs(port_id) if port: port['device'] = device diff --git a/neutron/plugins/brocade/NeutronPlugin.py b/neutron/plugins/brocade/NeutronPlugin.py index 7b46e04bc..5d9e431e4 100644 --- a/neutron/plugins/brocade/NeutronPlugin.py +++ b/neutron/plugins/brocade/NeutronPlugin.py @@ -58,7 +58,6 @@ LOG = logging.getLogger(__name__) PLUGIN_VERSION = 0.88 AGENT_OWNER_PREFIX = "network:" NOS_DRIVER = 'neutron.plugins.brocade.nos.nosdriver.NOSdriver' -TAP_PREFIX_LEN = 3 SWITCH_OPTS = [cfg.StrOpt('address', default='', help=_('The address of the host to SSH to')), @@ -95,7 +94,8 @@ class BridgeRpcCallbacks(n_rpc.RpcCallback): device = kwargs.get('device') LOG.debug(_("Device %(device)s details requested from %(agent_id)s"), {'device': device, 'agent_id': agent_id}) - port = brocade_db.get_port(rpc_context, device[TAP_PREFIX_LEN:]) + port = brocade_db.get_port(rpc_context, + device[len(q_const.TAP_DEVICE_PREFIX):]) if port: entry = {'device': device, 'vlan_id': port.vlan_id, @@ -155,7 +155,7 @@ class SecurityGroupServerRpcMixin(sg_db_rpc.SecurityGroupServerRpcMixin): # Doing what other plugins are doing session = db.get_session() port = brocade_db.get_port_from_device( - session, device[TAP_PREFIX_LEN:]) + session, device[len(q_const.TAP_DEVICE_PREFIX):]) # TODO(shiv): need to extend the db model to include device owners # make it appears that the device owner is of type network diff --git a/neutron/plugins/linuxbridge/agent/linuxbridge_neutron_agent.py b/neutron/plugins/linuxbridge/agent/linuxbridge_neutron_agent.py index 7d608c3e6..8663b4c76 100755 --- a/neutron/plugins/linuxbridge/agent/linuxbridge_neutron_agent.py +++ b/neutron/plugins/linuxbridge/agent/linuxbridge_neutron_agent.py @@ -51,7 +51,6 @@ from neutron.plugins.linuxbridge.common import constants as lconst LOG = logging.getLogger(__name__) BRIDGE_NAME_PREFIX = "brq" -TAP_INTERFACE_PREFIX = "tap" BRIDGE_FS = "/sys/devices/virtual/net/" BRIDGE_NAME_PLACEHOLDER = "bridge_name" BRIDGE_INTERFACES_FS = BRIDGE_FS + BRIDGE_NAME_PLACEHOLDER + "/brif/" @@ -110,7 +109,7 @@ class LinuxBridgeManager: if not interface_id: LOG.warning(_("Invalid Interface ID, will lead to incorrect " "tap device name")) - tap_device_name = TAP_INTERFACE_PREFIX + interface_id[0:11] + tap_device_name = constants.TAP_DEVICE_PREFIX + interface_id[0:11] return tap_device_name def get_vxlan_device_name(self, segmentation_id): @@ -142,7 +141,7 @@ class LinuxBridgeManager: try: if_list = os.listdir(bridge_interface_path) return len([interface for interface in if_list if - interface.startswith(TAP_INTERFACE_PREFIX)]) + interface.startswith(constants.TAP_DEVICE_PREFIX)]) except OSError: return 0 @@ -510,7 +509,7 @@ class LinuxBridgeManager: def get_tap_devices(self): devices = set() for device in os.listdir(BRIDGE_FS): - if device.startswith(TAP_INTERFACE_PREFIX): + if device.startswith(constants.TAP_DEVICE_PREFIX): devices.add(device) return devices diff --git a/neutron/plugins/linuxbridge/lb_neutron_plugin.py b/neutron/plugins/linuxbridge/lb_neutron_plugin.py index 2319f8da9..a692bbcfb 100644 --- a/neutron/plugins/linuxbridge/lb_neutron_plugin.py +++ b/neutron/plugins/linuxbridge/lb_neutron_plugin.py @@ -53,12 +53,10 @@ from neutron.plugins.linuxbridge.db import l2network_db_v2 as db LOG = logging.getLogger(__name__) -# Device names start with "tap" -TAP_PREFIX_LEN = 3 - class LinuxBridgeRpcCallbacks(n_rpc.RpcCallback): + # Device names start with "tap" # history # 1.1 Support Security Group RPC # 1.2 Support get_devices_details_list @@ -540,7 +538,7 @@ class LinuxBridgePluginV2(db_base_plugin_v2.NeutronDbPluginV2, @classmethod def get_port_from_device(cls, device): - port = db.get_port_from_device(device[TAP_PREFIX_LEN:]) + port = db.get_port_from_device(device[len(q_const.TAP_DEVICE_PREFIX):]) if port: port['device'] = device return port diff --git a/neutron/plugins/ml2/plugin.py b/neutron/plugins/ml2/plugin.py index 0de4e26d2..46913beaf 100644 --- a/neutron/plugins/ml2/plugin.py +++ b/neutron/plugins/ml2/plugin.py @@ -72,9 +72,6 @@ MAX_BIND_TRIES = 10 # providernet.py? TYPE_MULTI_SEGMENT = 'multi-segment' -TAP_DEVICE_PREFIX = 'tap' -TAP_DEVICE_PREFIX_LENGTH = 3 - class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2, dvr_mac_db.DVRDbMixin, @@ -1144,8 +1141,8 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2, # REVISIT(rkukura): Consider calling into MechanismDrivers to # process device names, or having MechanismDrivers supply list # of device prefixes to strip. - if device.startswith(TAP_DEVICE_PREFIX): - return device[TAP_DEVICE_PREFIX_LENGTH:] + if device.startswith(const.TAP_DEVICE_PREFIX): + return device[len(const.TAP_DEVICE_PREFIX):] else: # REVISIT(irenab): Consider calling into bound MD to # handle the get_device_details RPC, then remove the 'else' clause diff --git a/neutron/plugins/mlnx/mlnx_plugin.py b/neutron/plugins/mlnx/mlnx_plugin.py index 0a8ed5b76..155b85d97 100644 --- a/neutron/plugins/mlnx/mlnx_plugin.py +++ b/neutron/plugins/mlnx/mlnx_plugin.py @@ -52,9 +52,6 @@ from neutron.plugins.mlnx import rpc_callbacks LOG = logging.getLogger(__name__) -#to be compatible with Linux Bridge Agent on Network Node -TAP_PREFIX_LEN = 3 - class MellanoxEswitchPlugin(db_base_plugin_v2.NeutronDbPluginV2, external_net_db.External_net_db_mixin, @@ -529,7 +526,8 @@ class MellanoxEswitchPlugin(db_base_plugin_v2.NeutronDbPluginV2, services get device either by linux bridge plugin device name convention or by mac address """ - port = db.get_port_from_device(device[TAP_PREFIX_LEN:]) + port = db.get_port_from_device( + device[len(q_const.TAP_DEVICE_PREFIX):]) if port: port['device'] = device else: diff --git a/neutron/plugins/ofagent/agent/ports.py b/neutron/plugins/ofagent/agent/ports.py index 4389b7957..218dc5ece 100644 --- a/neutron/plugins/ofagent/agent/ports.py +++ b/neutron/plugins/ofagent/agent/ports.py @@ -14,6 +14,8 @@ # License for the specific language governing permissions and limitations # under the License. +from neutron.common import constants as n_const + class OFPort(object): def __init__(self, port_name, ofport): @@ -28,7 +30,7 @@ class OFPort(object): PORT_NAME_LEN = 14 PORT_NAME_PREFIXES = [ - "tap", # common cases, including ovs_use_veth=True + n_const.TAP_DEVICE_PREFIX, # common cases, including ovs_use_veth=True "qvo", # nova hybrid interface driver "qr-", # l3-agent INTERNAL_DEV_PREFIX (ovs_use_veth=False) "qg-", # l3-agent EXTERNAL_DEV_PREFIX (ovs_use_veth=False) @@ -61,7 +63,7 @@ def get_normalized_port_name(interface_id): use "tap" prefix throughout the agent and plugin for simplicity. Some care should be taken when talking to the switch. """ - return ("tap" + interface_id)[0:PORT_NAME_LEN] + return (n_const.TAP_DEVICE_PREFIX + interface_id)[0:PORT_NAME_LEN] def _normalize_port_name(name): @@ -71,7 +73,7 @@ def _normalize_port_name(name): """ for pref in PORT_NAME_PREFIXES: if name.startswith(pref): - return "tap" + name[len(pref):] + return n_const.TAP_DEVICE_PREFIX + name[len(pref):] return name diff --git a/neutron/tests/unit/linuxbridge/test_lb_neutron_agent.py b/neutron/tests/unit/linuxbridge/test_lb_neutron_agent.py index adc3822db..1a2bbc4d2 100644 --- a/neutron/tests/unit/linuxbridge/test_lb_neutron_agent.py +++ b/neutron/tests/unit/linuxbridge/test_lb_neutron_agent.py @@ -377,10 +377,10 @@ class TestLinuxBridgeManager(base.BaseTestCase): def test_get_tap_device_name(self): if_id = "123456789101112" self.assertEqual(self.lbm.get_tap_device_name(if_id), - "tap" + if_id[0:11]) + constants.TAP_DEVICE_PREFIX + if_id[0:11]) if_id = "" self.assertEqual(self.lbm.get_tap_device_name(if_id), - "tap") + constants.TAP_DEVICE_PREFIX) def test_get_vxlan_device_name(self): vn_id = constants.MAX_VXLAN_VNI diff --git a/neutron/tests/unit/ofagent/test_ofa_ports.py b/neutron/tests/unit/ofagent/test_ofa_ports.py index 6e36da749..5216e1db0 100644 --- a/neutron/tests/unit/ofagent/test_ofa_ports.py +++ b/neutron/tests/unit/ofagent/test_ofa_ports.py @@ -18,6 +18,7 @@ import mock +from neutron.common import constants as n_const from neutron.plugins.ofagent.agent import ports from neutron.tests import base @@ -35,7 +36,7 @@ class TestOFAgentPorts(base.BaseTestCase): self.assertFalse(p2.is_neutron_port()) def test_neutron_port(self): - for pref in ['qvo', 'qr-', 'qg-', 'tap']: + for pref in ['qvo', 'qr-', 'qg-', n_const.TAP_DEVICE_PREFIX]: name = pref + '03b9a237-0b' p1 = ports.Port(port_name=name, ofport=999) ryu_ofp_port = mock.Mock(port_no=999)