summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Lamar <brian.lamar@rackspace.com>2011-03-23 09:47:22 -0400
committerBrian Lamar <brian.lamar@rackspace.com>2011-03-23 09:47:22 -0400
commitff9e29e3ef56ec8b28f28d328ca010ce25f0c7b0 (patch)
tree83dc098598d322a4af4e8fa3992d39168433e2f7
parentc28ec048a56a3ead96dc7528ca50865945d40646 (diff)
Removed some un-needed code, and started adding tests for show(), which I forgot\!
-rw-r--r--nova/api/openstack/images.py37
-rw-r--r--nova/tests/api/openstack/test_images.py61
2 files changed, 81 insertions, 17 deletions
diff --git a/nova/api/openstack/images.py b/nova/api/openstack/images.py
index 4cd989054..d8606e3c2 100644
--- a/nova/api/openstack/images.py
+++ b/nova/api/openstack/images.py
@@ -13,9 +13,10 @@
# License for the specific language governing permissions and limitations
# under the License.
-from webob import exc
+import webob.exc
from nova import compute
+from nova import exception
from nova import flags
from nova import utils
from nova import wsgi
@@ -39,11 +40,6 @@ class Controller(wsgi.Controller):
},
}
- _builder_dispatch = {
- "1.0": images_view.ViewBuilderV10,
- "1.1": images_view.ViewBuilderV11,
- }
-
def __init__(self, image_service=None, compute_service=None):
"""
Initialize new `ImageController`.
@@ -60,7 +56,7 @@ class Controller(wsgi.Controller):
"""
Return an index listing of images available to the request.
- @param req: `webob.Request` object
+ @param req: `wsgi.Request` object
"""
context = req.environ['nova.context']
images = self.__image.index(context)
@@ -71,31 +67,38 @@ class Controller(wsgi.Controller):
"""
Return a detailed index listing of images available to the request.
- @param req: `webob.Request` object.
+ @param req: `wsgi.Request` object.
"""
context = req.environ['nova.context']
images = self.__image.detail(context)
build = self.get_builder(req).build
return dict(images=[build(image, True) for image in images])
- def show(self, req, image_id):
+ def show(self, req, id):
"""
Return detailed information about a specific image.
- @param req: `webob.Request` object
- @param image_id: Image identifier (integer)
+ @param req: `wsgi.Request` object
+ @param id: Image identifier (integer)
"""
+ image_id = id
context = req.environ['nova.context']
- image = self.__image.show(context, image_id)
- return self.get_builder().build(req, image, True)
- def delete(self, req, image_id):
+ try:
+ image = self.__image.show(context, image_id)
+ except exception.NotFound:
+ raise webob.exc.HTTPNotFound
+
+ return self.get_builder(req).build(image, True)
+
+ def delete(self, req, id):
"""
Delete an image, if allowed.
- @param req: `webob.Request` object
- @param image_id: Image identifier (integer)
+ @param req: `wsgi.Request` object
+ @param id: Image identifier (integer)
"""
+ image_id = id
context = req.environ['nova.context']
self.__image.delete(context, image_id)
return exc.HTTPNoContent()
@@ -104,7 +107,7 @@ class Controller(wsgi.Controller):
"""
Snapshot a server instance and save the image.
- @param req: `webob.Request` object
+ @param req: `wsgi.Request` object
"""
context = req.environ['nova.context']
body = req.body
diff --git a/nova/tests/api/openstack/test_images.py b/nova/tests/api/openstack/test_images.py
index c5a866bc7..8828b0e34 100644
--- a/nova/tests/api/openstack/test_images.py
+++ b/nova/tests/api/openstack/test_images.py
@@ -235,6 +235,67 @@ class ImageControllerWithGlanceServiceTest(test.TestCase):
self.assertEqual(len(response_list), len(self.IMAGE_FIXTURES))
+ def test_get_image(self):
+ request = webob.Request.blank('/v1.0/images/23g2ogk23k4hhkk4k42l')
+ response = request.get_response(fakes.wsgi_app())
+
+ actual_image = json.loads(response.body)
+
+ expected = self.IMAGE_FIXTURES[0]
+ expected_image = {
+ "id": expected["id"],
+ "name": expected["name"],
+ "updated": expected["updated_at"],
+ "created": expected["created_at"],
+ "status": expected["status"],
+ }
+
+ self.assertEqual(expected_image, actual_image)
+
+ def test_get_image_v1_1(self):
+ request = webob.Request.blank('/v1.1/images/23g2ogk23k4hhkk4k42l')
+ response = request.get_response(fakes.wsgi_app())
+
+ actual_image = json.loads(response.body)
+
+ expected = self.IMAGE_FIXTURES[0]
+ href = "http://localhost/v1.1/images/%s" % expected["id"]
+
+ expected_image = {
+ "id": expected["id"],
+ "name": expected["name"],
+ "updated": expected["updated_at"],
+ "created": expected["created_at"],
+ "status": expected["status"],
+ "links": [{
+ "rel": "self",
+ "href": href,
+ },
+ {
+ "rel": "bookmark",
+ "type": "application/json",
+ "href": href,
+ },
+ {
+ "rel": "bookmark",
+ "type": "application/xml",
+ "href": href,
+ }],
+ }
+
+ self.assertEqual(expected_image, actual_image)
+
+ def test_get_image_404(self):
+ request = webob.Request.blank('/v1.0/images/NonExistantImage')
+ response = request.get_response(fakes.wsgi_app())
+ self.assertEqual(404, response.status_int)
+ self.assertEqual("", response.body)
+
+ def test_get_image_v1_1_404(self):
+ request = webob.Request.blank('/v1.1/images/NonExistantImage')
+ response = request.get_response(fakes.wsgi_app())
+ self.assertEqual(404, response.status_int)
+
def test_get_image_index_v1_1(self):
request = webob.Request.blank('/v1.1/images')
response = request.get_response(fakes.wsgi_app())