Browse Source

Merge "[OVN] Allow use of ovn-sync mechanism driver" into stable/ussuri

tags/16.1.0
Zuul 2 months ago
committed by Gerrit Code Review
parent
commit
02d4eb001f
3 changed files with 51 additions and 1 deletions
  1. +21
    -0
      neutron/services/ovn_l3/exceptions.py
  2. +13
    -1
      neutron/services/ovn_l3/plugin.py
  3. +17
    -0
      neutron/tests/unit/services/ovn_l3/test_plugin.py

+ 21
- 0
neutron/services/ovn_l3/exceptions.py View File

@@ -0,0 +1,21 @@
# Copyright 2020 Canonical Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

from neutron._i18n import _
from neutron_lib import exceptions as n_exc


class MechanismDriverNotFound(n_exc.NotFound):
message = _("None of the supported mechanism drivers found: "
"%(mechanism_drivers)s. Check your configuration.")

+ 13
- 1
neutron/services/ovn_l3/plugin.py View File

@@ -42,6 +42,8 @@ from neutron.db import ovn_revision_numbers_db as db_rev
from neutron.plugins.ml2.drivers.ovn.mech_driver.ovsdb import ovn_client
from neutron.scheduler import l3_ovn_scheduler

from neutron.services.ovn_l3 import exceptions as ovn_l3_exc


LOG = log.getLogger(__name__)

@@ -108,7 +110,17 @@ class OVNL3RouterPlugin(service_base.ServicePluginBase,
@property
def _plugin_driver(self):
if self._mech is None:
self._mech = self._plugin.mechanism_manager.mech_drivers['ovn'].obj
drivers = ('ovn', 'ovn-sync')
for driver in drivers:
try:
self._mech = self._plugin.mechanism_manager.mech_drivers[
driver].obj
break
except KeyError:
pass
else:
raise ovn_l3_exc.MechanismDriverNotFound(
mechanism_drivers=drivers)
return self._mech

def get_plugin_type(self):


+ 17
- 0
neutron/tests/unit/services/ovn_l3/test_plugin.py View File

@@ -286,6 +286,23 @@ class TestOVNL3RouterPlugin(test_mech_driver.Ml2PluginV2TestCase):
return_value=False)
self.mock_is_lb_member_fip.start()

def test__plugin_driver(self):
# No valid mech drivers should raise an exception.
self._mechanism_drivers = None
self.l3_inst._plugin.mechanism_manager.mech_drivers = {}
self.l3_inst._mech = None
self.assertRaises(n_exc.NotFound, lambda: self.l3_inst._plugin_driver)
# Populate the mechanism driver map with keys the code under test looks
# for and validate it finds them.
fake_mech_driver = mock.MagicMock()
for driver in ('ovn', 'ovn-sync'):
self.l3_inst._plugin.mechanism_manager.mech_drivers[
driver] = fake_mech_driver
result = self.l3_inst._plugin_driver
self.l3_inst._plugin.mechanism_manager.mech_drivers.pop(
driver, None)
self.assertEqual(fake_mech_driver.obj, result)

@mock.patch('neutron.db.l3_db.L3_NAT_dbonly_mixin.add_router_interface')
def test_add_router_interface(self, func):
router_id = 'router-id'


Loading…
Cancel
Save