From c9110b536f7cc9cf42f2f82ece08d02b643ed980 Mon Sep 17 00:00:00 2001 From: Taku Fukushima Date: Mon, 7 Dec 2015 18:09:13 +0900 Subject: [PATCH] Replace hardcoded port name generation with function This patch replaces the hardcoded logic for generating the port name with utils.get_neutron_port_name. Change-Id: If8275c2c79c3a98cb6adcf436ca779881ac9d1e5 Signed-off-by: Taku Fukushima Closes-Bug: #1523405 --- kuryr/controllers.py | 4 ++-- kuryr/tests/base.py | 3 ++- kuryr/tests/test_kuryr.py | 6 +++--- kuryr/tests/test_kuryr_endpoint.py | 5 +++-- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/kuryr/controllers.py b/kuryr/controllers.py index cb0f7433..c729c873 100644 --- a/kuryr/controllers.py +++ b/kuryr/controllers.py @@ -245,7 +245,7 @@ def _create_subnets_and_or_port(interface, neutron_network_id, endpoint_id): try: port = { - 'name': '-'.join([endpoint_id, 'port']), + 'name': utils.get_neutron_port_name(endpoint_id), 'admin_state_up': True, 'network_id': neutron_network_id, 'device_owner': constants.DEVICE_OWNER, @@ -724,7 +724,7 @@ def network_driver_leave(): .format(neutron_network_name) }) else: - neutron_port_name = '-'.join([endpoint_id, 'port']) + neutron_port_name = utils.get_neutron_port_name(endpoint_id) filtered_ports = _get_ports_by_attrs(name=neutron_port_name) if not filtered_ports: raise exceptions.NoResourceException( diff --git a/kuryr/tests/base.py b/kuryr/tests/base.py index 517480c3..52bd4d06 100644 --- a/kuryr/tests/base.py +++ b/kuryr/tests/base.py @@ -14,6 +14,7 @@ from neutronclient.tests.unit import test_cli20 from kuryr import app from kuryr import binding +from kuryr import utils class TestCase(test_cli20.CLITestV20Base): @@ -165,7 +166,7 @@ class TestKuryrBase(TestCase): fake_port = { 'port': { "status": "DOWN", - "name": '-'.join([docker_endpoint_id, '0', 'port']), + "name": utils.get_neutron_port_name(docker_endpoint_id), "allowed_address_pairs": [], "admin_state_up": True, "network_id": neutron_network_id, diff --git a/kuryr/tests/test_kuryr.py b/kuryr/tests/test_kuryr.py index 46baa3e7..d22eed6f 100644 --- a/kuryr/tests/test_kuryr.py +++ b/kuryr/tests/test_kuryr.py @@ -177,7 +177,7 @@ class TestKuryr(base.TestKuryrBase): fake_neutron_port_id = str(uuid.uuid4()) fake_port_request = { 'port': { - 'name': '-'.join([docker_endpoint_id, 'port']), + 'name': utils.get_neutron_port_name(docker_endpoint_id), 'admin_state_up': True, 'mac_address': fake_mac_address, 'network_id': fake_neutron_network_id, @@ -286,7 +286,7 @@ class TestKuryr(base.TestKuryrBase): fake_neutron_port_id = str(uuid.uuid4()) fake_port_request = { 'port': { - 'name': '-'.join([docker_endpoint_id, 'port']), + 'name': utils.get_neutron_port_name(docker_endpoint_id), 'admin_state_up': True, 'mac_address': fake_mac_address, 'network_id': fake_neutron_network_id, @@ -396,7 +396,7 @@ class TestKuryr(base.TestKuryrBase): self.mox.StubOutWithMock(app.neutron, 'create_port') fake_port_request = { 'port': { - 'name': '-'.join([docker_endpoint_id, 'port']), + 'name': utils.get_neutron_port_name(docker_endpoint_id), 'admin_state_up': True, 'device_owner': constants.DEVICE_OWNER, 'device_id': docker_endpoint_id, diff --git a/kuryr/tests/test_kuryr_endpoint.py b/kuryr/tests/test_kuryr_endpoint.py index b0b2d3ef..d6b6870e 100644 --- a/kuryr/tests/test_kuryr_endpoint.py +++ b/kuryr/tests/test_kuryr_endpoint.py @@ -21,6 +21,7 @@ from oslo_serialization import jsonutils from kuryr import app from kuryr.common import constants from kuryr.tests import base +from kuryr import utils class TestKuryrEndpointFailures(base.TestKuryrFailures): @@ -85,7 +86,7 @@ class TestKuryrEndpointFailures(base.TestKuryrFailures): self.mox.StubOutWithMock(app.neutron, 'create_port') fake_port_request = { 'port': { - 'name': '-'.join([docker_endpoint_id, 'port']), + 'name': utils.get_neutron_port_name(docker_endpoint_id), 'admin_state_up': True, 'device_owner': constants.DEVICE_OWNER, 'device_id': docker_endpoint_id, @@ -105,7 +106,7 @@ class TestKuryrEndpointFailures(base.TestKuryrFailures): fake_port = { "port": { "status": "DOWN", - "name": '-'.join([docker_endpoint_id, 'port']), + "name": utils.get_neutron_port_name(docker_endpoint_id), "allowed_address_pairs": [], "admin_state_up": True, "network_id": neutron_network_id,