Merge lp:~bcwaldon/nova/osapi-versions-links into lp:~hudson-openstack/nova/trunk

Proposed by Brian Waldon
Status: Superseded
Proposed branch: lp:~bcwaldon/nova/osapi-versions-links
Merge into: lp:~hudson-openstack/nova/trunk
Prerequisite: lp:~rackspace-titan/nova/openstack-api-version-split
Diff against target: 244 lines (+176/-20)
6 files modified
etc/api-paste.ini (+1/-1)
nova/api/openstack/__init__.py (+0/-18)
nova/api/openstack/versions.py (+55/-0)
nova/api/openstack/views/versions.py (+57/-0)
nova/tests/api/openstack/fakes.py (+2/-1)
nova/tests/api/openstack/test_versions.py (+61/-0)
To merge this branch: bzr merge lp:~bcwaldon/nova/osapi-versions-links
Reviewer Review Type Date Requested Status
Mark Washenberger (community) Approve
Nova Core security contacts Pending
Review via email: mp+53890@code.launchpad.net

This proposal has been superseded by a proposal from 2011-03-21.

Commit message

Add a "links" container to versions entities for Openstack API v1.1

Description of the change

- add a "links" container to versions entities for Openstack API v1.1
- add testing for the openstack api versions resource and create a view builder

To post a comment you must log in.
Revision history for this message
Mark Washenberger (markwash) wrote :

LGTM -

but I'd like to see some ViewBuilder unit tests in the future.

review: Approve
807. By Brian Waldon

merging trunk r843

808. By Brian Waldon

adding view builder tests

809. By Brian Waldon

fixing copyright

810. By Brian Waldon

one more copyright fix

811. By Brian Waldon

merging trunk r864

812. By Brian Waldon

removing old Versions application and correcting fakes to use new controller

813. By Brian Waldon

merging trunk and resolving conflicts

814. By Brian Waldon

