diff --git a/nova/api/openstack/__init__.py b/nova/api/openstack/__init__.py index c16140a542..2fe8a6a35d 100644 --- a/nova/api/openstack/__init__.py +++ b/nova/api/openstack/__init__.py @@ -255,15 +255,17 @@ class APIRouterV21(base_wsgi.Router): and method. """ - # TODO(oomichi): This namespace will be changed after moving all v3 APIs - # to v2.1. - API_EXTENSION_NAMESPACE = 'nova.api.v3.extensions' - @classmethod def factory(cls, global_config, **local_config): """Simple paste factory, :class:`nova.wsgi.Router` doesn't have one.""" return cls() + @staticmethod + def api_extension_namespace(): + # TODO(oomichi): This namespaces will be changed after moving all v3 + # APIs to v2.1. + return 'nova.api.v3.extensions' + def __init__(self, init_only=None, v3mode=False): # TODO(cyeoh): bp v3-api-extension-framework. Currently load # all extensions but eventually should be able to exclude @@ -313,7 +315,7 @@ class APIRouterV21(base_wsgi.Router): list(in_blacklist_and_whitelist)) self.api_extension_manager = stevedore.enabled.EnabledExtensionManager( - namespace=self.API_EXTENSION_NAMESPACE, + namespace=self.api_extension_namespace(), check_func=_check_load_extension, invoke_on_load=True, invoke_kwds={"extension_info": self.loaded_extension_info}) diff --git a/nova/tests/unit/api/openstack/compute/test_plugin_framework.py b/nova/tests/unit/api/openstack/compute/test_plugin_framework.py new file mode 100644 index 0000000000..5b4ce6fa5d --- /dev/null +++ b/nova/tests/unit/api/openstack/compute/test_plugin_framework.py @@ -0,0 +1,36 @@ +# Copyright 2014 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. + +import mock +from oslo.config import cfg +from oslo.serialization import jsonutils + +from nova import test +from nova.tests.unit.api.openstack import fakes + +CONF = cfg.CONF + + +class PluginTest(test.NoDBTestCase): + + @mock.patch("nova.api.openstack.APIRouterV21.api_extension_namespace") + def test_plugin_framework_index(self, mock_namespace): + mock_namespace.return_value = 'nova.api.v3.test_extensions' + + app = fakes.wsgi_app_v21(init_only='test-basic') + req = fakes.HTTPRequest.blank('/v2/fake/test') + res = req.get_response(app) + self.assertEqual(200, res.status_int) + resp_json = jsonutils.loads(res.body) + self.assertEqual('val', resp_json['param']) diff --git a/nova/tests/unit/api/openstack/compute/test_plugins/__init__.py b/nova/tests/unit/api/openstack/compute/test_plugins/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/nova/tests/unit/api/openstack/compute/test_plugins/basic.py b/nova/tests/unit/api/openstack/compute/test_plugins/basic.py new file mode 100644 index 0000000000..abad891b06 --- /dev/null +++ b/nova/tests/unit/api/openstack/compute/test_plugins/basic.py @@ -0,0 +1,43 @@ +# Copyright 2014 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. + +"""Basic Test Extension""" + +from nova.api.openstack import extensions +from nova.api.openstack import wsgi + + +ALIAS = 'test-basic' + + +class BasicController(wsgi.Controller): + + def index(self, req): + data = {'param': 'val'} + return data + + +class Basic(extensions.V3APIExtensionBase): + """Basic Test Extension.""" + + name = "BasicTest" + alias = ALIAS + version = 1 + + def get_resources(self): + resource = extensions.ResourceExtension('test', BasicController()) + return [resource] + + def get_controller_extensions(self): + return [] diff --git a/setup.cfg b/setup.cfg index 8d679b5fa7..4b152149fa 100644 --- a/setup.cfg +++ b/setup.cfg @@ -158,6 +158,10 @@ nova.api.v3.extensions.server.update = nova.api.v3.extensions.server.resize = disk_config = nova.api.openstack.compute.plugins.v3.disk_config:DiskConfig +nova.api.v3.test_extensions = + basic = nova.tests.unit.api.openstack.compute.test_plugins.basic:Basic + + # These are for backwards compat with Havana notification_driver configuration values oslo.messaging.notify.drivers = nova.openstack.common.notifier.log_notifier = oslo.messaging.notify._impl_log:LogDriver