From 39bc84cfb2113d6cf5bb9e19f7a97ce45302fb02 Mon Sep 17 00:00:00 2001 From: Kamil Sambor Date: Tue, 15 Jun 2021 16:54:07 +0200 Subject: [PATCH] Add localport const and refactor Change-Id: Ice4b108d3eb9945798bf3f91be9672cff29f3295 --- neutron/common/ovn/constants.py | 1 + .../ml2/drivers/ovn/mech_driver/ovsdb/impl_idl_ovn.py | 2 +- .../ml2/drivers/ovn/mech_driver/ovsdb/maintenance.py | 2 +- .../plugins/ml2/drivers/ovn/mech_driver/ovsdb/ovn_client.py | 4 ++-- .../functional/agent/ovn/metadata/test_metadata_agent.py | 2 +- .../ml2/drivers/ovn/mech_driver/ovsdb/test_impl_idl.py | 3 ++- .../ml2/drivers/ovn/mech_driver/ovsdb/test_ovn_db_sync.py | 4 ++-- .../ml2/drivers/ovn/mech_driver/ovsdb/test_maintenance.py | 2 +- .../plugins/ml2/drivers/ovn/mech_driver/test_mech_driver.py | 6 ++++-- 9 files changed, 15 insertions(+), 11 deletions(-) diff --git a/neutron/common/ovn/constants.py b/neutron/common/ovn/constants.py index 4ad1845eeb2..5c9424c5035 100644 --- a/neutron/common/ovn/constants.py +++ b/neutron/common/ovn/constants.py @@ -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' diff --git a/neutron/plugins/ml2/drivers/ovn/mech_driver/ovsdb/impl_idl_ovn.py b/neutron/plugins/ml2/drivers/ovn/mech_driver/ovsdb/impl_idl_ovn.py index 91373e0b468..f9d2b97aa23 100644 --- a/neutron/plugins/ml2/drivers/ovn/mech_driver/ovsdb/impl_idl_ovn.py +++ b/neutron/plugins/ml2/drivers/ovn/mech_driver/ovsdb/impl_idl_ovn.py @@ -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, diff --git a/neutron/plugins/ml2/drivers/ovn/mech_driver/ovsdb/maintenance.py b/neutron/plugins/ml2/drivers/ovn/mech_driver/ovsdb/maintenance.py index d0c0c0fab78..7aea6ad1131 100644 --- a/neutron/plugins/ml2/drivers/ovn/mech_driver/ovsdb/maintenance.py +++ b/neutron/plugins/ml2/drivers/ovn/mech_driver/ovsdb/maintenance.py @@ -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 diff --git a/neutron/plugins/ml2/drivers/ovn/mech_driver/ovsdb/ovn_client.py b/neutron/plugins/ml2/drivers/ovn/mech_driver/ovsdb/ovn_client.py index 608d4b24021..1ccbad4d9c3 100644 --- a/neutron/plugins/ml2/drivers/ovn/mech_driver/ovsdb/ovn_client.py +++ b/neutron/plugins/ml2/drivers/ovn/mech_driver/ovsdb/ovn_client.py @@ -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', '') diff --git a/neutron/tests/functional/agent/ovn/metadata/test_metadata_agent.py b/neutron/tests/functional/agent/ovn/metadata/test_metadata_agent.py index a2483aa1cd8..9e50f9a11dc 100644 --- a/neutron/tests/functional/agent/ovn/metadata/test_metadata_agent.py +++ b/neutron/tests/functional/agent/ovn/metadata/test_metadata_agent.py @@ -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'})) diff --git a/neutron/tests/functional/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_impl_idl.py b/neutron/tests/functional/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_impl_idl.py index b6845760fc5..3ca442048e7 100644 --- a/neutron/tests/functional/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_impl_idl.py +++ b/neutron/tests/functional/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_impl_idl.py @@ -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) diff --git a/neutron/tests/functional/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_ovn_db_sync.py b/neutron/tests/functional/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_ovn_db_sync.py index 216f29fc93a..1355ca86da8 100644 --- a/neutron/tests/functional/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_ovn_db_sync.py +++ b/neutron/tests/functional/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_ovn_db_sync.py @@ -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: diff --git a/neutron/tests/unit/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_maintenance.py b/neutron/tests/unit/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_maintenance.py index 82180c591f3..ffdfe354bd2 100644 --- a/neutron/tests/unit/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_maintenance.py +++ b/neutron/tests/unit/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_maintenance.py @@ -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"}) diff --git a/neutron/tests/unit/plugins/ml2/drivers/ovn/mech_driver/test_mech_driver.py b/neutron/tests/unit/plugins/ml2/drivers/ovn/mech_driver/test_mech_driver.py index 5d9093a40b3..004e93c8338 100644 --- a/neutron/tests/unit/plugins/ml2/drivers/ovn/mech_driver/test_mech_driver.py +++ b/neutron/tests/unit/plugins/ml2/drivers/ovn/mech_driver/test_mech_driver.py @@ -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,