From: Ihar Hrachyshka Date: Wed, 30 Sep 2015 10:50:38 +0000 (+0200) Subject: Use DEVICE_OWNER_COMPUTE constant everywhere X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=fb2a5bd4cf67e4e3493937c1f2fb0a9bdcbbe2a3;p=openstack-build%2Fneutron-build.git Use DEVICE_OWNER_COMPUTE constant everywhere Now that we have the constant defined, we should reuse it from other code to avoid potential typos. Change-Id: Iebb270be46b116df3441370dc1a6784571311aa9 --- diff --git a/neutron/common/constants.py b/neutron/common/constants.py index 8d468d3b8..173188621 100644 --- a/neutron/common/constants.py +++ b/neutron/common/constants.py @@ -30,6 +30,8 @@ FLOATINGIP_STATUS_ACTIVE = 'ACTIVE' FLOATINGIP_STATUS_DOWN = 'DOWN' FLOATINGIP_STATUS_ERROR = 'ERROR' +DEVICE_OWNER_COMPUTE_PREFIX = "compute:" + DEVICE_OWNER_ROUTER_HA_INTF = "network:router_ha_interface" DEVICE_OWNER_ROUTER_INTF = "network:router_interface" DEVICE_OWNER_ROUTER_GW = "network:router_gateway" diff --git a/neutron/common/utils.py b/neutron/common/utils.py index 83886d597..b6d1e7492 100644 --- a/neutron/common/utils.py +++ b/neutron/common/utils.py @@ -378,7 +378,7 @@ def is_dvr_serviced(device_owner): dvr_serviced_device_owners = (n_const.DEVICE_OWNER_LOADBALANCER, n_const.DEVICE_OWNER_LOADBALANCERV2, n_const.DEVICE_OWNER_DHCP) - return (device_owner.startswith('compute:') or + return (device_owner.startswith(n_const.DEVICE_OWNER_COMPUTE_PREFIX) or device_owner in dvr_serviced_device_owners) diff --git a/neutron/debug/debug_agent.py b/neutron/debug/debug_agent.py index 89f17bd09..8c4966b49 100644 --- a/neutron/debug/debug_agent.py +++ b/neutron/debug/debug_agent.py @@ -23,6 +23,7 @@ from oslo_log import log as logging from neutron.agent.linux import dhcp from neutron.agent.linux import ip_lib from neutron.agent.linux import utils +from neutron.common import constants from neutron.i18n import _LW @@ -30,7 +31,7 @@ LOG = logging.getLogger(__name__) DEVICE_OWNER_NETWORK_PROBE = 'network:probe' -DEVICE_OWNER_COMPUTE_PROBE = 'compute:probe' +DEVICE_OWNER_COMPUTE_PROBE = constants.DEVICE_OWNER_COMPUTE_PREFIX + 'probe' class NeutronDebugAgent(object): diff --git a/neutron/notifiers/nova.py b/neutron/notifiers/nova.py index adb6520c8..3479ef91d 100644 --- a/neutron/notifiers/nova.py +++ b/neutron/notifiers/nova.py @@ -67,7 +67,8 @@ class Notifier(object): def _is_compute_port(self, port): try: if (port['device_id'] and uuidutils.is_uuid_like(port['device_id']) - and port['device_owner'].startswith('compute:')): + and port['device_owner'].startswith( + constants.DEVICE_OWNER_COMPUTE_PREFIX)): return True except (KeyError, AttributeError): pass diff --git a/neutron/tests/functional/agent/linux/test_iptables_firewall.py b/neutron/tests/functional/agent/linux/test_iptables_firewall.py index 2d82fdd73..625bb7c8e 100644 --- a/neutron/tests/functional/agent/linux/test_iptables_firewall.py +++ b/neutron/tests/functional/agent/linux/test_iptables_firewall.py @@ -18,11 +18,14 @@ from neutron.agent.linux import iptables_firewall from neutron.agent import securitygroups_rpc as sg_cfg +from neutron.common import constants from neutron.tests.common import machine_fixtures from neutron.tests.common import net_helpers from neutron.tests.functional import base from oslo_config import cfg +DEVICE_OWNER_COMPUTE = constants.DEVICE_OWNER_COMPUTE_PREFIX + 'fake' + class IptablesFirewallTestCase(base.BaseSudoTestCase): MAC_REAL = "fa:16:3e:9a:2f:49" @@ -51,7 +54,7 @@ class IptablesFirewallTestCase(base.BaseSudoTestCase): self.client.port.name) self.src_port_desc = {'admin_state_up': True, 'device': client_br_port_name, - 'device_owner': 'compute:None', + 'device_owner': DEVICE_OWNER_COMPUTE, 'fixed_ips': [self.client.ip], 'mac_address': self.MAC_REAL, 'port_security_enabled': True, diff --git a/neutron/tests/functional/agent/test_l3_agent.py b/neutron/tests/functional/agent/test_l3_agent.py index d8eca9630..e2bcd9696 100644 --- a/neutron/tests/functional/agent/test_l3_agent.py +++ b/neutron/tests/functional/agent/test_l3_agent.py @@ -59,6 +59,8 @@ _uuid = uuidutils.generate_uuid METADATA_REQUEST_TIMEOUT = 60 METADATA_REQUEST_SLEEP = 5 +DEVICE_OWNER_COMPUTE = l3_constants.DEVICE_OWNER_COMPUTE_PREFIX + 'fake' + def get_ovs_bridge(br_name): return ovs_lib.OVSBridge(br_name) @@ -1413,7 +1415,7 @@ class TestDvrRouter(L3AgentTestFramework): port_data = { 'fixed_ips': [{'ip_address': expected_neighbor}], 'mac_address': 'fa:3e:aa:bb:cc:dd', - 'device_owner': 'compute:None' + 'device_owner': DEVICE_OWNER_COMPUTE } self.agent.plugin_rpc.get_ports_by_subnet.return_value = [port_data] router1 = self.manage_router(self.agent, router_info) diff --git a/neutron/tests/functional/services/l3_router/test_l3_dvr_router_plugin.py b/neutron/tests/functional/services/l3_router/test_l3_dvr_router_plugin.py index da0ba9216..c65b271c7 100644 --- a/neutron/tests/functional/services/l3_router/test_l3_dvr_router_plugin.py +++ b/neutron/tests/functional/services/l3_router/test_l3_dvr_router_plugin.py @@ -15,17 +15,20 @@ import mock from neutron.api.v2 import attributes -from neutron.common import constants as l3_const +from neutron.common import constants from neutron.extensions import external_net from neutron.tests.common import helpers from neutron.tests.unit.plugins.ml2 import base as ml2_test_base +DEVICE_OWNER_COMPUTE = constants.DEVICE_OWNER_COMPUTE_PREFIX + 'fake' + + class L3DvrTestCase(ml2_test_base.ML2TestFramework): def setUp(self): super(L3DvrTestCase, self).setUp() self.l3_agent = helpers.register_l3_agent( - agent_mode=l3_const.L3_AGENT_MODE_DVR_SNAT) + agent_mode=constants.L3_AGENT_MODE_DVR_SNAT) def _create_router(self, distributed=True): return (super(L3DvrTestCase, self). @@ -45,19 +48,19 @@ class L3DvrTestCase(ml2_test_base.ML2TestFramework): def test_get_device_owner_distributed_router_object(self): router = self._create_router() self.assertEqual( - l3_const.DEVICE_OWNER_DVR_INTERFACE, + constants.DEVICE_OWNER_DVR_INTERFACE, self.l3_plugin._get_device_owner(self.context, router)) def test_get_device_owner_distributed_router_id(self): router = self._create_router() self.assertEqual( - l3_const.DEVICE_OWNER_DVR_INTERFACE, + constants.DEVICE_OWNER_DVR_INTERFACE, self.l3_plugin._get_device_owner(self.context, router['id'])) def test_get_device_owner_centralized(self): router = self._create_router(distributed=False) self.assertEqual( - l3_const.DEVICE_OWNER_ROUTER_INTF, + constants.DEVICE_OWNER_ROUTER_INTF, self.l3_plugin._get_device_owner(self.context, router['id'])) def test_get_agent_gw_ports_exist_for_network_no_port(self): @@ -98,7 +101,7 @@ class L3DvrTestCase(ml2_test_base.ML2TestFramework): self.context, filters={ 'network_id': [subnet1['subnet']['network_id']], 'device_owner': - [l3_const.DEVICE_OWNER_DVR_INTERFACE]})[0] + [constants.DEVICE_OWNER_DVR_INTERFACE]})[0] self.l3_plugin.remove_router_interface( self.context, router['id'], {'port_id': port['id']}) @@ -125,7 +128,7 @@ class L3DvrTestCase(ml2_test_base.ML2TestFramework): 'mac_address': attributes.ATTR_NOT_SPECIFIED, 'fixed_ips': attributes.ATTR_NOT_SPECIFIED, 'device_id': self.l3_agent['id'], - 'device_owner': l3_const.DEVICE_OWNER_AGENT_GW, + 'device_owner': constants.DEVICE_OWNER_AGENT_GW, 'binding:host_id': '', 'admin_state_up': True, 'name': ''}}) @@ -227,7 +230,7 @@ class L3DvrTestCase(ml2_test_base.ML2TestFramework): with self.subnet() as ext_subnet,\ self.subnet(cidr='20.0.0.0/24') as int_subnet,\ self.port(subnet=int_subnet, - device_owner='compute:None') as int_port: + device_owner=DEVICE_OWNER_COMPUTE) as int_port: # make net external ext_net_id = ext_subnet['subnet']['network_id'] self._update('networks', ext_net_id, @@ -272,9 +275,9 @@ class L3DvrTestCase(ml2_test_base.ML2TestFramework): self.subnet(cidr='20.0.0.0/24') as int_subnet1,\ self.subnet(cidr='30.0.0.0/24') as int_subnet2,\ self.port(subnet=int_subnet1, - device_owner='compute:None') as int_port1,\ + device_owner=DEVICE_OWNER_COMPUTE) as int_port1,\ self.port(subnet=int_subnet2, - device_owner='compute:None') as int_port2: + device_owner=DEVICE_OWNER_COMPUTE) as int_port2: # locate internal ports on different hosts self.core_plugin.update_port( self.context, int_port1['port']['id'], @@ -284,9 +287,9 @@ class L3DvrTestCase(ml2_test_base.ML2TestFramework): {'port': {'binding:host_id': 'host2'}}) # and create l3 agents on corresponding hosts helpers.register_l3_agent(host='host1', - agent_mode=l3_const.L3_AGENT_MODE_DVR) + agent_mode=constants.L3_AGENT_MODE_DVR) helpers.register_l3_agent(host='host2', - agent_mode=l3_const.L3_AGENT_MODE_DVR) + agent_mode=constants.L3_AGENT_MODE_DVR) # make net external ext_net_id = ext_subnet['subnet']['network_id'] @@ -350,7 +353,7 @@ class L3DvrTestCase(ml2_test_base.ML2TestFramework): with self.subnet() as ext_subnet,\ self.subnet(cidr='20.0.0.0/24') as int_subnet,\ self.port(subnet=int_subnet, - device_owner='compute:None') as int_port: + device_owner=DEVICE_OWNER_COMPUTE) as int_port: # make net external ext_net_id = ext_subnet['subnet']['network_id'] self._update('networks', ext_net_id, @@ -456,7 +459,7 @@ class L3DvrTestCase(ml2_test_base.ML2TestFramework): # register l3 agent in dvr mode in addition to existing dvr_snat agent HOST = 'host1' dvr_agent = helpers.register_l3_agent( - host=HOST, agent_mode=l3_const.L3_AGENT_MODE_DVR) + host=HOST, agent_mode=constants.L3_AGENT_MODE_DVR) router = self._create_router() with self.subnet() as subnet: self.l3_plugin.add_router_interface( @@ -472,7 +475,7 @@ class L3DvrTestCase(ml2_test_base.ML2TestFramework): with mock.patch.object(self.l3_plugin, '_l3_rpc_notifier') as l3_notifier,\ self.port(subnet=subnet, - device_owner='compute:None') as port: + device_owner=DEVICE_OWNER_COMPUTE) as port: self.core_plugin.update_port( self.context, port['port']['id'], {'port': {'binding:host_id': HOST}}) diff --git a/neutron/tests/unit/common/test_utils.py b/neutron/tests/unit/common/test_utils.py index 97939ebaf..553c6622b 100644 --- a/neutron/tests/unit/common/test_utils.py +++ b/neutron/tests/unit/common/test_utils.py @@ -570,7 +570,7 @@ class TestDvrServices(base.BaseTestCase): self._test_is_dvr_serviced(constants.DEVICE_OWNER_DHCP, True) def test_is_dvr_serviced_with_vm_port(self): - self._test_is_dvr_serviced('compute:', True) + self._test_is_dvr_serviced(constants.DEVICE_OWNER_COMPUTE_PREFIX, True) class TestIpToCidr(base.BaseTestCase): diff --git a/neutron/tests/unit/db/test_agentschedulers_db.py b/neutron/tests/unit/db/test_agentschedulers_db.py index 2a56241ab..65e34e702 100644 --- a/neutron/tests/unit/db/test_agentschedulers_db.py +++ b/neutron/tests/unit/db/test_agentschedulers_db.py @@ -52,6 +52,10 @@ DHCP_HOSTA = 'hosta' L3_HOSTB = 'hostb' DHCP_HOSTC = 'hostc' +DEVICE_OWNER_COMPUTE = ''.join([constants.DEVICE_OWNER_COMPUTE_PREFIX, + 'test:', + DHCP_HOSTA]) + class AgentSchedulerTestMixIn(object): @@ -402,7 +406,7 @@ class OvsAgentSchedulerTestCase(OvsAgentSchedulerTestCaseBase): result0 = len(dhcp_agents['agents']) self._register_agent_states() with self.port(subnet=subnet, - device_owner="compute:test:" + DHCP_HOSTA) as port: + device_owner=DEVICE_OWNER_COMPUTE) as port: dhcp_agents = self._list_dhcp_agents_hosting_network( port['port']['network_id']) result1 = len(dhcp_agents['agents']) @@ -417,7 +421,7 @@ class OvsAgentSchedulerTestCase(OvsAgentSchedulerTestCaseBase): result0 = len(dhcp_agents['agents']) self._register_agent_states() with self.port(subnet=subnet, - device_owner="compute:test:" + DHCP_HOSTA) as port: + device_owner=DEVICE_OWNER_COMPUTE) as port: dhcp_agents = self._list_dhcp_agents_hosting_network( port['port']['network_id']) result1 = len(dhcp_agents['agents']) @@ -432,13 +436,13 @@ class OvsAgentSchedulerTestCase(OvsAgentSchedulerTestCaseBase): result0 = len(dhcp_agents['agents']) self._register_agent_states() with self.port(subnet=subnet, - device_owner="compute:test:" + DHCP_HOSTA) as port: + device_owner=DEVICE_OWNER_COMPUTE) as port: dhcp_agents = self._list_dhcp_agents_hosting_network( port['port']['network_id']) result1 = len(dhcp_agents['agents']) helpers.register_dhcp_agent('host1') with self.port(subnet=subnet, - device_owner="compute:test:" + DHCP_HOSTA) as port: + device_owner=DEVICE_OWNER_COMPUTE) as port: dhcp_agents = self._list_dhcp_agents_hosting_network( port['port']['network_id']) result2 = len(dhcp_agents['agents']) diff --git a/neutron/tests/unit/db/test_db_base_plugin_v2.py b/neutron/tests/unit/db/test_db_base_plugin_v2.py index 4f2ee240e..1834deefc 100644 --- a/neutron/tests/unit/db/test_db_base_plugin_v2.py +++ b/neutron/tests/unit/db/test_db_base_plugin_v2.py @@ -51,7 +51,7 @@ from neutron.tests.unit import testlib_api DB_PLUGIN_KLASS = 'neutron.db.db_base_plugin_v2.NeutronDbPluginV2' -DEVICE_OWNER_COMPUTE = 'compute:None' +DEVICE_OWNER_COMPUTE = constants.DEVICE_OWNER_COMPUTE_PREFIX + 'fake' DEVICE_OWNER_NOT_COMPUTE = constants.DEVICE_OWNER_DHCP diff --git a/neutron/tests/unit/extensions/test_l3.py b/neutron/tests/unit/extensions/test_l3.py index f9dc6a8c8..e0e8cee55 100644 --- a/neutron/tests/unit/extensions/test_l3.py +++ b/neutron/tests/unit/extensions/test_l3.py @@ -62,6 +62,9 @@ _uuid = uuidutils.generate_uuid _get_path = test_base._get_path +DEVICE_OWNER_COMPUTE = l3_constants.DEVICE_OWNER_COMPUTE_PREFIX + 'fake' + + class L3TestExtensionManager(object): def get_resources(self): @@ -2831,7 +2834,7 @@ class L3RpcCallbackTestCase(base.BaseTestCase): port_id = 'foo_port_id' port = { 'id': port_id, - 'device_owner': 'compute:None', + 'device_owner': DEVICE_OWNER_COMPUTE, portbindings.HOST_ID: '', portbindings.VIF_TYPE: portbindings.VIF_TYPE_BINDING_FAILED } diff --git a/neutron/tests/unit/extensions/test_l3_ext_gw_mode.py b/neutron/tests/unit/extensions/test_l3_ext_gw_mode.py index 83f2d13c4..28577f571 100644 --- a/neutron/tests/unit/extensions/test_l3_ext_gw_mode.py +++ b/neutron/tests/unit/extensions/test_l3_ext_gw_mode.py @@ -204,7 +204,7 @@ class TestL3GwModeMixin(testlib_api.SqlTestCase): tenant_id=self.tenant_id, admin_state_up=True, device_id='something', - device_owner='compute:nova', + device_owner=constants.DEVICE_OWNER_COMPUTE_PREFIX + 'nova', status=constants.PORT_STATUS_ACTIVE, mac_address=FAKE_FIP_INT_PORT_MAC, network_id=self.int_net_id) diff --git a/neutron/tests/unit/notifiers/test_nova.py b/neutron/tests/unit/notifiers/test_nova.py index 6f6a24b8c..551e912a5 100644 --- a/neutron/tests/unit/notifiers/test_nova.py +++ b/neutron/tests/unit/notifiers/test_nova.py @@ -21,11 +21,13 @@ from sqlalchemy.orm import attributes as sql_attr from oslo_config import cfg -from neutron.common import constants +from neutron.common import constants as n_const from neutron.db import models_v2 from neutron.notifiers import nova from neutron.tests import base +DEVICE_OWNER_COMPUTE = n_const.DEVICE_OWNER_COMPUTE_PREFIX + 'fake' + class TestNovaNotify(base.BaseTestCase): def setUp(self, plugin=None): @@ -35,14 +37,14 @@ class TestNovaNotify(base.BaseTestCase): def get_port(self, context, port_id): device_id = '32102d7b-1cf4-404d-b50a-97aae1f55f87' return {'device_id': device_id, - 'device_owner': 'compute:None'} + 'device_owner': DEVICE_OWNER_COMPUTE} self.nova_notifier = nova.Notifier() self.nova_notifier._plugin_ref = FakePlugin() def test_notify_port_status_all_values(self): - states = [constants.PORT_STATUS_ACTIVE, constants.PORT_STATUS_DOWN, - constants.PORT_STATUS_ERROR, constants.PORT_STATUS_BUILD, + states = [n_const.PORT_STATUS_ACTIVE, n_const.PORT_STATUS_DOWN, + n_const.PORT_STATUS_ERROR, n_const.PORT_STATUS_BUILD, sql_attr.NO_VALUE] device_id = '32102d7b-1cf4-404d-b50a-97aae1f55f87' # test all combinations @@ -50,7 +52,7 @@ class TestNovaNotify(base.BaseTestCase): for current_port_status in states: port = models_v2.Port(id='port-uuid', device_id=device_id, - device_owner="compute:", + device_owner=DEVICE_OWNER_COMPUTE, status=current_port_status) self._record_port_status_changed_helper(current_port_status, previous_port_status, @@ -58,33 +60,33 @@ class TestNovaNotify(base.BaseTestCase): def test_port_without_uuid_device_id_no_notify(self): port = models_v2.Port(id='port-uuid', device_id='compute_probe:', - device_owner='compute:', - status=constants.PORT_STATUS_ACTIVE) - self._record_port_status_changed_helper(constants.PORT_STATUS_ACTIVE, + device_owner=DEVICE_OWNER_COMPUTE, + status=n_const.PORT_STATUS_ACTIVE) + self._record_port_status_changed_helper(n_const.PORT_STATUS_ACTIVE, sql_attr.NO_VALUE, port) def test_port_without_device_owner_no_notify(self): device_id = '32102d7b-1cf4-404d-b50a-97aae1f55f87' port = models_v2.Port(id='port-uuid', device_id=device_id, - status=constants.PORT_STATUS_ACTIVE) - self._record_port_status_changed_helper(constants.PORT_STATUS_ACTIVE, + status=n_const.PORT_STATUS_ACTIVE) + self._record_port_status_changed_helper(n_const.PORT_STATUS_ACTIVE, sql_attr.NO_VALUE, port) def test_port_without_device_id_no_notify(self): port = models_v2.Port(id='port-uuid', device_owner="network:dhcp", - status=constants.PORT_STATUS_ACTIVE) - self._record_port_status_changed_helper(constants.PORT_STATUS_ACTIVE, + status=n_const.PORT_STATUS_ACTIVE) + self._record_port_status_changed_helper(n_const.PORT_STATUS_ACTIVE, sql_attr.NO_VALUE, port) def test_port_without_id_no_notify(self): device_id = '32102d7b-1cf4-404d-b50a-97aae1f55f87' port = models_v2.Port(device_id=device_id, - device_owner="compute:", - status=constants.PORT_STATUS_ACTIVE) - self._record_port_status_changed_helper(constants.PORT_STATUS_ACTIVE, + device_owner=DEVICE_OWNER_COMPUTE, + status=n_const.PORT_STATUS_ACTIVE) + self._record_port_status_changed_helper(n_const.PORT_STATUS_ACTIVE, sql_attr.NO_VALUE, port) @@ -92,8 +94,8 @@ class TestNovaNotify(base.BaseTestCase): device_id = '32102d7b-1cf4-404d-b50a-97aae1f55f87' port = models_v2.Port(id='port-uuid', device_id=device_id, device_owner="network:dhcp", - status=constants.PORT_STATUS_ACTIVE) - self._record_port_status_changed_helper(constants.PORT_STATUS_ACTIVE, + status=n_const.PORT_STATUS_ACTIVE) + self._record_port_status_changed_helper(n_const.PORT_STATUS_ACTIVE, sql_attr.NO_VALUE, port) @@ -101,19 +103,20 @@ class TestNovaNotify(base.BaseTestCase): previous_port_status, port): if not (port.device_id and port.id and port.device_owner and - port.device_owner.startswith('compute:') and + port.device_owner.startswith( + n_const.DEVICE_OWNER_COMPUTE_PREFIX) and uuidutils.is_uuid_like(port.device_id)): return - if (previous_port_status == constants.PORT_STATUS_ACTIVE and - current_port_status == constants.PORT_STATUS_DOWN): + if (previous_port_status == n_const.PORT_STATUS_ACTIVE and + current_port_status == n_const.PORT_STATUS_DOWN): event_name = nova.VIF_UNPLUGGED elif (previous_port_status in [sql_attr.NO_VALUE, - constants.PORT_STATUS_DOWN, - constants.PORT_STATUS_BUILD] - and current_port_status in [constants.PORT_STATUS_ACTIVE, - constants.PORT_STATUS_ERROR]): + n_const.PORT_STATUS_DOWN, + n_const.PORT_STATUS_BUILD] + and current_port_status in [n_const.PORT_STATUS_ACTIVE, + n_const.PORT_STATUS_ERROR]): event_name = nova.VIF_PLUGGED else: @@ -132,7 +135,7 @@ class TestNovaNotify(base.BaseTestCase): def test_update_fixed_ip_changed(self): device_id = '32102d7b-1cf4-404d-b50a-97aae1f55f87' returned_obj = {'port': - {'device_owner': u'compute:dfd', + {'device_owner': DEVICE_OWNER_COMPUTE, 'id': u'bee50827-bcee-4cc8-91c1-a27b0ce54222', 'device_id': device_id}} @@ -295,7 +298,7 @@ class TestNovaNotify(base.BaseTestCase): device_id = '32102d7b-1cf4-404d-b50a-97aae1f55f87' port_id = 'bee50827-bcee-4cc8-91c1-a27b0ce54222' returned_obj = {'port': - {'device_owner': 'compute:dfd', + {'device_owner': DEVICE_OWNER_COMPUTE, 'id': port_id, 'device_id': device_id}} diff --git a/neutron/tests/unit/objects/qos/test_rule.py b/neutron/tests/unit/objects/qos/test_rule.py index f4e14e703..e73778287 100644 --- a/neutron/tests/unit/objects/qos/test_rule.py +++ b/neutron/tests/unit/objects/qos/test_rule.py @@ -20,7 +20,7 @@ from neutron.tests.unit import testlib_api POLICY_ID_A = 'policy-id-a' POLICY_ID_B = 'policy-id-b' -DEVICE_OWNER_COMPUTE = 'compute:None' +DEVICE_OWNER_COMPUTE = constants.DEVICE_OWNER_COMPUTE_PREFIX + 'fake' class QosRuleObjectTestCase(neutron_test_base.BaseTestCase): diff --git a/neutron/tests/unit/plugins/ml2/drivers/l2pop/test_mech_driver.py b/neutron/tests/unit/plugins/ml2/drivers/l2pop/test_mech_driver.py index ef0386657..ccfe85ba3 100644 --- a/neutron/tests/unit/plugins/ml2/drivers/l2pop/test_mech_driver.py +++ b/neutron/tests/unit/plugins/ml2/drivers/l2pop/test_mech_driver.py @@ -43,7 +43,7 @@ HOST_5 = HOST + '_5' NOTIFIER = 'neutron.plugins.ml2.rpc.AgentNotifierApi' -DEVICE_OWNER_COMPUTE = 'compute:None' +DEVICE_OWNER_COMPUTE = constants.DEVICE_OWNER_COMPUTE_PREFIX + 'fake' class TestL2PopulationRpcTestCase(test_plugin.Ml2PluginV2TestCase): @@ -894,7 +894,7 @@ class TestL2PopulationMechDriver(base.BaseTestCase): def test_update_port_precommit_mac_address_changed_raises(self): port = {'status': u'ACTIVE', - 'device_owner': u'compute:None', + 'device_owner': DEVICE_OWNER_COMPUTE, 'mac_address': u'12:34:56:78:4b:0e', 'id': u'1'} diff --git a/neutron/tests/unit/plugins/ml2/drivers/openvswitch/agent/test_ovs_neutron_agent.py b/neutron/tests/unit/plugins/ml2/drivers/openvswitch/agent/test_ovs_neutron_agent.py index 304d5f02c..25936b779 100644 --- a/neutron/tests/unit/plugins/ml2/drivers/openvswitch/agent/test_ovs_neutron_agent.py +++ b/neutron/tests/unit/plugins/ml2/drivers/openvswitch/agent/test_ovs_neutron_agent.py @@ -50,6 +50,8 @@ TEST_PORT_ID3 = 'port-id-3' TEST_NETWORK_ID1 = 'net-id-1' TEST_NETWORK_ID2 = 'net-id-2' +DEVICE_OWNER_COMPUTE = n_const.DEVICE_OWNER_COMPUTE_PREFIX + 'fake' + class FakeVif(object): ofport = 99 @@ -167,7 +169,7 @@ class TestOvsNeutronAgent(object): int_br.set_db_attribute.return_value = True needs_binding = self.agent.port_bound( port, net_uuid, 'local', None, None, - fixed_ips, "compute:None", False) + fixed_ips, DEVICE_OWNER_COMPUTE, False) if db_get_val is None: self.assertEqual(0, int_br.set_db_attribute.call_count) self.assertFalse(needs_binding) @@ -602,7 +604,7 @@ class TestOvsNeutronAgent(object): 'network_type': 'baz', 'fixed_ips': [{'subnet_id': 'my-subnet-uuid', 'ip_address': '1.1.1.1'}], - 'device_owner': 'compute:None', + 'device_owner': DEVICE_OWNER_COMPUTE, 'port_security_enabled': True } @@ -2054,13 +2056,13 @@ class TestOvsDvrNeutronAgent(object): def test_port_bound_for_dvr_with_compute_ports(self): self._test_port_bound_for_dvr_on_vlan_network( - device_owner="compute:None") + device_owner=DEVICE_OWNER_COMPUTE) self._test_port_bound_for_dvr_on_vlan_network( - device_owner="compute:None", ip_version=6) + device_owner=DEVICE_OWNER_COMPUTE, ip_version=6) self._test_port_bound_for_dvr_on_vxlan_network( - device_owner="compute:None") + device_owner=DEVICE_OWNER_COMPUTE) self._test_port_bound_for_dvr_on_vxlan_network( - device_owner="compute:None", ip_version=6) + device_owner=DEVICE_OWNER_COMPUTE, ip_version=6) def test_port_bound_for_dvr_with_lbaas_vip_ports(self): self._test_port_bound_for_dvr_on_vlan_network( @@ -2348,9 +2350,9 @@ class TestOvsDvrNeutronAgent(object): def test_treat_devices_removed_for_dvr_with_compute_ports(self): self._test_treat_devices_removed_for_dvr( - device_owner="compute:None") + device_owner=DEVICE_OWNER_COMPUTE) self._test_treat_devices_removed_for_dvr( - device_owner="compute:None", ip_version=6) + device_owner=DEVICE_OWNER_COMPUTE, ip_version=6) def test_treat_devices_removed_for_dvr_with_lbaas_vip_ports(self): self._test_treat_devices_removed_for_dvr( diff --git a/neutron/tests/unit/plugins/ml2/drivers/openvswitch/agent/test_ovs_tunnel.py b/neutron/tests/unit/plugins/ml2/drivers/openvswitch/agent/test_ovs_tunnel.py index 079d2dea0..c0cecfcb8 100644 --- a/neutron/tests/unit/plugins/ml2/drivers/openvswitch/agent/test_ovs_tunnel.py +++ b/neutron/tests/unit/plugins/ml2/drivers/openvswitch/agent/test_ovs_tunnel.py @@ -23,6 +23,7 @@ import six from neutron.agent.common import ovs_lib from neutron.agent.linux import ip_lib +from neutron.common import constants as n_const from neutron.plugins.common import constants as p_const from neutron.plugins.ml2.drivers.openvswitch.agent.common import constants from neutron.tests.unit.plugins.ml2.drivers.openvswitch.agent \ @@ -48,7 +49,7 @@ VIF_PORT = ovs_lib.VifPort('port', OFPORT_NUM, VIF_PORTS = {VIF_ID: VIF_PORT} FIXED_IPS = [{'subnet_id': 'my-subnet-uuid', 'ip_address': '1.1.1.1'}] -VM_DEVICE_OWNER = "compute:None" +VM_DEVICE_OWNER = n_const.DEVICE_OWNER_COMPUTE_PREFIX + 'fake' TUN_OFPORTS = {p_const.TYPE_GRE: {'ip1': '11', 'ip2': '12'}} diff --git a/neutron/tests/unit/plugins/ml2/test_plugin.py b/neutron/tests/unit/plugins/ml2/test_plugin.py index 1db4d7af9..bf4df57e8 100644 --- a/neutron/tests/unit/plugins/ml2/test_plugin.py +++ b/neutron/tests/unit/plugins/ml2/test_plugin.py @@ -69,7 +69,7 @@ config.cfg.CONF.import_opt('network_vlan_ranges', PLUGIN_NAME = 'neutron.plugins.ml2.plugin.Ml2Plugin' -DEVICE_OWNER_COMPUTE = 'compute:None' +DEVICE_OWNER_COMPUTE = constants.DEVICE_OWNER_COMPUTE_PREFIX + 'fake' HOST = 'fake_host' @@ -643,7 +643,7 @@ class TestMl2PortsV2(test_plugin.TestPortsV2, Ml2PluginV2TestCase): self.assertTrue(notify.call_counts) def test_check_if_compute_port_serviced_by_dvr(self): - self.assertTrue(utils.is_dvr_serviced('compute:None')) + self.assertTrue(utils.is_dvr_serviced(DEVICE_OWNER_COMPUTE)) def test_check_if_lbaas_vip_port_serviced_by_dvr(self): self.assertTrue(utils.is_dvr_serviced( @@ -795,10 +795,10 @@ class TestMl2DvrPortsV2(TestMl2PortsV2): port['port']['id']) def test_delete_last_vm_port(self): - self._test_delete_dvr_serviced_port(device_owner='compute:None') + self._test_delete_dvr_serviced_port(device_owner=DEVICE_OWNER_COMPUTE) def test_delete_last_vm_port_with_floatingip(self): - self._test_delete_dvr_serviced_port(device_owner='compute:None', + self._test_delete_dvr_serviced_port(device_owner=DEVICE_OWNER_COMPUTE, floating_ip=True) def test_delete_lbaas_vip_port(self): @@ -1757,7 +1757,7 @@ class TestMl2PluginCreateUpdateDeletePort(base.BaseTestCase): admin_state_up=True, status='ACTIVE', device_id='vm_id', - device_owner='compute:None') + device_owner=DEVICE_OWNER_COMPUTE) binding = mock.Mock() binding.port_id = port_id diff --git a/neutron/tests/unit/scheduler/test_l3_agent_scheduler.py b/neutron/tests/unit/scheduler/test_l3_agent_scheduler.py index fed593587..db20311d3 100644 --- a/neutron/tests/unit/scheduler/test_l3_agent_scheduler.py +++ b/neutron/tests/unit/scheduler/test_l3_agent_scheduler.py @@ -56,6 +56,8 @@ load_tests = testscenarios.load_tests_apply_scenarios HOST_DVR = 'my_l3_host_dvr' HOST_DVR_SNAT = 'my_l3_host_dvr_snat' +DEVICE_OWNER_COMPUTE = constants.DEVICE_OWNER_COMPUTE_PREFIX + 'fake' +DEVICE_OWNER_COMPUTE_NOVA = constants.DEVICE_OWNER_COMPUTE_PREFIX + 'nova' class FakeL3Scheduler(l3_agent_scheduler.L3Scheduler): @@ -740,7 +742,7 @@ class L3SchedulerTestBaseMixin(object): # matching subnet port = {'subnet_id': str(uuid.uuid4()), 'binding:host_id': 'host_1', - 'device_owner': 'compute:', + 'device_owner': constants.DEVICE_OWNER_COMPUTE_PREFIX, 'id': 1234} subnet = {'id': str(uuid.uuid4()), 'enable_dhcp': False} @@ -934,7 +936,7 @@ class L3DvrSchedulerTestCase(testlib_api.SqlTestCase): 'id': port_id, 'binding:host_id': 'vm-host', 'device_id': 'vm-id', - 'device_owner': 'compute:None', + 'device_owner': DEVICE_OWNER_COMPUTE, 'mac_address': '02:04:05:17:18:19' }, 'mac_address_updated': True @@ -973,7 +975,7 @@ class L3DvrSchedulerTestCase(testlib_api.SqlTestCase): 'id': port_id, 'binding:host_id': 'vm-host', 'device_id': 'vm-id', - 'device_owner': 'compute:None' + 'device_owner': DEVICE_OWNER_COMPUTE } } @@ -1028,7 +1030,7 @@ class L3DvrSchedulerTestCase(testlib_api.SqlTestCase): port = { 'id': 'port1', 'device_id': 'abcd', - 'device_owner': 'compute:nova', + 'device_owner': DEVICE_OWNER_COMPUTE_NOVA, 'binding:host_id': 'host1', 'fixed_ips': [ { @@ -1140,7 +1142,7 @@ class L3DvrSchedulerTestCase(testlib_api.SqlTestCase): 'device_id': 'r1', 'status': port_status, 'binding:host_id': 'thisHost', - 'device_owner': 'compute:nova', + 'device_owner': DEVICE_OWNER_COMPUTE_NOVA, 'fixed_ips': [ { 'subnet_id': '80947d4a-fbc8-484b-9f92-623a6bfcf3e0', @@ -1215,7 +1217,7 @@ class L3DvrSchedulerTestCase(testlib_api.SqlTestCase): def _create_port(self, port_name, tenant_id, host, subnet_id, ip_address, status='ACTIVE', - device_owner='compute:nova'): + device_owner=DEVICE_OWNER_COMPUTE_NOVA): return { 'id': port_name + '-port-id', 'tenant_id': tenant_id,