From 151d94521fb91dfe849213c5f743f70721fdf9df Mon Sep 17 00:00:00 2001 From: Edan David Date: Wed, 6 Jul 2016 08:40:04 -0400 Subject: [PATCH] Replace device owners hard coded strings to neutron_lib constants Change-Id: I821f0def82164ab1303188d3f1bdfd85473470cd --- neutron/agent/l2/extensions/fdb_population.py | 7 ++++--- neutron/debug/debug_agent.py | 2 +- neutron/tests/functional/agent/l2/base.py | 2 +- neutron/tests/functional/db/test_ipam.py | 2 +- .../unit/agent/l2/extensions/test_fdb_population.py | 5 +++-- .../tests/unit/db/test_ipam_non_pluggable_backend.py | 4 ++-- neutron/tests/unit/db/test_ipam_pluggable_backend.py | 4 +++- neutron/tests/unit/db/test_l3_db.py | 9 +++++---- neutron/tests/unit/ipam/test_requests.py | 10 ++++++---- neutron/tests/unit/plugins/ml2/test_driver_context.py | 4 ++-- .../tests/unit/scheduler/test_l3_agent_scheduler.py | 4 ++-- 11 files changed, 30 insertions(+), 23 deletions(-) diff --git a/neutron/agent/l2/extensions/fdb_population.py b/neutron/agent/l2/extensions/fdb_population.py index 96ef12184ae..9bd89bd1a3f 100644 --- a/neutron/agent/l2/extensions/fdb_population.py +++ b/neutron/agent/l2/extensions/fdb_population.py @@ -15,6 +15,7 @@ import sys +from neutron_lib import constants from oslo_config import cfg from oslo_log import log as logging @@ -63,9 +64,9 @@ class FdbPopulationAgentExtension(agent_extension.AgentCoreResourceExtension): # the message will be sent to the wire, causing the message # to get lost in case the sender uses direct port and is # located on the same hypervisor as the network node. - PERMITTED_DEVICE_OWNERS = {'compute', - 'network:router_interface', - 'network:dhcp'} + PERMITTED_DEVICE_OWNERS = {constants.DEVICE_OWNER_COMPUTE_PREFIX, + constants.DEVICE_OWNER_ROUTER_INTF, + constants.DEVICE_OWNER_DHCP} class FdbTableTracker(object): """FDB table tracker is a helper class diff --git a/neutron/debug/debug_agent.py b/neutron/debug/debug_agent.py index 50bb89f03e4..e1a564aa935 100644 --- a/neutron/debug/debug_agent.py +++ b/neutron/debug/debug_agent.py @@ -27,7 +27,7 @@ from neutron.extensions import portbindings LOG = logging.getLogger(__name__) -DEVICE_OWNER_NETWORK_PROBE = 'network:probe' +DEVICE_OWNER_NETWORK_PROBE = constants.DEVICE_OWNER_NETWORK_PREFIX + 'probe' DEVICE_OWNER_COMPUTE_PROBE = constants.DEVICE_OWNER_COMPUTE_PREFIX + 'probe' diff --git a/neutron/tests/functional/agent/l2/base.py b/neutron/tests/functional/agent/l2/base.py index 8442e3c42b0..c931de35fd2 100644 --- a/neutron/tests/functional/agent/l2/base.py +++ b/neutron/tests/functional/agent/l2/base.py @@ -212,7 +212,7 @@ class OVSAgentTestFramework(base.BaseOVSLinuxTestCase): 'physical_network': network.get('physical_network', 'physnet'), 'segmentation_id': network.get('segmentation_id', 1), 'fixed_ips': port['fixed_ips'], - 'device_owner': 'compute', + 'device_owner': n_const.DEVICE_OWNER_COMPUTE_PREFIX, 'port_security_enabled': True, 'security_groups': ['default'], 'admin_state_up': True} diff --git a/neutron/tests/functional/db/test_ipam.py b/neutron/tests/functional/db/test_ipam.py index 2520fa48a57..653acf27bd5 100644 --- a/neutron/tests/functional/db/test_ipam.py +++ b/neutron/tests/functional/db/test_ipam.py @@ -129,7 +129,7 @@ class IpamTestCase(testlib_api.SqlTestCase): 'admin_state_up': True, 'status': constants.PORT_STATUS_ACTIVE, 'device_id': 'test_dev_id', - 'device_owner': 'compute', + 'device_owner': constants.DEVICE_OWNER_COMPUTE_PREFIX, 'fixed_ips': port_fixed_ips} self.plugin.create_port(self.cxt, {'port': port}) diff --git a/neutron/tests/unit/agent/l2/extensions/test_fdb_population.py b/neutron/tests/unit/agent/l2/extensions/test_fdb_population.py index dd70ba864d4..b96d92d6cd0 100644 --- a/neutron/tests/unit/agent/l2/extensions/test_fdb_population.py +++ b/neutron/tests/unit/agent/l2/extensions/test_fdb_population.py @@ -16,6 +16,7 @@ import copy import mock +from neutron_lib import constants from oslo_config import cfg import six @@ -31,7 +32,7 @@ from neutron.tests import base class FdbPopulationExtensionTestCase(base.BaseTestCase): - UPDATE_MSG = {u'device_owner': u'network:router_interface', + UPDATE_MSG = {u'device_owner': constants.DEVICE_OWNER_ROUTER_INTF, u'physical_network': u'physnet1', u'mac_address': u'fa:16:3e:ba:bc:21', u'port_id': u'17ceda02-43e1-48d8-beb6-35885b20cae6'} @@ -128,7 +129,7 @@ class FdbPopulationExtensionTestCase(base.BaseTestCase): fdb_extension = self._get_fdb_extension(mock_execute, '') mock_execute.reset_mock() details = copy.deepcopy(self.UPDATE_MSG) - details['device_owner'] = 'neutron:LOADBALANCER' + details['device_owner'] = constants.DEVICE_OWNER_LOADBALANCER fdb_extension.handle_port(context=None, details=details) self.assertFalse(mock_execute.called) updated_macs_for_device = ( diff --git a/neutron/tests/unit/db/test_ipam_non_pluggable_backend.py b/neutron/tests/unit/db/test_ipam_non_pluggable_backend.py index 9defbdd1ab5..5f595e4f832 100644 --- a/neutron/tests/unit/db/test_ipam_non_pluggable_backend.py +++ b/neutron/tests/unit/db/test_ipam_non_pluggable_backend.py @@ -67,7 +67,7 @@ class TestIpamNonPluggableBackend(base.BaseTestCase): 'network_id': 'fbb9b578-95eb-4b79-a116-78e5c4927176', 'fixed_ips': n_const.ATTR_NOT_SPECIFIED, 'mac_address': '12:34:56:78:44:ab', - 'device_owner': 'compute'}} + 'device_owner': n_const.DEVICE_OWNER_COMPUTE_PREFIX}} expected = [] for subnet in subnets: addr = str(ipv6_utils.get_ipv6_addr_by_EUI64( @@ -100,7 +100,7 @@ class TestIpamNonPluggableBackend(base.BaseTestCase): 'network_id': 'fbb9b578-95eb-4b79-a116-78e5c4927176', 'fixed_ips': n_const.ATTR_NOT_SPECIFIED, 'mac_address': '12:34:56:78:44:ab', - 'device_owner': 'compute'}} + 'device_owner': n_const.DEVICE_OWNER_COMPUTE_PREFIX}} expected = [] for subnet in subnets: addr = str(ipv6_utils.get_ipv6_addr_by_EUI64( diff --git a/neutron/tests/unit/db/test_ipam_pluggable_backend.py b/neutron/tests/unit/db/test_ipam_pluggable_backend.py index d4079c9a06b..8254bdb7289 100644 --- a/neutron/tests/unit/db/test_ipam_pluggable_backend.py +++ b/neutron/tests/unit/db/test_ipam_pluggable_backend.py @@ -75,7 +75,9 @@ class TestDbBasePluginIpam(test_db_base.NeutronDbPluginV2TestCase): 'driver': mock.Mock(), 'subnet': mock.Mock(), 'subnets': mock.Mock(), - 'port': {'device_owner': 'compute:None'}, + 'port': { + 'device_owner': n_const.DEVICE_OWNER_COMPUTE_PREFIX + 'None' + }, 'subnet_request': ipam_req.SpecificSubnetRequest( self.tenant_id, self.subnet_id, diff --git a/neutron/tests/unit/db/test_l3_db.py b/neutron/tests/unit/db/test_l3_db.py index 9867d7bb333..585e49b4368 100644 --- a/neutron/tests/unit/db/test_l3_db.py +++ b/neutron/tests/unit/db/test_l3_db.py @@ -14,6 +14,7 @@ # limitations under the License. import mock +from neutron_lib import constants as n_const from neutron_lib import exceptions as n_exc import testtools @@ -161,7 +162,7 @@ class TestL3_NAT_dbonly_mixin(base.BaseTestCase): def test_prevent_l3_port_no_fixed_ips(self, gp): # without fixed IPs is allowed gp.return_value.get_port.return_value = { - 'device_owner': 'network:router_interface', 'fixed_ips': [], + 'device_owner': n_const.DEVICE_OWNER_ROUTER_INTF, 'fixed_ips': [], 'id': 'f' } self.db.prevent_l3_port_deletion(None, None) @@ -170,7 +171,7 @@ class TestL3_NAT_dbonly_mixin(base.BaseTestCase): def test_prevent_l3_port_no_router(self, gp): # without router is allowed gp.return_value.get_port.return_value = { - 'device_owner': 'network:router_interface', + 'device_owner': n_const.DEVICE_OWNER_ROUTER_INTF, 'device_id': '44', 'id': 'f', 'fixed_ips': [{'ip_address': '1.1.1.1', 'subnet_id': '4'}]} self.db.get_router = mock.Mock() @@ -180,7 +181,7 @@ class TestL3_NAT_dbonly_mixin(base.BaseTestCase): @mock.patch.object(manager.NeutronManager, 'get_plugin') def test_prevent_l3_port_existing_router(self, gp): gp.return_value.get_port.return_value = { - 'device_owner': 'network:router_interface', + 'device_owner': n_const.DEVICE_OWNER_ROUTER_INTF, 'device_id': 'some_router', 'id': 'f', 'fixed_ips': [{'ip_address': '1.1.1.1', 'subnet_id': '4'}]} self.db.get_router = mock.Mock() @@ -190,7 +191,7 @@ class TestL3_NAT_dbonly_mixin(base.BaseTestCase): @mock.patch.object(manager.NeutronManager, 'get_plugin') def test_prevent_l3_port_existing_floating_ip(self, gp): gp.return_value.get_port.return_value = { - 'device_owner': 'network:floatingip', + 'device_owner': n_const.DEVICE_OWNER_FLOATINGIP, 'device_id': 'some_flip', 'id': 'f', 'fixed_ips': [{'ip_address': '1.1.1.1', 'subnet_id': '4'}]} self.db.get_floatingip = mock.Mock() diff --git a/neutron/tests/unit/ipam/test_requests.py b/neutron/tests/unit/ipam/test_requests.py index e73531e7bf2..7e635e07728 100644 --- a/neutron/tests/unit/ipam/test_requests.py +++ b/neutron/tests/unit/ipam/test_requests.py @@ -288,7 +288,8 @@ class TestAddressRequestFactory(base.BaseTestCase): def test_specific_address_request_is_loaded(self): for address in ('10.12.0.15', 'fffe::1'): ip = {'ip_address': address} - port = {'device_owner': 'compute:None'} + port = {'device_owner': + constants.DEVICE_OWNER_COMPUTE_PREFIX + 'None'} self.assertIsInstance( ipam_req.AddressRequestFactory.get_request(None, port, ip), ipam_req.SpecificAddressRequest) @@ -296,7 +297,8 @@ class TestAddressRequestFactory(base.BaseTestCase): def test_any_address_request_is_loaded(self): for addr in [None, '']: ip = {'ip_address': addr} - port = {'device_owner': 'compute:None'} + port = {'device_owner': + constants.DEVICE_OWNER_COMPUTE_PREFIX + 'None'} self.assertIsInstance( ipam_req.AddressRequestFactory.get_request(None, port, ip), ipam_req.AnyAddressRequest) @@ -305,14 +307,14 @@ class TestAddressRequestFactory(base.BaseTestCase): ip = {'mac': '6c:62:6d:de:cf:49', 'subnet_cidr': '2001:470:abcd::/64', 'eui64_address': True} - port = {'device_owner': 'compute:None'} + port = {'device_owner': constants.DEVICE_OWNER_COMPUTE_PREFIX + 'None'} self.assertIsInstance( ipam_req.AddressRequestFactory.get_request(None, port, ip), ipam_req.AutomaticAddressRequest) def test_prefernext_address_request_on_dhcp_port(self): ip = {} - port = {'device_owner': 'network:dhcp'} + port = {'device_owner': constants.DEVICE_OWNER_DHCP} self.assertIsInstance( ipam_req.AddressRequestFactory.get_request(None, port, ip), ipam_req.PreferNextAddressRequest) diff --git a/neutron/tests/unit/plugins/ml2/test_driver_context.py b/neutron/tests/unit/plugins/ml2/test_driver_context.py index 737d1abbde4..1ab5a2ad318 100644 --- a/neutron/tests/unit/plugins/ml2/test_driver_context.py +++ b/neutron/tests/unit/plugins/ml2/test_driver_context.py @@ -53,7 +53,7 @@ class TestPortContext(base.BaseTestCase): network = mock.MagicMock() binding = mock.Mock() - port = {'device_owner': 'compute', + port = {'device_owner': constants.DEVICE_OWNER_COMPUTE_PREFIX, portbindings.HOST_ID: 'host'} binding.host = 'foohost' @@ -92,7 +92,7 @@ class TestPortContext(base.BaseTestCase): network = mock.MagicMock() binding = mock.Mock() - port = {'device_owner': 'compute', + port = {'device_owner': constants.DEVICE_OWNER_COMPUTE_PREFIX, 'status': 'status'} binding.status = 'foostatus' diff --git a/neutron/tests/unit/scheduler/test_l3_agent_scheduler.py b/neutron/tests/unit/scheduler/test_l3_agent_scheduler.py index 44cb1555175..b2bf5705c56 100644 --- a/neutron/tests/unit/scheduler/test_l3_agent_scheduler.py +++ b/neutron/tests/unit/scheduler/test_l3_agent_scheduler.py @@ -1025,7 +1025,7 @@ class L3DvrSchedulerTestCase(testlib_api.SqlTestCase): 'context': self.adminContext, 'original_port': None, 'port': { - 'device_owner': 'network:None', + 'device_owner': constants.DEVICE_OWNER_NETWORK_PREFIX + 'None', } } l3plugin = mock.Mock() @@ -1374,7 +1374,7 @@ class L3DvrSchedulerTestCase(testlib_api.SqlTestCase): dvr_port = { 'id': 'dvr_port1', 'device_id': 'r1', - 'device_owner': 'network:router_interface_distributed', + 'device_owner': constants.DEVICE_OWNER_DVR_INTERFACE, 'fixed_ips': [] } r1 = {