summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Prince <dan.prince@rackspace.com>2011-03-10 15:05:04 -0500
committerDan Prince <dan.prince@rackspace.com>2011-03-10 15:05:04 -0500
commit6b95c5133452ae26da2cb7f08267aa4cb056e7af (patch)
tree1e69a7b663351b3c1dfa5ed2776f023d2b807a1c
parentacbc0f597f6183fc856f82b07392ddd4a61393f7 (diff)
downloadnova-6b95c5133452ae26da2cb7f08267aa4cb056e7af.tar.gz
nova-6b95c5133452ae26da2cb7f08267aa4cb056e7af.tar.xz
nova-6b95c5133452ae26da2cb7f08267aa4cb056e7af.zip
Initial support fo extension resources. Tests.
-rw-r--r--nova/api/openstack/__init__.py8
-rw-r--r--nova/api/openstack/extensions.py29
-rw-r--r--nova/tests/api/openstack/test_extensions.py83
3 files changed, 119 insertions, 1 deletions
diff --git a/nova/api/openstack/__init__.py b/nova/api/openstack/__init__.py
index ab9dbb780..28e2a1691 100644
--- a/nova/api/openstack/__init__.py
+++ b/nova/api/openstack/__init__.py
@@ -30,6 +30,7 @@ from nova import wsgi
from nova.api.openstack import faults
from nova.api.openstack import backup_schedules
from nova.api.openstack import consoles
+from nova.api.openstack import extensions
from nova.api.openstack import flavors
from nova.api.openstack import images
from nova.api.openstack import servers
@@ -68,7 +69,7 @@ class APIRouter(wsgi.Router):
"""Simple paste factory, :class:`nova.wsgi.Router` doesn't have one"""
return cls()
- def __init__(self):
+ def __init__(self, ext_manager=None):
mapper = routes.Mapper()
server_members = {'action': 'POST'}
@@ -111,6 +112,11 @@ class APIRouter(wsgi.Router):
collection={'detail': 'GET'},
controller=shared_ip_groups.Controller())
+ if ext_manager is None:
+ ext_manager = extensions.ExtensionManager()
+ for resource in ext_manager.get_resources():
+ resource.add_routes(mapper)
+
super(APIRouter, self).__init__(mapper)
diff --git a/nova/api/openstack/extensions.py b/nova/api/openstack/extensions.py
new file mode 100644
index 000000000..1c539c500
--- /dev/null
+++ b/nova/api/openstack/extensions.py
@@ -0,0 +1,29 @@
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+# Copyright 2011 OpenStack LLC.
+# All Rights Reserved.
+#
+# 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.
+
+class ExtensionManager(object):
+
+ def get_resources(self):
+ """
+ returns a list of ExtensionResource objects
+ """
+ return []
+
+class ExtensionResource(object):
+
+ def add_routes(self, mapper):
+ pass
diff --git a/nova/tests/api/openstack/test_extensions.py b/nova/tests/api/openstack/test_extensions.py
new file mode 100644
index 000000000..f5332c84a
--- /dev/null
+++ b/nova/tests/api/openstack/test_extensions.py
@@ -0,0 +1,83 @@
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+# Copyright 2011 OpenStack LLC.
+# All Rights Reserved.
+#
+# 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 unittest
+
+import webob
+
+from nova.api import openstack
+import nova.wsgi
+
+class StubController(nova.wsgi.Controller):
+
+ def __init__(self, body):
+ self.body = body
+
+ def index(self, req):
+ return self.body
+
+class StubExtensionManager(object):
+
+ def __init__(self, resources):
+ self.resources = resources
+
+ def get_resources(self):
+ return self.resources
+
+class WidgetExtensionResource(object):
+
+ def __init__(self, name, collection, wsgi_app):
+ self.name = name
+ self.collection = collection
+ self.wsgi_app = wsgi_app
+
+ def add_routes(self, mapper):
+ mapper.resource(self.name, self.collection, controller=self.wsgi_app)
+
+class ExtensionTest(unittest.TestCase):
+
+ def test_no_extension_present(self):
+ manager = StubExtensionManager([])
+ router = openstack.APIRouter(manager)
+ request = webob.Request.blank("/widgets")
+ response = request.get_response(router)
+ self.assertEqual(404, response.status_int)
+
+ def test_get_resources(self):
+ response_body = "Buy more widgets!"
+ response = webob.Response()
+ response.body = response_body
+ resource1 = WidgetExtensionResource("widget", "widgets", response)
+ manager = StubExtensionManager([resource1])
+ router = openstack.APIRouter(manager)
+ request = webob.Request.blank("/widgets")
+ response = request.get_response(router)
+ self.assertEqual(200, response.status_int)
+ self.assertEqual(response_body, response.body)
+
+ def test_get_resources_with_controller(self):
+ response_body = "Buy more widgets!"
+ controller = StubController(response_body)
+ resource1 = WidgetExtensionResource("widget", "widgets", controller)
+ manager = StubExtensionManager([resource1])
+ router = openstack.APIRouter(manager)
+ request = webob.Request.blank("/widgets")
+ response = request.get_response(router)
+ self.assertEqual(200, response.status_int)
+ self.assertEqual(response_body, response.body)
+
+