Browse Source

[ovn]: Fix l3_plugin.add_router_interface to comply with RouterPluginBase

OVNL3RouterPlugin inherits from L3_NAT_dbonly_mixin, which inherits
from neutron.extensions.l3.RouterPluginBase

As maintenance task expects OVNL3RouterPlugin to behave as
RouterPluginBase, the add_router_interface should have the signature:

  add_router_interface(self, context, router_id, interface_info)

Note: With this change, the default behavior of OVNL3RouterPlugin's
_add_neutron_router_interface becomes idem-potent: multiple calls to add
the same interface will not fail. Because of that, the unit test
test_router_add_interface_dup_port no longer makes sense and is being
removed.

Closes-Bug: #1876148
Change-Id: I8010113b4d8c66ecbccf3126f322a8836d92e7ba
Signed-off-by: Flavio Fernandes <flaviof@redhat.com>
changes/85/726385/1
Flavio Fernandes 1 year ago
committed by Rodolfo Alonso Hernandez
parent
commit
86b5771896
  1. 2
      neutron/plugins/ml2/drivers/ovn/mech_driver/ovsdb/maintenance.py
  2. 9
      neutron/services/ovn_l3/plugin.py
  3. 32
      neutron/tests/unit/extensions/test_l3.py
  4. 3
      neutron/tests/unit/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_maintenance.py

2
neutron/plugins/ml2/drivers/ovn/mech_driver/ovsdb/maintenance.py

@ -398,7 +398,7 @@ class DBInconsistenciesPeriodics(SchemaAwarePeriodicsBase):
def _create_lrouter_port(self, context, port):
router_id = port['device_id']
self._ovn_client._l3_plugin.add_router_interface(
context, router_id, {'port_id': port['id']}, may_exist=True)
context, router_id, {'port_id': port['id']})
def _check_subnet_global_dhcp_opts(self):
inconsistent_subnets = []

9
neutron/services/ovn_l3/plugin.py

@ -159,14 +159,12 @@ class OVNL3RouterPlugin(service_base.ServicePluginBase,
context, {'router': original_router})
def _add_neutron_router_interface(self, context, router_id,
interface_info, may_exist=False):
interface_info):
try:
router_interface_info = (
super(OVNL3RouterPlugin, self).add_router_interface(
context, router_id, interface_info))
except n_exc.PortInUse:
if not may_exist:
raise
# NOTE(lucasagomes): If the port is already being used it means
# the interface has been created already, let's just fetch it from
# the database. Perhaps the code below should live in Neutron
@ -183,10 +181,9 @@ class OVNL3RouterPlugin(service_base.ServicePluginBase,
return router_interface_info
def add_router_interface(self, context, router_id, interface_info,
may_exist=False):
def add_router_interface(self, context, router_id, interface_info=None):
router_interface_info = self._add_neutron_router_interface(
context, router_id, interface_info, may_exist=may_exist)
context, router_id, interface_info)
try:
self._ovn_client.create_router_port(
context, router_id, router_interface_info)

32
neutron/tests/unit/extensions/test_l3.py

@ -1457,38 +1457,6 @@ class L3NatTestCaseBase(L3NatTestCaseMixin):
exc.HTTPBadRequest.code)
self.assertFalse(plugin.get_ports(context.get_admin_context()))
def test_router_add_interface_dup_port(self):
'''This tests that if multiple routers add one port as their
interfaces. Only the first router's interface would be added
to this port. All the later requests would return exceptions.
'''
with self.router() as r1, self.router() as r2, self.network() as n:
with self.subnet(network=n) as s:
with self.port(subnet=s) as p:
self._router_interface_action('add',
r1['router']['id'],
None,
p['port']['id'])
# mock out the sequential check
plugin = 'neutron.db.l3_db.L3_NAT_dbonly_mixin'
check_p = mock.patch(plugin + '._check_router_port',
port_id=p['port']['id'],
device_id=r2['router']['id'],
return_value=p['port'])
checkport = check_p.start()
# do regular checkport after first skip
checkport.side_effect = check_p.stop()
self._router_interface_action('add',
r2['router']['id'],
None,
p['port']['id'],
exc.HTTPConflict.code)
# clean-up
self._router_interface_action('remove',
r1['router']['id'],
None,
p['port']['id'])
def _assert_body_port_id_and_update_port(self, body, mock_update_port,
port_id, device_id):
self.assertNotIn('port_id', body)

3
neutron/tests/unit/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_maintenance.py

@ -276,8 +276,7 @@ class TestDBInconsistenciesPeriodics(testlib_api.SqlTestCaseLight,
self.periodic._create_lrouter_port(self.ctx, port)
l3_mock = self.periodic._ovn_client._l3_plugin
l3_mock.add_router_interface.assert_called_once_with(
self.ctx, port['device_id'], {'port_id': port['id']},
may_exist=True)
self.ctx, port['device_id'], {'port_id': port['id']})
@mock.patch.object(maintenance.LOG, 'debug')
def test__log_maintenance_inconsistencies(self, mock_log):

Loading…
Cancel
Save