Merge "Merge multiple constants defining linux interface maximum length"

This commit is contained in:
Jenkins 2014-06-25 03:48:13 +00:00 committed by Gerrit Code Review
commit 1974244531
7 changed files with 12 additions and 13 deletions

View File

@ -27,7 +27,6 @@ OPTS = [
] ]
VETH_MAX_NAME_LENGTH = 15
LOOPBACK_DEVNAME = 'lo' LOOPBACK_DEVNAME = 'lo'
# NOTE(ethuleau): depend of the version of iproute2, the vlan # NOTE(ethuleau): depend of the version of iproute2, the vlan
# interface details vary. # interface details vary.

View File

@ -25,6 +25,7 @@ import tempfile
from eventlet.green import subprocess from eventlet.green import subprocess
from eventlet import greenthread from eventlet import greenthread
from neutron.common import constants
from neutron.common import utils from neutron.common import utils
from neutron.openstack.common import excutils from neutron.openstack.common import excutils
from neutron.openstack.common import log as logging from neutron.openstack.common import log as logging
@ -85,12 +86,11 @@ def execute(cmd, root_helper=None, process_input=None, addl_env=None,
def get_interface_mac(interface): def get_interface_mac(interface):
DEVICE_NAME_LEN = 15
MAC_START = 18 MAC_START = 18
MAC_END = 24 MAC_END = 24
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
info = fcntl.ioctl(s.fileno(), 0x8927, 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) return ''.join(['%02x:' % ord(char)
for char in info[MAC_START:MAC_END]])[:-1] for char in info[MAC_START:MAC_END]])[:-1]

View File

@ -119,3 +119,6 @@ IPV6_SLAAC = 'slaac'
IPV6_MODES = [DHCPV6_STATEFUL, DHCPV6_STATELESS, IPV6_SLAAC] IPV6_MODES = [DHCPV6_STATEFUL, DHCPV6_STATELESS, IPV6_SLAAC]
IPV6_LLA_PREFIX = 'fe80::/64' IPV6_LLA_PREFIX = 'fe80::/64'
# Linux interface max length
DEVICE_NAME_MAX_LEN = 15

View File

@ -78,6 +78,3 @@ TYPE_LOCAL = 'local'
TYPE_VXLAN = 'vxlan' TYPE_VXLAN = 'vxlan'
TYPE_VLAN = 'vlan' TYPE_VLAN = 'vlan'
TYPE_NONE = 'none' TYPE_NONE = 'none'
# The maximum length of an interface name (in Linux)
MAX_DEV_NAME_LEN = 16

View File

@ -857,20 +857,20 @@ class OVSNeutronAgent(n_rpc.RpcCallback,
exceed the maximum length allowed for a linux device. Longer names exceed the maximum length allowed for a linux device. Longer names
are hashed to help ensure uniqueness. 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 return prefix + name
# We can't just truncate because bridges may be distinguished # We can't just truncate because bridges may be distinguished
# by an ident at the end. A hash over the name should be unique. # by an ident at the end. A hash over the name should be unique.
# Leave part of the bridge name on for easier identification # Leave part of the bridge name on for easier identification
hashlen = 6 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' % new_name = ('%(prefix)s%(truncated)s%(hash)s' %
{'prefix': prefix, 'truncated': name[0:namelen], {'prefix': prefix, 'truncated': name[0:namelen],
'hash': hashlib.sha1(name).hexdigest()[0:hashlen]}) 'hash': hashlib.sha1(name).hexdigest()[0:hashlen]})
LOG.warning(_("Creating an interface named %(name)s exceeds the " LOG.warning(_("Creating an interface named %(name)s exceeds the "
"%(limit)d character limitation. It was shortened to " "%(limit)d character limitation. It was shortened to "
"%(new_name)s to fit."), "%(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}) 'new_name': new_name})
return new_name return new_name

View File

@ -17,7 +17,7 @@ import random
from neutron.agent.linux import ovs_lib from neutron.agent.linux import ovs_lib
from neutron.agent.linux import utils 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 from neutron.tests import base
@ -56,7 +56,7 @@ class BaseLinuxTestCase(base.BaseTestCase):
:param *args *kwargs: These will be passed to the create function. :param *args *kwargs: These will be passed to the create function.
""" """
while True: 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: try:
return creation_func(name, *args, **kwargs) return creation_func(name, *args, **kwargs)
except RuntimeError: except RuntimeError:

View File

@ -488,9 +488,9 @@ class TestOvsNeutronAgent(base.BaseTestCase):
bridge1 = "A_REALLY_LONG_BRIDGE_NAME1" bridge1 = "A_REALLY_LONG_BRIDGE_NAME1"
bridge2 = "A_REALLY_LONG_BRIDGE_NAME2" bridge2 = "A_REALLY_LONG_BRIDGE_NAME2"
self.assertEqual(len(self.agent.get_veth_name('int-', bridge1)), 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)), 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.assertNotEqual(self.agent.get_veth_name('int-', bridge1),
self.agent.get_veth_name('int-', bridge2)) self.agent.get_veth_name('int-', bridge2))