Change definition of API_EXTENSION_NAMESPACE to method

Moves definition of API_EXTENSION_NAMESPACE to a method so we can
mock it for unittests. This will allow us to do much better
unittesting for the API framework including the new microversion
features. It will also allow us to cleanup other framework type
tests which currently rely on real plugins.

Partially implements blueprint api-microversions

Change-Id: I093e15483fc84d823c09c84a218e5eb14f1de607
This commit is contained in:
Chris Yeoh
2014-11-21 17:48:02 +10:30
committed by Michael Still
parent b81de68d05
commit 9d311d1545
5 changed files with 90 additions and 5 deletions

View File

@@ -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})

View File

@@ -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'])

View File

@@ -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 []

View File

@@ -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