[OVN][Cosmetic] Improve gen_router_port_options

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 <egarciar@redhat.com>
Change-Id: I679bbb5aa59d0a71d14bd5540d33eada53054b18
This commit is contained in:
Elvira García 2022-02-23 17:54:36 +01:00
parent b2421b01e5
commit a51aff743c
2 changed files with 8 additions and 6 deletions

View File

@ -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):

View File

@ -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}