From bb36650f87dd4b30e9ebbbb4409444b4482338b5 Mon Sep 17 00:00:00 2001 From: Chris Yeoh Date: Fri, 17 May 2013 16:53:37 +0930 Subject: Adds ability to black/whitelist v3 API extensions Adds a config option which will blacklist specific v3 API extensions from being loaded even if they are detected. Adds a config option which if the list is not empty will stop any v3 API extension from being loaded unless it is in the whitelist. No filtering occurs if the whitelist is empty Creates a config option group osapi_v3 to hold the two new options and osapi_v3_enabled renamed to just enabled within the new group Partially implements blueprint v3-api-extension-framework Change-Id: Iec7fdb073b933791b0110dae485538c9080f2670 --- .../api/openstack/compute/test_v3_extensions.py | 72 ++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 nova/tests/api/openstack/compute/test_v3_extensions.py (limited to 'nova/tests') diff --git a/nova/tests/api/openstack/compute/test_v3_extensions.py b/nova/tests/api/openstack/compute/test_v3_extensions.py new file mode 100644 index 000000000..f7c1bf39c --- /dev/null +++ b/nova/tests/api/openstack/compute/test_v3_extensions.py @@ -0,0 +1,72 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2013 IBM Corp. +# +# 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 oslo.config import cfg + +from nova.api.openstack import compute +from nova.api.openstack.compute import plugins +from nova import test + +CONF = cfg.CONF + + +class fake_bad_extension(object): + name = "fake_bad_extension" + alias = "fake-bad" + + +class ExtensionLoadingTestCase(test.TestCase): + + def test_extensions_loaded(self): + app = compute.APIRouterV3() + self.assertIn('servers', app._loaded_extension_info.extensions) + + def test_check_bad_extension(self): + extension_info = plugins.LoadedExtensionInfo() + self.assertFalse(extension_info._check_extension(fake_bad_extension)) + + def test_extensions_blacklist(self): + app = compute.APIRouterV3() + self.assertIn('os-fixed-ips', app._loaded_extension_info.extensions) + CONF.set_override('extensions_blacklist', 'os-fixed-ips', 'osapi_v3') + app = compute.APIRouterV3() + self.assertNotIn('os-fixed-ips', app._loaded_extension_info.extensions) + + def test_extensions_whitelist_accept(self): + app = compute.APIRouterV3() + self.assertIn('os-fixed-ips', app._loaded_extension_info.extensions) + CONF.set_override('extensions_whitelist', 'servers,os-fixed-ips', + 'osapi_v3') + app = compute.APIRouterV3() + self.assertIn('os-fixed-ips', app._loaded_extension_info.extensions) + + def test_extensions_whitelist_block(self): + app = compute.APIRouterV3() + self.assertIn('os-fixed-ips', app._loaded_extension_info.extensions) + CONF.set_override('extensions_whitelist', 'servers', 'osapi_v3') + app = compute.APIRouterV3() + self.assertNotIn('os-fixed-ips', app._loaded_extension_info.extensions) + + def test_blacklist_overrides_whitelist(self): + app = compute.APIRouterV3() + self.assertIn('os-fixed-ips', app._loaded_extension_info.extensions) + CONF.set_override('extensions_whitelist', 'servers,os-fixed-ips', + 'osapi_v3') + CONF.set_override('extensions_blacklist', 'os-fixed-ips', 'osapi_v3') + app = compute.APIRouterV3() + 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) -- cgit