From a51aff743c4659347f39efa1fd36ed883a37766f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elvira=20Garc=C3=ADa?= Date: Wed, 23 Feb 2022 17:54:36 +0100 Subject: [PATCH] [OVN][Cosmetic] Improve gen_router_port_options MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The gen_router_port_options now has a try/catch operation that could be better formulated as jlibosva stated in a comment in https://review.opendev.org/c/openstack/neutron/+/830509 Related-Bug: #1961967 Signed-off-by: Elvira GarcĂ­a Change-Id: I679bbb5aa59d0a71d14bd5540d33eada53054b18 --- .../ml2/drivers/ovn/mech_driver/ovsdb/ovn_client.py | 12 +++++++----- neutron/tests/unit/services/ovn_l3/test_plugin.py | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) 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 815e342a142..8b7f17251dd 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 @@ -1492,17 +1492,19 @@ class OVNClient(object): 'device_owner') if is_gw_port and ovn_conf.is_ovn_emit_need_to_frag_enabled(): try: - network_ids = set([port['network_id'] for port in - self._get_router_ports(admin_context, port['device_id'])]) + router_ports = self._get_router_ports(admin_context, + port['device_id']) + except l3_exc.RouterNotFound: + # Don't add any mtu info if the router no longer exists + LOG.debug("Router %s not found", port['device_id']) + else: + network_ids = {port['network_id'] for port in router_ports} for net in self._plugin.get_networks(admin_context, filters={'id': network_ids}): if net['mtu'] > network['mtu']: options[ovn_const.OVN_ROUTER_PORT_GW_MTU_OPTION] = str( network['mtu']) break - except l3_exc.RouterNotFound: - # Don't add any mtu info if the router no longer exists - pass return options def _create_lrouter_port(self, context, router, port, txn=None): diff --git a/neutron/tests/unit/services/ovn_l3/test_plugin.py b/neutron/tests/unit/services/ovn_l3/test_plugin.py index c4c12f081dd..448a5219dd4 100644 --- a/neutron/tests/unit/services/ovn_l3/test_plugin.py +++ b/neutron/tests/unit/services/ovn_l3/test_plugin.py @@ -1634,7 +1634,7 @@ class TestOVNL3RouterPlugin(test_mech_driver.Ml2PluginV2TestCase): 'network_id': 'priv-net'} ari.return_value = self.fake_router_interface_info # If we remove the router halfway the return value of - # _get_routers_ports will be [] + # _get_routers_ports will be RouterNotFound grps.side_effect = l3_exc.RouterNotFound(router_id=router_id) self.get_router.return_value = self.fake_router_with_ext_gw network_attrs = {'id': 'prov-net', 'mtu': 1200}