Replace device owners hard coded strings to neutron_lib constants

Change-Id: I821f0def82164ab1303188d3f1bdfd85473470cd
changes/51/338251/3
Edan David 6 years ago
parent b6592c7372
commit 151d94521f
  1. 7
      neutron/agent/l2/extensions/fdb_population.py
  2. 2
      neutron/debug/debug_agent.py
  3. 2
      neutron/tests/functional/agent/l2/base.py
  4. 2
      neutron/tests/functional/db/test_ipam.py
  5. 5
      neutron/tests/unit/agent/l2/extensions/test_fdb_population.py
  6. 4
      neutron/tests/unit/db/test_ipam_non_pluggable_backend.py
  7. 4
      neutron/tests/unit/db/test_ipam_pluggable_backend.py
  8. 9
      neutron/tests/unit/db/test_l3_db.py
  9. 10
      neutron/tests/unit/ipam/test_requests.py
  10. 4
      neutron/tests/unit/plugins/ml2/test_driver_context.py
  11. 4
      neutron/tests/unit/scheduler/test_l3_agent_scheduler.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

@ -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'

@ -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}

@ -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})

@ -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 = (

@ -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(

@ -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,

@ -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()

@ -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)

@ -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'

@ -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 = {

Loading…
Cancel
Save