[OVN] Add the physical network to the `Logical_Switch` register
Now the ``Logical_Switch`` register (that represents an OVN network), stored the physical in the "external_ids" field, if the network has it. If not, this field won't be present. Related-Bug: #2125553 Signed-off-by: Rodolfo Alonso Hernandez <ralonsoh@redhat.com> Change-Id: I4e7c78da3bc0367f7208477a4d84dd970c9d366c
This commit is contained in:
@@ -999,26 +999,32 @@ class DBInconsistenciesPeriodics(SchemaAwarePeriodicsBase):
|
||||
|
||||
raise periodics.NeverAgain()
|
||||
|
||||
# TODO(ralonsoh): Remove this method in the E+2 cycle (SLURP release)
|
||||
# TODO(ralonsoh): Remove this method in the G+4 cycle (SLURP release)
|
||||
@has_lock_periodic(
|
||||
periodic_run_limit=ovn_const.MAINTENANCE_TASK_RETRY_LIMIT,
|
||||
spacing=ovn_const.MAINTENANCE_ONE_RUN_TASK_SPACING,
|
||||
run_immediately=True)
|
||||
def set_network_type(self):
|
||||
"""Add the network type to the Logical_Switch registers"""
|
||||
def set_network_type_and_physnet(self):
|
||||
"""Add the network type and physnet to the Logical_Switch registers"""
|
||||
context = n_context.get_admin_context()
|
||||
net_segments = network_obj.NetworkSegment.get_objects(context)
|
||||
net_segments = {seg.network_id: seg.network_type
|
||||
for seg in net_segments}
|
||||
net_type = {seg.network_id: seg.network_type for seg in net_segments}
|
||||
net_physnet = {seg.network_id: seg.physical_network
|
||||
for seg in net_segments}
|
||||
cmds = []
|
||||
for ls in self._nb_idl.ls_list().execute(check_error=True):
|
||||
if ovn_const.OVN_NETWORK_NAME_EXT_ID_KEY not in ls.external_ids:
|
||||
continue
|
||||
|
||||
if ovn_const.OVN_NETTYPE_EXT_ID_KEY not in ls.external_ids:
|
||||
net_id = utils.get_neutron_name(ls.name)
|
||||
net_id = utils.get_neutron_name(ls.name)
|
||||
physnet = net_physnet[net_id]
|
||||
if (ovn_const.OVN_NETTYPE_EXT_ID_KEY not in ls.external_ids or
|
||||
(ovn_const.OVN_PHYSNET_EXT_ID_KEY not in ls.external_ids
|
||||
and physnet)):
|
||||
external_ids = {
|
||||
ovn_const.OVN_NETTYPE_EXT_ID_KEY: net_segments[net_id]}
|
||||
ovn_const.OVN_NETTYPE_EXT_ID_KEY: net_type[net_id]}
|
||||
if physnet:
|
||||
external_ids[ovn_const.OVN_PHYSNET_EXT_ID_KEY] = physnet
|
||||
cmds.append(self._nb_idl.db_set(
|
||||
'Logical_Switch', ls.uuid, ('external_ids', external_ids)))
|
||||
|
||||
|
||||
@@ -2117,6 +2117,8 @@ class OVNClient:
|
||||
# NOTE(twilson): in the case of multiple segments, or when all
|
||||
# segments are removed, NETWORK_TYPE=None, which is invalid ovsdb
|
||||
ovn_const.OVN_NETTYPE_EXT_ID_KEY: network.get(pnet.NETWORK_TYPE),
|
||||
ovn_const.OVN_PHYSNET_EXT_ID_KEY:
|
||||
network.get(pnet.PHYSICAL_NETWORK),
|
||||
}
|
||||
|
||||
# Enable IGMP snooping if igmp_snooping_enable is enabled in Neutron
|
||||
|
||||
@@ -1257,20 +1257,42 @@ class TestMaintenance(_TestMaintenanceHelper):
|
||||
lr = self.nb_api.lookup('Logical_Router', utils.ovn_name(router['id']))
|
||||
self.assertEqual([], lr.ports[0].gateway_chassis)
|
||||
|
||||
def test_set_network_type(self):
|
||||
def test_set_network_type_and_physnet(self):
|
||||
net1 = self._create_network(uuidutils.generate_uuid())
|
||||
ls_name = utils.ovn_name(net1['id'])
|
||||
self.nb_api.db_remove(
|
||||
'Logical_Switch', ls_name, 'external_ids',
|
||||
ovn_const.OVN_NETTYPE_EXT_ID_KEY).execute(check_error=True)
|
||||
ls = self.nb_api.lookup('Logical_Switch', ls_name)
|
||||
self.assertIsNone(ls.external_ids.get(
|
||||
ovn_const.OVN_NETTYPE_EXT_ID_KEY))
|
||||
net2 = self._create_network(uuidutils.generate_uuid(),
|
||||
provider='physnet1', net_type='vlan')
|
||||
ls1_name = utils.ovn_name(net1['id'])
|
||||
ls2_name = utils.ovn_name(net2['id'])
|
||||
for _ls_name in (ls1_name, ls2_name):
|
||||
self.nb_api.db_remove(
|
||||
'Logical_Switch', _ls_name, 'external_ids',
|
||||
ovn_const.OVN_NETTYPE_EXT_ID_KEY).execute(check_error=True)
|
||||
self.nb_api.db_remove(
|
||||
'Logical_Switch', _ls_name, 'external_ids',
|
||||
ovn_const.OVN_PHYSNET_EXT_ID_KEY).execute(check_error=True)
|
||||
ls = self.nb_api.lookup('Logical_Switch', _ls_name)
|
||||
self.assertIsNone(ls.external_ids.get(
|
||||
ovn_const.OVN_NETTYPE_EXT_ID_KEY))
|
||||
self.assertIsNone(ls.external_ids.get(
|
||||
ovn_const.OVN_PHYSNET_EXT_ID_KEY))
|
||||
|
||||
self.assertRaises(periodics.NeverAgain, self.maint.set_network_type)
|
||||
ls = self.nb_api.lookup('Logical_Switch', ls_name)
|
||||
self.assertEqual(net1[provnet_apidef.NETWORK_TYPE],
|
||||
ls.external_ids.get(ovn_const.OVN_NETTYPE_EXT_ID_KEY))
|
||||
self.assertRaises(periodics.NeverAgain,
|
||||
self.maint.set_network_type_and_physnet)
|
||||
ls1 = self.nb_api.lookup('Logical_Switch', ls1_name)
|
||||
self.assertEqual(
|
||||
net1[provnet_apidef.NETWORK_TYPE],
|
||||
ls1.external_ids.get(ovn_const.OVN_NETTYPE_EXT_ID_KEY))
|
||||
self.assertNotIn(
|
||||
ovn_const.OVN_PHYSNET_EXT_ID_KEY,
|
||||
ls1.external_ids.get)
|
||||
|
||||
ls2 = self.nb_api.lookup('Logical_Switch', ls2_name)
|
||||
self.assertEqual(
|
||||
net2[provnet_apidef.NETWORK_TYPE],
|
||||
ls2.external_ids.get(ovn_const.OVN_NETTYPE_EXT_ID_KEY))
|
||||
self.assertEqual(
|
||||
net2[provnet_apidef.PHYSICAL_NETWORK],
|
||||
ls2.external_ids.get(ovn_const.OVN_PHYSNET_EXT_ID_KEY))
|
||||
|
||||
def test_check_network_broadcast_arps_to_all_routers(self):
|
||||
net = self._create_network('net', external=True)
|
||||
|
||||
Reference in New Issue
Block a user