]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Merge multiple constants defining linux interface maximum length
authorCedric Brandily <zzelle@gmail.com>
Fri, 20 Jun 2014 14:41:22 +0000 (16:41 +0200)
committerCedric Brandily <zzelle@gmail.com>
Mon, 23 Jun 2014 17:45:30 +0000 (19:45 +0200)
DEVICE_NAME_MAX_LEN constant in neutron.common.constants replaces
and correct multiple constants defining linux interface maximum
length.

Closes-Bug: #1332571
Change-Id: I63f760a21e17dcd57b3685b1e71c913d2722e097

neutron/agent/linux/ip_lib.py
neutron/agent/linux/utils.py
neutron/common/constants.py
neutron/plugins/common/constants.py
neutron/plugins/openvswitch/agent/ovs_neutron_agent.py
neutron/tests/functional/agent/linux/base.py
neutron/tests/unit/openvswitch/test_ovs_neutron_agent.py

index c88c54c20605e630d0f73f0b27b1c07fbf186cc3..11b4ad4eac931029ee11f6c395ed10484dbffa2b 100644 (file)
@@ -28,7 +28,6 @@ OPTS = [
 ]
 
 
-VETH_MAX_NAME_LENGTH = 15
 LOOPBACK_DEVNAME = 'lo'
 # NOTE(ethuleau): depend of the version of iproute2, the vlan
 # interface details vary.
index d4ef237e56a78fdc3a73ea4865c5bca1efaa1e6e..265a2553dc3bde0b114e511bfdb915499923c4a5 100644 (file)
@@ -27,6 +27,7 @@ import tempfile
 from eventlet.green import subprocess
 from eventlet import greenthread
 
+from neutron.common import constants
 from neutron.common import utils
 from neutron.openstack.common import excutils
 from neutron.openstack.common import log as logging
@@ -87,12 +88,11 @@ def execute(cmd, root_helper=None, process_input=None, addl_env=None,
 
 
 def get_interface_mac(interface):
-    DEVICE_NAME_LEN = 15
     MAC_START = 18
     MAC_END = 24
     s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
     info = fcntl.ioctl(s.fileno(), 0x8927,
-                       struct.pack('256s', interface[:DEVICE_NAME_LEN]))
+        struct.pack('256s', interface[:constants.DEVICE_NAME_MAX_LEN]))
     return ''.join(['%02x:' % ord(char)
                     for char in info[MAC_START:MAC_END]])[:-1]
 
index cf3fb6025bce45fd1d11b206c2b8d75ef57764dd..7500cede13454bda2bae75110c7a9ab682bac08c 100644 (file)
@@ -119,3 +119,6 @@ IPV6_SLAAC = 'slaac'
 IPV6_MODES = [DHCPV6_STATEFUL, DHCPV6_STATELESS, IPV6_SLAAC]
 
 IPV6_LLA_PREFIX = 'fe80::/64'
+
+# Linux interface max length
+DEVICE_NAME_MAX_LEN = 15
index 366945ad082e021f3e017c5241ad7d9c00fefcca..abf18507f8259afec80651bb59ecf9d9215f4a53 100644 (file)
@@ -80,6 +80,3 @@ TYPE_LOCAL = 'local'
 TYPE_VXLAN = 'vxlan'
 TYPE_VLAN = 'vlan'
 TYPE_NONE = 'none'
-
-# The maximum length of an interface name (in Linux)
-MAX_DEV_NAME_LEN = 16
index a66d773c82c745c9d4d049f8cb953989c437c16c..46bdb1dfaae45dbfdb57d07f5d5cc8aed81b9d8b 100644 (file)
@@ -866,20 +866,20 @@ class OVSNeutronAgent(rpc_compat.RpcCallback,
            exceed the maximum length allowed for a linux device. Longer names
            are hashed to help ensure uniqueness.
         """
-        if len(prefix + name) <= ip_lib.VETH_MAX_NAME_LENGTH:
+        if len(prefix + name) <= q_const.DEVICE_NAME_MAX_LEN:
             return prefix + name
         # We can't just truncate because bridges may be distinguished
         # by an ident at the end. A hash over the name should be unique.
         # Leave part of the bridge name on for easier identification
         hashlen = 6
-        namelen = ip_lib.VETH_MAX_NAME_LENGTH - len(prefix) - hashlen
+        namelen = q_const.DEVICE_NAME_MAX_LEN - len(prefix) - hashlen
         new_name = ('%(prefix)s%(truncated)s%(hash)s' %
                     {'prefix': prefix, 'truncated': name[0:namelen],
                      'hash': hashlib.sha1(name).hexdigest()[0:hashlen]})
         LOG.warning(_("Creating an interface named %(name)s exceeds the "
                       "%(limit)d character limitation. It was shortened to "
                       "%(new_name)s to fit."),
-                    {'name': name, 'limit': ip_lib.VETH_MAX_NAME_LENGTH,
+                    {'name': name, 'limit': q_const.DEVICE_NAME_MAX_LEN,
                      'new_name': new_name})
         return new_name
 
index c5ea717f7f7030d57819e80b11ce15a7fb2f4416..e8c069750ac78b0c9c415cfe6f541734f0e85e85 100644 (file)
@@ -17,7 +17,7 @@ import random
 
 from neutron.agent.linux import ovs_lib
 from neutron.agent.linux import utils
-from neutron.plugins.common import constants as q_const
+from neutron.common import constants as n_const
 from neutron.tests import base
 
 
@@ -56,7 +56,7 @@ class BaseLinuxTestCase(base.BaseTestCase):
         :param *args *kwargs: These will be passed to the create function.
         """
         while True:
-            name = self.get_rand_name(q_const.MAX_DEV_NAME_LEN, name_prefix)
+            name = self.get_rand_name(n_const.DEV_NAME_MAX_LEN, name_prefix)
             try:
                 return creation_func(name, *args, **kwargs)
             except RuntimeError:
index b1d2371b3b1254ff79d3df0eaf7a8788b2a6daa4..a3752fe0968cf1dc89e712c9fe60749156f441ee 100644 (file)
@@ -490,9 +490,9 @@ class TestOvsNeutronAgent(base.BaseTestCase):
             bridge1 = "A_REALLY_LONG_BRIDGE_NAME1"
             bridge2 = "A_REALLY_LONG_BRIDGE_NAME2"
             self.assertEqual(len(self.agent.get_veth_name('int-', bridge1)),
-                             ip_lib.VETH_MAX_NAME_LENGTH)
+                             n_const.DEVICE_NAME_MAX_LEN)
             self.assertEqual(len(self.agent.get_veth_name('int-', bridge2)),
-                             ip_lib.VETH_MAX_NAME_LENGTH)
+                             n_const.DEVICE_NAME_MAX_LEN)
             self.assertNotEqual(self.agent.get_veth_name('int-', bridge1),
                                 self.agent.get_veth_name('int-', bridge2))