Makes tap device name consistent
Keeping device names used by Kuryr consistent with those used by Nova makes the users' and operators' experience better. It also makes debugging easier for those used to names employed by Nova. This patch set changes the tap device name to use part of the Neutron port id. Closes-Bug: #1582348 Change-Id: I502f7bba09044106885de28cef8a432d5b5b1321
This commit is contained in:
@@ -22,8 +22,6 @@ from kuryr.common import exceptions
|
||||
from kuryr import utils
|
||||
|
||||
|
||||
VETH_PREFIX = 'tap'
|
||||
CONTAINER_VETH_PREFIX = 't_c'
|
||||
BINDING_SUBCOMMAND = 'bind'
|
||||
DOWN = 'DOWN'
|
||||
FALLBACK_VIF_TYPE = 'unbound'
|
||||
@@ -115,8 +113,8 @@ def port_bind(endpoint_id, neutron_port, neutron_subnets):
|
||||
"""
|
||||
ip = get_ipdb()
|
||||
|
||||
ifname = VETH_PREFIX + endpoint_id[:8]
|
||||
peer_name = CONTAINER_VETH_PREFIX + ifname
|
||||
port_id = neutron_port['id']
|
||||
ifname, peer_name = utils.get_veth_pair_names(port_id)
|
||||
subnets_dict = {subnet['id']: subnet for subnet in neutron_subnets}
|
||||
|
||||
try:
|
||||
@@ -176,8 +174,10 @@ def port_unbind(endpoint_id, neutron_port):
|
||||
vif_type = neutron_port.get(VIF_TYPE_KEY, FALLBACK_VIF_TYPE)
|
||||
vif_details = utils.string_mappings(neutron_port.get(VIF_DETAILS_KEY))
|
||||
unbinding_exec_path = os.path.join(config.CONF.bindir, vif_type)
|
||||
ifname = VETH_PREFIX + endpoint_id[:8]
|
||||
|
||||
port_id = neutron_port['id']
|
||||
ifname, _ = utils.get_veth_pair_names(port_id)
|
||||
|
||||
mac_address = neutron_port['mac_address']
|
||||
stdout, stderr = processutils.execute(
|
||||
unbinding_exec_path, UNBINDING_SUBCOMMAND, port_id, ifname,
|
||||
|
@@ -19,6 +19,9 @@ SCHEMA = {
|
||||
}
|
||||
|
||||
DEVICE_OWNER = 'kuryr:container'
|
||||
NIC_NAME_LEN = 14
|
||||
VETH_PREFIX = 'tap'
|
||||
CONTAINER_VETH_PREFIX = 't_c'
|
||||
|
||||
NEUTRON_ID_LH_OPTION = 'kuryr.net.uuid.lh'
|
||||
NEUTRON_ID_UH_OPTION = 'kuryr.net.uuid.uh'
|
||||
|
@@ -20,6 +20,7 @@ from werkzeug import exceptions as w_exceptions
|
||||
|
||||
from kuryr import app
|
||||
from kuryr import binding
|
||||
from kuryr.common import constants as const
|
||||
from kuryr.common import exceptions
|
||||
from kuryr.tests.unit import base
|
||||
from kuryr import utils
|
||||
@@ -47,7 +48,7 @@ class TestKuryrJoinFailures(base.TestKuryrFailures):
|
||||
fake_ifname = 'fake-veth'
|
||||
fake_binding_response = (
|
||||
fake_ifname,
|
||||
binding.CONTAINER_VETH_PREFIX + fake_ifname,
|
||||
const.CONTAINER_VETH_PREFIX + fake_ifname,
|
||||
('fake stdout', '')
|
||||
)
|
||||
self.mox.StubOutWithMock(binding, 'port_bind')
|
||||
|
@@ -11,10 +11,12 @@
|
||||
# under the License.
|
||||
|
||||
import hashlib
|
||||
import uuid
|
||||
|
||||
import ddt
|
||||
from oslo_config import cfg
|
||||
|
||||
from kuryr.common import constants as const
|
||||
from kuryr.tests.unit import base
|
||||
from kuryr import utils
|
||||
|
||||
@@ -38,6 +40,22 @@ class TestKuryrUtils(base.TestKuryrBase):
|
||||
self.assertIn(utils.PORT_POSTFIX, generated_neutron_port_name)
|
||||
self.assertIn(fake_docker_endpoint_id, generated_neutron_port_name)
|
||||
|
||||
def test_get_veth_pair_names(self):
|
||||
fake_neutron_port_id = str(uuid.uuid4())
|
||||
generated_ifname, generated_peer = utils.get_veth_pair_names(
|
||||
fake_neutron_port_id)
|
||||
|
||||
namelen = const.NIC_NAME_LEN
|
||||
ifname_postlen = namelen - len(const.VETH_PREFIX)
|
||||
peer_postlen = namelen - len(const.CONTAINER_VETH_PREFIX)
|
||||
|
||||
self.assertEqual(namelen, len(generated_ifname))
|
||||
self.assertEqual(namelen, len(generated_peer))
|
||||
self.assertIn(const.VETH_PREFIX, generated_ifname)
|
||||
self.assertIn(const.CONTAINER_VETH_PREFIX, generated_peer)
|
||||
self.assertIn(fake_neutron_port_id[:ifname_postlen], generated_ifname)
|
||||
self.assertIn(fake_neutron_port_id[:peer_postlen], generated_peer)
|
||||
|
||||
def test_get_subnetpool_name(self):
|
||||
fake_subnet_cidr = "10.0.0.0/16"
|
||||
generated_neutron_subnetpool_name = utils.get_neutron_subnetpool_name(
|
||||
|
@@ -109,6 +109,14 @@ def get_neutron_port_name(docker_endpoint_id):
|
||||
return '-'.join([docker_endpoint_id, PORT_POSTFIX])
|
||||
|
||||
|
||||
def get_veth_pair_names(port_id):
|
||||
ifname = const.VETH_PREFIX + port_id
|
||||
ifname = ifname[:const.NIC_NAME_LEN]
|
||||
peer_name = const.CONTAINER_VETH_PREFIX + port_id
|
||||
peer_name = peer_name[:const.NIC_NAME_LEN]
|
||||
return ifname, peer_name
|
||||
|
||||
|
||||
def get_hostname():
|
||||
"""Returns the host name."""
|
||||
return socket.gethostname()
|
||||
|
Reference in New Issue
Block a user