diff options
| author | Chris Yeoh <cyeoh@au1.ibm.com> | 2013-05-18 12:48:44 +0930 |
|---|---|---|
| committer | Chris Yeoh <cyeoh@au1.ibm.com> | 2013-06-07 10:06:52 +0930 |
| commit | d5ae8d5667fee22ba4df4feea53224874a19d167 (patch) | |
| tree | 8e04a8005d8417460600b43518380854d6653946 /nova/tests | |
| parent | 8b632660aff27582c9b8ced3e0642399f3139f81 (diff) | |
Adds check that the core V3 API is loaded
Adds infrastructure to be able to check that the core V3 API
plugins are present and raise an exception and abort if any are missing. The
list is deliberately hard coded though it is not yet complete and
will be expanded as the core APIs are ported and it is decided
exactly what will be considered to be the core API.
Partially implements blueprint v3-api-extension-framework
Change-Id: Ic2c1d5cd6836ee18819106558880682cf4cda487
Diffstat (limited to 'nova/tests')
| -rw-r--r-- | nova/tests/api/openstack/compute/test_v3_extensions.py | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/nova/tests/api/openstack/compute/test_v3_extensions.py b/nova/tests/api/openstack/compute/test_v3_extensions.py index f7c1bf39c..97429ca45 100644 --- a/nova/tests/api/openstack/compute/test_v3_extensions.py +++ b/nova/tests/api/openstack/compute/test_v3_extensions.py @@ -15,9 +15,12 @@ # under the License. from oslo.config import cfg +import stevedore +from nova.api import openstack from nova.api.openstack import compute from nova.api.openstack.compute import plugins +from nova import exception from nova import test CONF = cfg.CONF @@ -28,8 +31,35 @@ class fake_bad_extension(object): alias = "fake-bad" +class fake_stevedore_enabled_extensions(object): + def __init__(self, namespace, check_func, invoke_on_load=False, + invoke_args=(), invoke_kwds={}): + self.extensions = [] + + def map(self, func, *args, **kwds): + pass + + def __iter__(self): + return iter(self.extensions) + + +class fake_loaded_extension_info(object): + def __init__(self): + self.extensions = {} + + def register_extension(self, ext): + self.extensions[ext] = ext + return True + + def get_extensions(self): + return {'core1': None, 'core2': None, 'noncore1': None} + + class ExtensionLoadingTestCase(test.TestCase): + def _set_v3_core(self, core_extensions): + openstack.API_V3_CORE_EXTENSIONS = core_extensions + def test_extensions_loaded(self): app = compute.APIRouterV3() self.assertIn('servers', app._loaded_extension_info.extensions) @@ -70,3 +100,42 @@ class ExtensionLoadingTestCase(test.TestCase): self.assertNotIn('os-fixed-ips', app._loaded_extension_info.extensions) self.assertIn('servers', app._loaded_extension_info.extensions) self.assertEqual(len(app._loaded_extension_info.extensions), 1) + + def test_get_missing_core_extensions(self): + v3_core = openstack.API_V3_CORE_EXTENSIONS + openstack.API_V3_CORE_EXTENSIONS = set(['core1', 'core2']) + self.addCleanup(self._set_v3_core, v3_core) + self.assertEqual(len(compute.APIRouterV3.get_missing_core_extensions( + ['core1', 'core2', 'noncore1'])), 0) + missing_core = compute.APIRouterV3.get_missing_core_extensions( + ['core1']) + self.assertEqual(len(missing_core), 1) + self.assertIn('core2', missing_core) + missing_core = compute.APIRouterV3.get_missing_core_extensions([]) + self.assertEqual(len(missing_core), 2) + self.assertIn('core1', missing_core) + self.assertIn('core2', missing_core) + missing_core = compute.APIRouterV3.get_missing_core_extensions( + ['noncore1']) + self.assertEqual(len(missing_core), 2) + self.assertIn('core1', missing_core) + self.assertIn('core2', missing_core) + + def test_core_extensions_present(self): + self.stubs.Set(stevedore.enabled, 'EnabledExtensionManager', + fake_stevedore_enabled_extensions) + self.stubs.Set(plugins, 'LoadedExtensionInfo', + fake_loaded_extension_info) + v3_core = openstack.API_V3_CORE_EXTENSIONS + openstack.API_V3_CORE_EXTENSIONS = set(['core1', 'core2']) + self.addCleanup(self._set_v3_core, v3_core) + # if no core API extensions are missing then an exception will + # not be raised when creating an instance of compute.APIRouterV3 + _ = compute.APIRouterV3() + + def test_core_extensions_missing(self): + self.stubs.Set(stevedore.enabled, 'EnabledExtensionManager', + fake_stevedore_enabled_extensions) + self.stubs.Set(plugins, 'LoadedExtensionInfo', + fake_loaded_extension_info) + self.assertRaises(exception.CoreAPIMissing, compute.APIRouterV3) |
