Create an OVN metadata namespace prefix constant
Create a constant for the OVN metadata namespace prefix called OVN_METADATA_PREFIX and use it throughout tree. TrivialFix Change-Id: Ib068c49a0cbba3cbf592a337187e3dc70dbae37d
This commit is contained in:
parent
119c3ba85c
commit
41fd683663
|
@ -46,7 +46,7 @@ agents_db.register_db_agents_opts()
|
|||
_SYNC_STATE_LOCK = lockutils.ReaderWriterLock()
|
||||
CHASSIS_METADATA_LOCK = 'chassis_metadata_lock'
|
||||
|
||||
NS_PREFIX = 'ovnmeta-'
|
||||
NS_PREFIX = ovn_const.OVN_METADATA_PREFIX
|
||||
MAC_PATTERN = re.compile(r'([0-9A-F]{2}[:-]){5}([0-9A-F]{2})', re.I)
|
||||
OVN_VIF_PORT_TYPES = (
|
||||
"", ovn_const.LSP_TYPE_EXTERNAL, ovn_const.LSP_TYPE_LOCALPORT)
|
||||
|
|
|
@ -70,6 +70,7 @@ OVN_ROUTER_PORT_GW_MTU_OPTION = 'gateway_mtu'
|
|||
OVN_PROVNET_PORT_NAME_PREFIX = 'provnet-'
|
||||
OVN_NAME_PREFIX = 'neutron-'
|
||||
OVN_HA_CH_GROUP_EXTPORT_PREFIX = 'neutron-extport-'
|
||||
OVN_METADATA_PREFIX = 'ovnmeta-'
|
||||
|
||||
# TODO(froyo): Move this to neutron-lib as soon as possible, and when a new
|
||||
# release is created and pointed to in the requirements remove this code
|
||||
|
|
|
@ -641,7 +641,7 @@ def ovn_metadata_name(id_):
|
|||
|
||||
def is_ovn_metadata_port(port):
|
||||
return (port['device_owner'] == const.DEVICE_OWNER_DISTRIBUTED and
|
||||
port['device_id'].startswith('ovnmeta'))
|
||||
port['device_id'].startswith(constants.OVN_METADATA_PREFIX))
|
||||
|
||||
|
||||
def is_ovn_lb_hm_port(port):
|
||||
|
|
|
@ -2437,19 +2437,20 @@ class OVNClient(object):
|
|||
if not ovn_conf.is_ovn_metadata_enabled():
|
||||
return
|
||||
|
||||
metadata_port = self._find_metadata_port(context, network['id'])
|
||||
net_id = network['id']
|
||||
metadata_port = self._find_metadata_port(context, net_id)
|
||||
if metadata_port:
|
||||
return metadata_port
|
||||
|
||||
# Create a neutron port for DHCP/metadata services
|
||||
filters = {'network_id': [network['id']]}
|
||||
filters = {'network_id': [net_id]}
|
||||
subnets = self._plugin.get_subnets(context, filters=filters)
|
||||
fixed_ips = [{'subnet_id': s['id']}
|
||||
for s in subnets if s['enable_dhcp']]
|
||||
port = {'port': {'network_id': network['id'],
|
||||
port = {'port': {'network_id': net_id,
|
||||
'tenant_id': network['project_id'],
|
||||
'device_owner': const.DEVICE_OWNER_DISTRIBUTED,
|
||||
'device_id': 'ovnmeta-%s' % network['id'],
|
||||
'device_id': ovn_const.OVN_METADATA_PREFIX + net_id,
|
||||
'fixed_ips': fixed_ips,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -161,7 +161,8 @@ class TestMetadataAgent(base.TestOVNFunctionalBase):
|
|||
addresses='AA:AA:AA:AA:AA:AA 192.168.122.123',
|
||||
external_ids={
|
||||
ovn_const.OVN_CIDRS_EXT_ID_KEY: '192.168.122.123/24',
|
||||
ovn_const.OVN_DEVID_EXT_ID_KEY: 'ovnmeta-' + lswitch_name,
|
||||
ovn_const.OVN_DEVID_EXT_ID_KEY:
|
||||
ovn_const.OVN_METADATA_PREFIX + lswitch_name,
|
||||
ovn_const.OVN_DEVICE_OWNER_EXT_ID_KEY:
|
||||
constants.DEVICE_OWNER_DISTRIBUTED
|
||||
}))
|
||||
|
@ -170,7 +171,7 @@ class TestMetadataAgent(base.TestOVNFunctionalBase):
|
|||
external_ids = {
|
||||
ovn_const.OVN_CIDRS_EXT_ID_KEY: "192.168.122.2/24",
|
||||
ovn_const.OVN_DEVID_EXT_ID_KEY:
|
||||
'ovnmeta-' + uuidutils.generate_uuid()
|
||||
ovn_const.OVN_METADATA_PREFIX + uuidutils.generate_uuid()
|
||||
}
|
||||
self.nb_api.set_lswitch_port(lport_name=metadata_port_name,
|
||||
external_ids=external_ids).execute()
|
||||
|
|
|
@ -39,6 +39,7 @@ from neutron.agent.linux import utils as linux_utils
|
|||
from neutron.agent.metadata import driver as metadata_driver
|
||||
from neutron.common import _constants as common_constants
|
||||
from neutron.common import config as common_config
|
||||
from neutron.common.ovn import constants as ovn_const
|
||||
from neutron.common import utils
|
||||
from neutron.conf.agent import common as config
|
||||
from neutron.conf.agent import dhcp as dhcp_config
|
||||
|
@ -167,7 +168,8 @@ fake_ovn_port = dhcp.DictModel(id='12345678-1234-aaaa-123456789000',
|
|||
fake_ovn_metadata_port = dhcp.DictModel(id='12345678-1234-aaaa-123456789000',
|
||||
device_owner=const.
|
||||
DEVICE_OWNER_DISTRIBUTED,
|
||||
device_id='ovnmeta-{}'.format(
|
||||
device_id='{}{}'.format(
|
||||
ovn_const.OVN_METADATA_PREFIX,
|
||||
FAKE_NETWORK_UUID),
|
||||
mac_address='aa:bb:cc:dd:ee:99',
|
||||
network_id=FAKE_NETWORK_UUID,
|
||||
|
|
|
@ -34,6 +34,7 @@ from neutron.agent.linux import dhcp
|
|||
from neutron.agent.linux import ip_lib
|
||||
from neutron.cmd import runtime_checks as checks
|
||||
from neutron.common import _constants as common_constants
|
||||
from neutron.common.ovn import constants as ovn_const
|
||||
from neutron.common import utils as common_utils
|
||||
from neutron.conf.agent import common as config
|
||||
from neutron.conf.agent import dhcp as dhcp_config
|
||||
|
@ -99,7 +100,8 @@ class FakeOvnMetadataPort(Dictable):
|
|||
FakeIPAllocation('192.168.0.10',
|
||||
'dddddddd-dddd-dddd-dddd-dddddddddddd')]
|
||||
self.mac_address = '00:00:80:aa:bb:ee'
|
||||
self.device_id = 'ovnmeta-aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'
|
||||
self.device_id = (ovn_const.OVN_METADATA_PREFIX +
|
||||
'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa')
|
||||
self.extra_dhcp_opts = []
|
||||
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@ from neutron.agent.linux.ip_lib import IpNetnsCommand as ip_netns
|
|||
from neutron.agent.linux.ip_lib import IPWrapper as ip_wrap
|
||||
from neutron.agent.ovn.metadata import agent
|
||||
from neutron.agent.ovn.metadata import driver
|
||||
from neutron.common.ovn import constants as ovn_const
|
||||
from neutron.conf.agent.metadata import config as meta_conf
|
||||
from neutron.conf.agent.ovn.metadata import config as ovn_meta_conf
|
||||
from neutron.conf.plugins.ml2.drivers.ovn import ovn_conf
|
||||
|
@ -96,7 +97,8 @@ class TestMetadataAgent(base.BaseTestCase):
|
|||
ip_lib, 'list_network_namespaces') as lnn,\
|
||||
mock.patch.object(
|
||||
self.agent, 'teardown_datapath') as tdp:
|
||||
lnn.return_value = ['ovnmeta-1', 'ovnmeta-2']
|
||||
lnn.return_value = [ovn_const.OVN_METADATA_PREFIX + '1',
|
||||
ovn_const.OVN_METADATA_PREFIX + '2']
|
||||
|
||||
self.agent.sync()
|
||||
|
||||
|
@ -119,7 +121,9 @@ class TestMetadataAgent(base.BaseTestCase):
|
|||
ip_lib, 'list_network_namespaces') as lnn,\
|
||||
mock.patch.object(
|
||||
self.agent, 'teardown_datapath') as tdp:
|
||||
lnn.return_value = ['ovnmeta-1', 'ovnmeta-2', 'ovnmeta-3',
|
||||
lnn.return_value = [ovn_const.OVN_METADATA_PREFIX + '1',
|
||||
ovn_const.OVN_METADATA_PREFIX + '2',
|
||||
ovn_const.OVN_METADATA_PREFIX + '3',
|
||||
'ns1', 'ns2']
|
||||
|
||||
self.agent.sync()
|
||||
|
@ -195,7 +199,7 @@ class TestMetadataAgent(base.BaseTestCase):
|
|||
self.agent.teardown_datapath('1')
|
||||
|
||||
destroy_mdp.assert_called_once_with(
|
||||
mock.ANY, '1', mock.ANY, 'ovnmeta-1')
|
||||
mock.ANY, '1', mock.ANY, ovn_const.OVN_METADATA_PREFIX + '1')
|
||||
self.agent.ovs_idl.del_port.assert_called_once_with('veth_0')
|
||||
del_veth.assert_called_once_with('veth_0')
|
||||
garbage_collect.assert_called_once_with()
|
||||
|
|
|
@ -218,13 +218,13 @@ class TestUtils(base.BaseTestCase):
|
|||
def test_is_ovn_metadata_port(self):
|
||||
meta_port = {
|
||||
'device_owner': n_const.DEVICE_OWNER_DISTRIBUTED,
|
||||
'device_id': 'ovnmeta-12345'}
|
||||
'device_id': constants.OVN_METADATA_PREFIX + '12345'}
|
||||
non_meta_port_0 = {
|
||||
'device_owner': n_const.DEVICE_OWNER_DISTRIBUTED,
|
||||
'device_id': 'dhcp-12345'}
|
||||
non_meta_port_1 = {
|
||||
'device_owner': n_const.DEVICE_OWNER_DHCP,
|
||||
'device_id': 'ovnmeta-12345'}
|
||||
'device_id': constants.OVN_METADATA_PREFIX + '12345'}
|
||||
|
||||
self.assertTrue(utils.is_ovn_metadata_port(meta_port))
|
||||
self.assertFalse(utils.is_ovn_metadata_port(non_meta_port_0))
|
||||
|
@ -236,7 +236,7 @@ class TestUtils(base.BaseTestCase):
|
|||
'device_id': 'ovn-lb-hm-12345'}
|
||||
non_ovn_lb_hm_port_0 = {
|
||||
'device_owner': n_const.DEVICE_OWNER_DISTRIBUTED,
|
||||
'device_id': 'ovnmeta-12345'}
|
||||
'device_id': constants.OVN_METADATA_PREFIX + '12345'}
|
||||
non_ovn_lb_hm_port_1 = {
|
||||
'device_owner': n_const.DEVICE_OWNER_DHCP,
|
||||
'device_id': 'dhcp-12345'}
|
||||
|
|
|
@ -23,6 +23,7 @@ from neutron_lib.exceptions import address_scope as addr_scope_exc
|
|||
from oslo_utils import uuidutils
|
||||
import webob.exc
|
||||
|
||||
from neutron.common.ovn import constants as ovn_const
|
||||
from neutron.db import ipam_backend_mixin
|
||||
from neutron.objects import subnet as subnet_obj
|
||||
from neutron.plugins.ml2 import plugin as ml2_plugin
|
||||
|
@ -88,18 +89,19 @@ class TestIpamBackendMixin(base.BaseTestCase):
|
|||
side_effect=_get_subnet_object)
|
||||
|
||||
def test__is_distributed_service(self):
|
||||
uuid = uuidutils.generate_uuid()
|
||||
port = {'device_owner':
|
||||
'%snova' % constants.DEVICE_OWNER_COMPUTE_PREFIX,
|
||||
'device_id': uuidutils.generate_uuid()}
|
||||
'device_id': uuid}
|
||||
self.assertFalse(self.mixin._is_distributed_service(port))
|
||||
port = {'device_owner': constants.DEVICE_OWNER_DHCP,
|
||||
'device_id': uuidutils.generate_uuid()}
|
||||
'device_id': uuid}
|
||||
self.assertFalse(self.mixin._is_distributed_service(port))
|
||||
port = {'device_owner': constants.DEVICE_OWNER_DHCP,
|
||||
'device_id': 'ovnmeta-%s' % uuidutils.generate_uuid()}
|
||||
'device_id': ovn_const.OVN_METADATA_PREFIX + uuid}
|
||||
self.assertFalse(self.mixin._is_distributed_service(port))
|
||||
port = {'device_owner': constants.DEVICE_OWNER_DISTRIBUTED,
|
||||
'device_id': 'ovnmeta-%s' % uuidutils.generate_uuid()}
|
||||
'device_id': ovn_const.OVN_METADATA_PREFIX + uuid}
|
||||
self.assertTrue(self.mixin._is_distributed_service(port))
|
||||
|
||||
def _test_get_changed_ips_for_port(self, expected, original_ips,
|
||||
|
|
|
@ -26,6 +26,7 @@ from oslo_utils import netutils
|
|||
from oslo_utils import uuidutils
|
||||
import webob.exc
|
||||
|
||||
from neutron.common.ovn import constants as ovn_const
|
||||
from neutron.conf import common as base_config
|
||||
from neutron.db import ipam_backend_mixin
|
||||
from neutron.db import ipam_pluggable_backend
|
||||
|
@ -752,11 +753,12 @@ class TestDbBasePluginIpam(test_db_base.NeutronDbPluginV2TestCase):
|
|||
mocks['ipam']._test_fixed_ips_for_port = fixed_ips_mock
|
||||
mocks['ipam']._update_ips_for_pd_subnet = mock.Mock(return_value=[])
|
||||
|
||||
uuid = uuidutils.generate_uuid()
|
||||
port_dict = {
|
||||
'device_owner': constants.DEVICE_OWNER_DISTRIBUTED,
|
||||
'device_id': 'ovnmeta-%s' % uuidutils.generate_uuid(),
|
||||
'device_id': ovn_const.OVN_METADATA_PREFIX + uuid,
|
||||
'mac_address': 'aa:bb:cc:dd:ee:ff',
|
||||
'network_id': uuidutils.generate_uuid()}
|
||||
'network_id': uuid}
|
||||
|
||||
mocks['ipam']._update_ips_for_port(context, port_dict, None,
|
||||
original_ips, new_ips, mac)
|
||||
|
|
|
@ -2166,7 +2166,7 @@ class TestOVNMechanismDriver(TestOVNMechanismDriverBase):
|
|||
port = {'id': 'metadata_id',
|
||||
'network_id': 'net_id',
|
||||
'device_owner': const.DEVICE_OWNER_DISTRIBUTED,
|
||||
'device_id': 'ovnmeta-%s' % 'net_id',
|
||||
'device_id': ovn_const.OVN_METADATA_PREFIX + 'net_id',
|
||||
'fixed_ips': fixed_ips}
|
||||
mock_get_subnets.return_value = [subnet]
|
||||
mock_find_metaport.return_value = None
|
||||
|
@ -3282,7 +3282,7 @@ class TestOVNMechanismDriverSegment(MechDriverSetupBase,
|
|||
# Make sure both updates where on same metadata port
|
||||
args_list = ovn_nb_api.set_lswitch_port.call_args_list
|
||||
self.assertEqual(
|
||||
'ovnmeta-%s' % self.net['network']['id'],
|
||||
ovn_const.OVN_METADATA_PREFIX + self.net['network']['id'],
|
||||
args_list[6][1]['external_ids']['neutron:device_id'])
|
||||
self.assertEqual(
|
||||
args_list[6][1]['external_ids']['neutron:device_id'],
|
||||
|
@ -3333,7 +3333,7 @@ class TestOVNMechanismDriverSegment(MechDriverSetupBase,
|
|||
port[1]['lport_name']
|
||||
for port in ovn_nb_api.delete_lswitch_port.call_args_list]
|
||||
self.assertNotIn(
|
||||
'ovnmeta-%s' % self.net['network']['id'],
|
||||
ovn_const.OVN_METADATA_PREFIX + self.net['network']['id'],
|
||||
deleted_ports)
|
||||
self.assertEqual(
|
||||
2,
|
||||
|
|
Loading…
Reference in New Issue