Add test cases for Invalid exception type

Partially-Implements: blueprint multi-l3-backends
Closes-Bug: #1612183

Change-Id: I76ab8b3a99d4459a24a8e43223e0c13654395216
This commit is contained in:
gong yong sheng 2016-08-11 18:37:56 +08:00
parent 89cf28e3dc
commit 78554d9b35
2 changed files with 27 additions and 1 deletions

View File

@ -37,7 +37,7 @@ MANDATORY = _FeatureFlag(supports=True, requires=True)
class L3ServiceProvider(object): class L3ServiceProvider(object):
"""Base class for L3 service providers. """Base class for L3 service provider drivers.
On __init__ this will be given a handle to the l3 plugin. It is then the On __init__ this will be given a handle to the l3 plugin. It is then the
responsibility of the driver to subscribe to the events it is interested responsibility of the driver to subscribe to the events it is interested

View File

@ -15,12 +15,15 @@
import mock import mock
from mock import patch from mock import patch
from neutron_lib import constants from neutron_lib import constants
from neutron_lib import exceptions as lib_exc
import testtools import testtools
from neutron import context from neutron import context
from neutron import manager from neutron import manager
from neutron.plugins.common import constants as p_cons from neutron.plugins.common import constants as p_cons
from neutron.services.l3_router.service_providers import driver_controller from neutron.services.l3_router.service_providers import driver_controller
from neutron.services import provider_configuration
from neutron.tests import base
from neutron.tests.unit import testlib_api from neutron.tests.unit import testlib_api
@ -50,6 +53,20 @@ class TestDriverController(testlib_api.SqlTestCase):
self.dc._get_provider_for_router(self.ctx, self.dc._get_provider_for_router(self.ctx,
'router_id')) 'router_id'))
def test__update_router_provider_invalid(self):
test_dc = driver_controller.DriverController(self.fake_l3)
with mock.patch.object(test_dc, "_get_provider_for_router"):
with mock.patch.object(
driver_controller,
"_ensure_driver_supports_request") as _ensure:
_ensure.side_effect = lib_exc.Invalid(message='message')
self.assertRaises(
lib_exc.Invalid,
test_dc._update_router_provider,
None, None, None, None,
None, {'name': 'testname'},
{'flavor_id': 'old_fid'}, None)
def test__set_router_provider_attr_lookups(self): def test__set_router_provider_attr_lookups(self):
# ensure correct drivers are looked up based on attrs # ensure correct drivers are looked up based on attrs
cases = [ cases = [
@ -100,3 +117,12 @@ class TestDriverController(testlib_api.SqlTestCase):
_fake_flavor_plugin} _fake_flavor_plugin}
_dc = driver_controller.DriverController(self.fake_l3) _dc = driver_controller.DriverController(self.fake_l3)
self.assertEqual(_fake_flavor_plugin, _dc._flavor_plugin) self.assertEqual(_fake_flavor_plugin, _dc._flavor_plugin)
class Test_LegacyPlusProviderConfiguration(base.BaseTestCase):
@mock.patch.object(provider_configuration.ProviderConfiguration,
"add_provider")
def test__update_router_provider_invalid(self, mock_method):
mock_method.side_effect = lib_exc.Invalid(message='message')
driver_controller._LegacyPlusProviderConfiguration()