Add localport const and refactor

Change-Id: Ice4b108d3eb9945798bf3f91be9672cff29f3295
This commit is contained in:
Kamil Sambor 2021-06-15 16:54:07 +02:00
parent ca3ec4133b
commit 39bc84cfb2
9 changed files with 15 additions and 11 deletions

View File

@ -272,6 +272,7 @@ PORT_SECURITYGROUPS = 'security_groups'
LSP_TYPE_LOCALNET = 'localnet'
LSP_TYPE_VIRTUAL = 'virtual'
LSP_TYPE_EXTERNAL = 'external'
LSP_TYPE_LOCALPORT = 'localport'
LSP_OPTIONS_VIRTUAL_PARENTS_KEY = 'virtual-parents'
LSP_OPTIONS_VIRTUAL_IP_KEY = 'virtual-ip'
LSP_OPTIONS_MCAST_FLOOD_REPORTS = 'mcast_flood_reports'

View File

@ -879,7 +879,7 @@ class OvsdbSbOvnIdl(sb_impl_idl.OvnSbApiIdlImpl, Backend):
except idlutils.RowNotFound:
return None
cmd = self.db_find_rows('Port_Binding', ('datapath', '=', dp),
('type', '=', 'localport'))
('type', '=', ovn_const.LSP_TYPE_LOCALPORT))
return next(iter(cmd.execute(check_error=True)), None)
def set_chassis_neutron_description(self, chassis, description,

View File

@ -673,7 +673,7 @@ class DBInconsistenciesPeriodics(SchemaAwarePeriodicsBase):
cmds = []
for port in self._nb_idl.lsp_list().execute(check_error=True):
port_type = port.type.strip()
if port_type in ("vtep", "localport", "router"):
if port_type in ("vtep", ovn_const.LSP_TYPE_LOCALPORT, "router"):
continue
options = port.options

View File

@ -263,7 +263,7 @@ class OVNClient(object):
const.DEVICE_OWNER_DISTRIBUTED,
const.DEVICE_OWNER_DHCP] and
not utils.is_neutron_dhcp_agent_port(port)):
port_type = 'localport'
port_type = ovn_const.LSP_TYPE_LOCALPORT
if utils.is_port_external(port):
if self.is_external_ports_supported():
@ -306,7 +306,7 @@ class OVNClient(object):
# and will be ignored when mcast_snoop is False. We can revise
# this once https://bugzilla.redhat.com/show_bug.cgi?id=1933990
# (see comment #3) is fixed in Core OVN.
if port_type not in ('vtep', 'localport', 'router'):
if port_type not in ('vtep', ovn_const.LSP_TYPE_LOCALPORT, 'router'):
options.update({ovn_const.LSP_OPTIONS_MCAST_FLOOD_REPORTS: 'true'})
device_owner = port.get('device_owner', '')

View File

@ -131,7 +131,7 @@ class TestMetadataAgent(base.TestOVNFunctionalBase):
self.nb_api.lsp_add(
lswitch_name,
mdt_port_name,
type='localport',
type=ovn_const.LSP_TYPE_LOCALPORT,
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'}))

View File

@ -99,7 +99,8 @@ class TestSbApi(BaseOvnIdlTest):
self.assertGreaterEqual(set(mapping.keys()),
{c['name'] for c in self.data['chassis']})
def _add_switch_port(self, chassis_name, type='localport'):
def _add_switch_port(self, chassis_name,
type=ovn_const.LSP_TYPE_LOCALPORT):
sname, pname = (utils.get_rand_device_name(prefix=p)
for p in ('switch', 'port'))
chassis = self.api.lookup('Chassis', chassis_name)

View File

@ -963,7 +963,7 @@ class TestOvnNbSync(base.TestOVNFunctionalBase):
_plugin_nb_ovn = self.mech_driver._nb_ovn
plugin_metadata_ports = [row.name for row in (
_plugin_nb_ovn._tables['Logical_Switch_Port'].rows.values())
if row.type == 'localport']
if row.type == ovn_const.LSP_TYPE_LOCALPORT]
if should_match:
# Check that metadata ports exist in both Neutron and OVN dbs.
@ -1481,7 +1481,7 @@ class TestOvnNbSync(base.TestOVNFunctionalBase):
_plugin_nb_ovn = self.mech_driver._nb_ovn
plugin_metadata_ports = [row.name for row in (
_plugin_nb_ovn._tables['Logical_Switch_Port'].rows.values())
if row.type == 'localport']
if row.type == ovn_const.LSP_TYPE_LOCALPORT]
with self.nb_api.transaction(check_error=True) as txn:
for port in plugin_metadata_ports:

View File

@ -421,7 +421,7 @@ class TestDBInconsistenciesPeriodics(testlib_api.SqlTestCaseLight,
'type': "vtep"})
lsp3 = fakes.FakeOvsdbRow.create_one_ovsdb_row(
attrs={'name': 'lsp3', 'options': {},
'type': "localport"})
'type': constants.LSP_TYPE_LOCALPORT})
lsp4 = fakes.FakeOvsdbRow.create_one_ovsdb_row(
attrs={'name': 'lsp4', 'options': {},
'type': "router"})

View File

@ -3292,7 +3292,8 @@ class TestOVNMechanismDriverMetadataPort(test_plugin.Ml2PluginV2TestCase):
with self.network():
self.assertEqual(1, self.nb_ovn.create_lswitch_port.call_count)
args, kwargs = self.nb_ovn.create_lswitch_port.call_args
self.assertEqual('localport', kwargs['type'])
self.assertEqual(ovn_const.LSP_TYPE_LOCALPORT,
kwargs['type'])
def test_metadata_port_not_created_if_exists(self):
"""Check that metadata port is not created if it already exists.
@ -3325,7 +3326,8 @@ class TestOVNMechanismDriverMetadataPort(test_plugin.Ml2PluginV2TestCase):
self.assertEqual(
2, self.nb_ovn.set_lswitch_port.call_count)
args, kwargs = self.nb_ovn.set_lswitch_port.call_args
self.assertEqual('localport', kwargs['type'])
self.assertEqual(ovn_const.LSP_TYPE_LOCALPORT,
kwargs['type'])
self.assertEqual('10.0.0.2/24 20.0.0.2/24',
kwargs['external_ids'].get(
ovn_const.OVN_CIDRS_EXT_ID_KEY,