]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Added TAP_DEVICE_PREFIX info to common/constants
authorSam Betts <sam@code-smash.net>
Tue, 26 Aug 2014 17:35:36 +0000 (18:35 +0100)
committerSam Betts <sam@code-smash.net>
Wed, 10 Sep 2014 08:59:28 +0000 (09:59 +0100)
Change-Id: Ia84629732490585164237ca4f7d1db90bde9fbf2
Closes-Bug: 1361573

12 files changed:
neutron/agent/linux/interface.py
neutron/agent/linux/iptables_firewall.py
neutron/common/constants.py
neutron/plugins/bigswitch/plugin.py
neutron/plugins/brocade/NeutronPlugin.py
neutron/plugins/linuxbridge/agent/linuxbridge_neutron_agent.py
neutron/plugins/linuxbridge/lb_neutron_plugin.py
neutron/plugins/ml2/plugin.py
neutron/plugins/mlnx/mlnx_plugin.py
neutron/plugins/ofagent/agent/ports.py
neutron/tests/unit/linuxbridge/test_lb_neutron_agent.py
neutron/tests/unit/ofagent/test_ofa_ports.py

index c6677c1141b17078668919c05cb95c7217558967..3a99c1a2e47a09c853b0b5c8c140b5a6865cdc6b 100644 (file)
@@ -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)
index ec37306a5593f97e17f0865e02337ceb3d4d4c7f..c7cafc0d063b34fc4e518d8c4ebcf316a2ead87a 100644 (file)
@@ -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(
index f1c15c535b618c26a18b5b31f50df51bc4da792c..1d85e0f86fc8a0071bb623285f9ee7c3ac36a120 100644 (file)
@@ -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'
index 728a5dd0cdc648c0ccf27e3286a3336d4becf3dd..9ecc0140e9caa0dcb1add61b76d4104abf4c22c7 100644 (file)
@@ -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
index 7b46e04bceee211af13036c3ec226114f31a4d37..5d9e431e4607bca254302416606f79b418e2684a 100644 (file)
@@ -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
index 7d608c3e6ee28286c5019a65b06d3602470a9959..8663b4c76f0b29d2b333d0a0557262fd1b784812 100755 (executable)
@@ -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
 
index 2319f8da9607d4333e37464af6251dda59284435..a692bbcfb960539d2d45b3b8f2a9822d41144205 100644 (file)
@@ -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
index 0de4e26d2a9f64ed1ecc54e587f5f3eddc137fc5..46913beaf3b84f3fa07e5edd3f53684e7b4210a2 100644 (file)
@@ -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
index 0a8ed5b7612f358633213beb07ab47218bd9d9dc..155b85d972d47b120ad02a188f728458868ed8ce 100644 (file)
@@ -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:
index 4389b795742ce4092fa55a8e1be92e8c6adf1239..218dc5eceed602ed1ac52e54b9a35d570b585019 100644 (file)
@@ -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
 
 
index adc3822db398198f042c511b8bbfaaba589a34e4..1a2bbc4d2e408e42e94db8b32f2a249151225b3e 100644 (file)
@@ -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
index 6e36da749233e477b076ee7237620e2ec282e228..5216e1db0f1bc02f2f0c0935d56ba0dcd9121091 100644 (file)
@@ -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)