Skip to content

Commit

Permalink
Using plain routes for the microversions test
Browse files Browse the repository at this point in the history
Few microversions unittest still depend on the stevedore to load few
fake controller. This patch uses the plain routes to instead of stevedore.

For the unittest can injects routes which are used for test, the `custom_routes`
parameter is added to the APIRouterV21.

Partial-implement-blueprint api-no-more-extensions-pike

Change-Id: I1a7c653ab21be41b1a41f748a35ec9a57dd8b15d
  • Loading branch information
soulxu committed Jul 23, 2017
1 parent c11e9c4 commit d8928e4
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 124 deletions.
11 changes: 9 additions & 2 deletions nova/api/openstack/compute/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -877,11 +877,18 @@ class APIRouterV21(nova.api.openstack.APIRouterV21):
and method. The URL mapping based on the plain list `ROUTE_LIST` is built
at here. The stevedore based API loading will be replaced by this.
"""
def __init__(self):
def __init__(self, custom_routes=None):
""":param custom_routes: the additional routes can be added by this
parameter. This parameter is used to test on some fake routes
primarily.
"""
self._loaded_extension_info = extension_info.LoadedExtensionInfo()
super(APIRouterV21, self).__init__()

for path, methods in ROUTE_LIST:
if custom_routes is None:
custom_routes = tuple()

for path, methods in ROUTE_LIST + custom_routes:
# NOTE(alex_xu): The variable 'methods' is a dict in normal, since
# the dict includes all the methods supported in the path. But
# if the variable 'method' is a string, it means a redirection.
Expand Down
82 changes: 50 additions & 32 deletions nova/tests/unit/api/openstack/compute/microversions.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,15 @@
# under the License.

"""Microversions Test Extension"""
import functools

import webob

from nova.api.openstack import extensions
from nova.api.openstack.compute import routes
from nova.api.openstack import wsgi
from nova.api import validation
from nova.tests.unit.api.openstack.compute import dummy_schema

ALIAS = 'test-microversions'


class MicroversionsController(wsgi.Controller):

Expand Down Expand Up @@ -124,32 +123,51 @@ def show(self, req, resp_obj, id):
resp_obj.obj['extend_ctrlr3'] = 'val_3'


class Microversions(extensions.V21APIExtensionBase):
"""Basic Microversions Extension."""

name = "Microversions"
alias = ALIAS
version = 1

def get_resources(self):
res1 = extensions.ResourceExtension('microversions',
MicroversionsController())
res2 = extensions.ResourceExtension('microversions2',
MicroversionsController2())
res3 = extensions.ResourceExtension('microversions3',
MicroversionsController3(),
member_actions={"action": "POST"})
res4 = extensions.ResourceExtension('microversions4',
MicroversionsController4())
res5 = extensions.ResourceExtension(
'microversions5', MicroversionsExtendsBaseController())
return [res1, res2, res3, res4, res5]

def get_controller_extensions(self):
extension1 = extensions.ControllerExtension(
self, 'microversions5', MicroversionsExtendsController1())
extension2 = extensions.ControllerExtension(
self, 'microversions5', MicroversionsExtendsController2())
extension3 = extensions.ControllerExtension(
self, 'microversions5', MicroversionsExtendsController3())
return [extension1, extension2, extension3]
mv_controller = functools.partial(routes._create_controller,
MicroversionsController, [], [])


mv2_controller = functools.partial(routes._create_controller,
MicroversionsController2, [], [])


mv3_controller = functools.partial(routes._create_controller,
MicroversionsController3, [], [])


mv4_controller = functools.partial(routes._create_controller,
MicroversionsController4, [], [])


mv5_controller = functools.partial(routes._create_controller,
MicroversionsExtendsBaseController,
[
MicroversionsExtendsController1,
MicroversionsExtendsController2,
MicroversionsExtendsController3
], [])


ROUTES = (
('/microversions', {
'GET': [mv_controller, 'index']
}),
('/microversions2', {
'GET': [mv2_controller, 'index']
}),
('/microversions3', {
'POST': [mv3_controller, 'create']
}),
('/microversions3/{id}', {
'PUT': [mv3_controller, 'update']
}),
('/microversions3/{id}/action', {
'POST': [mv3_controller, 'action']
}),
('/microversions4', {
'POST': [mv4_controller, 'create']
}),
('/microversions5/{id}', {
'GET': [mv5_controller, 'show']
}),
)
Loading

0 comments on commit d8928e4

Please sign in to comment.