merging trunk, resolving conflicts

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'etc/api-paste.ini'
2--- etc/api-paste.ini 2011-03-17 19:52:29 +0000
3+++ etc/api-paste.ini 2011-03-17 19:52:29 +0000
4@@ -89,4 +89,4 @@
5 pipeline = faultwrap osversionapp
6
7 [app:osversionapp]
8-paste.app_factory = nova.api.openstack:Versions.factory
9+paste.app_factory = nova.api.openstack.versions:Versions.factory
10
11=== modified file 'nova/api/openstack/__init__.py'
12--- nova/api/openstack/__init__.py 2011-03-17 19:52:29 +0000
13+++ nova/api/openstack/__init__.py 2011-03-17 19:52:29 +0000
14@@ -121,21 +121,3 @@
15 controller=shared_ip_groups.Controller())
16
17 super(APIRouter, self).__init__(mapper)
18-
19-
20-class Versions(wsgi.Application):
21- @webob.dec.wsgify(RequestClass=wsgi.Request)
22- def __call__(self, req):
23- """Respond to a request for all OpenStack API versions."""
24- response = {
25- "versions": [
26- dict(status="DEPRECATED", id="v1.0"),
27- dict(status="CURRENT", id="v1.1"),
28- ],
29- }
30- metadata = {
31- "application/xml": {
32- "attributes": dict(version=["status", "id"])}}
33-
34- content_type = req.best_match_content_type()
35- return wsgi.Serializer(metadata).serialize(response, content_type)
36
37=== added file 'nova/api/openstack/versions.py'
38--- nova/api/openstack/versions.py 1970-01-01 00:00:00 +0000
39+++ nova/api/openstack/versions.py 2011-03-17 19:52:29 +0000
40@@ -0,0 +1,55 @@
41+# vim: tabstop=4 shiftwidth=4 softtabstop=4
42+
43+# Copyright 2010 United States Government as represented by the
44+# Administrator of the National Aeronautics and Space Administration.
45+# All Rights Reserved.
46+#
47+# Licensed under the Apache License, Version 2.0 (the "License"); you may
48+# not use this file except in compliance with the License. You may obtain
49+# a copy of the License at
50+#
51+# http://www.apache.org/licenses/LICENSE-2.0
52+#
53+# Unless required by applicable law or agreed to in writing, software
54+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
55+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
56+# License for the specific language governing permissions and limitations
57+# under the License.
58+
59+import webob.dec
60+import webob.exc
61+
62+from nova import wsgi
63+import nova.api.openstack.views.versions
64+
65+
66+class Versions(wsgi.Application):
67+ @webob.dec.wsgify(RequestClass=wsgi.Request)
68+ def __call__(self, req):
69+ """Respond to a request for all OpenStack API versions."""
70+ version_objs = [
71+ {
72+ "id": "v1.1",
73+ "status": "CURRENT",
74+ },
75+ {
76+ "id": "v1.0",
77+ "status": "DEPRECATED",
78+ },
79+ ]
80+
81+ builder = nova.api.openstack.views.versions.get_view_builder(req)
82+ versions = [builder.build(version) for version in version_objs]
83+ response = dict(versions=versions)
84+
85+ metadata = {
86+ "application/xml": {
87+ "attributes": {
88+ "version": ["status", "id"],
89+ "link": ["rel", "href"],
90+ }
91+ }
92+ }
93+
94+ content_type = req.best_match_content_type()
95+ return wsgi.Serializer(metadata).serialize(response, content_type)
96
97=== added file 'nova/api/openstack/views/versions.py'
98--- nova/api/openstack/views/versions.py 1970-01-01 00:00:00 +0000
99+++ nova/api/openstack/views/versions.py 2011-03-17 19:52:29 +0000
100@@ -0,0 +1,57 @@
101+# vim: tabstop=4 shiftwidth=4 softtabstop=4
102+
103+# Copyright 2010-2011 OpenStack LLC.
104+# All Rights Reserved.
105+#
106+# Licensed under the Apache License, Version 2.0 (the "License"); you may
107+# not use this file except in compliance with the License. You may obtain
108+# a copy of the License at
109+#
110+# http://www.apache.org/licenses/LICENSE-2.0
111+#
112+# Unless required by applicable law or agreed to in writing, software
113+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
114+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
115+# License for the specific language governing permissions and limitations
116+# under the License.
117+
118+
119+def get_view_builder(req):
120+ base_url = req.application_url
121+ return ViewBuilder(base_url)
122+
123+
124+class ViewBuilder(object):
125+
126+ def __init__(self, base_url):
127+ """
128+ :param base_url: url of the root wsgi application
129+ """
130+ self.base_url = base_url
131+
132+ def build(self, version_data):
133+ """Generic method used to generate a version entity."""
134+ version = {
135+ "id": version_data["id"],
136+ "status": version_data["status"],
137+ "links": self._build_links(version_data),
138+ }
139+
140+ return version
141+
142+ def _build_links(self, version_data):
143+ """Generate a container of links that refer to the provided version."""
144+ href = self.generate_href(version_data["id"])
145+
146+ links = [
147+ {
148+ "rel": "self",
149+ "href": href,
150+ },
151+ ]
152+
153+ return links
154+
155+ def generate_href(self, version_number):
156+ """Create an url that refers to a specific version_number."""
157+ return "%s/%s" % (self.base_url, version_number)
158
159=== modified file 'nova/tests/api/openstack/fakes.py'
160--- nova/tests/api/openstack/fakes.py 2011-03-17 19:52:29 +0000
161+++ nova/tests/api/openstack/fakes.py 2011-03-17 19:52:29 +0000
162@@ -35,6 +35,7 @@
163 from nova.api import openstack
164 from nova.api.openstack import auth
165 from nova.api.openstack import ratelimiting
166+from nova.api.openstack import versions
167 from nova.auth.manager import User, Project
168 from nova.image import glance
169 from nova.image import local
170@@ -80,7 +81,7 @@
171 ratelimiting.RateLimitingMiddleware(inner_application)))
172 mapper['/v1.0'] = api
173 mapper['/v1.1'] = api
174- mapper['/'] = openstack.FaultWrapper(openstack.Versions())
175+ mapper['/'] = openstack.FaultWrapper(versions.Versions())
176 return mapper
177
178
179
180=== added file 'nova/tests/api/openstack/test_versions.py'
181--- nova/tests/api/openstack/test_versions.py 1970-01-01 00:00:00 +0000
182+++ nova/tests/api/openstack/test_versions.py 2011-03-17 19:52:29 +0000
183@@ -0,0 +1,61 @@
184+# vim: tabstop=4 shiftwidth=4 softtabstop=4
185+
186+# Copyright 2010 OpenStack LLC.
187+# All Rights Reserved.
188+#
189+# Licensed under the Apache License, Version 2.0 (the "License"); you may
190+# not use this file except in compliance with the License. You may obtain
191+# a copy of the License at
192+#
193+# http://www.apache.org/licenses/LICENSE-2.0
194+#
195+# Unless required by applicable law or agreed to in writing, software
196+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
197+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
198+# License for the specific language governing permissions and limitations
199+# under the License.
200+
201+import json
202+import webob
203+
204+from nova import context
205+from nova import test
206+from nova.tests.api.openstack import fakes
207+
208+
209+class VersionsTest(test.TestCase):
210+ def setUp(self):
211+ super(VersionsTest, self).setUp()
212+ self.context = context.get_admin_context()
213+
214+ def tearDown(self):
215+ super(VersionsTest, self).tearDown()
216+
217+ def test_get_version_list(self):
218+ req = webob.Request.blank('/')
219+ res = req.get_response(fakes.wsgi_app())
220+ self.assertEqual(res.status_int, 200)
221+ versions = json.loads(res.body)["versions"]
222+ expected = [
223+ {
224+ "id": "v1.1",
225+ "status": "CURRENT",
226+ "links": [
227+ {
228+ "rel": "self",
229+ "href": "http://localhost/v1.1",
230+ }
231+ ],
232+ },
233+ {
234+ "id": "v1.0",
235+ "status": "DEPRECATED",
236+ "links": [
237+ {
238+ "rel": "self",
239+ "href": "http://localhost/v1.0",
240+ }
241+ ],
242+ },
243+ ]
244+ self.assertEqual(versions, expected)