From f96dcc39c764f78c1a81cfc13e598f6acc033ddb Mon Sep 17 00:00:00 2001 From: Vishvananda Ishaya Date: Fri, 24 Feb 2012 12:54:34 -0800 Subject: [PATCH] Make sure detail view works for volume snaphots * adds tests for volume router * test uncovered bug in versions that now fixed * fixes bug 940616 Change-Id: I3f780d59d2fd60ebca3d142277a747400fe35336 --- nova/api/openstack/volume/__init__.py | 3 +- nova/api/openstack/volume/versions.py | 6 +- .../tests/api/openstack/volume/test_router.py | 96 +++++++++++++++++++ .../api/openstack/volume/test_snapshots.py | 1 + 4 files changed, 102 insertions(+), 4 deletions(-) create mode 100644 nova/tests/api/openstack/volume/test_router.py diff --git a/nova/api/openstack/volume/__init__.py b/nova/api/openstack/volume/__init__.py index b4f72d8d5f7b..f65fe8033055 100644 --- a/nova/api/openstack/volume/__init__.py +++ b/nova/api/openstack/volume/__init__.py @@ -58,4 +58,5 @@ class APIRouter(nova.api.openstack.APIRouter): self.resources['snapshots'] = snapshots.create_resource() mapper.resource("snapshot", "snapshots", - controller=self.resources['snapshots']) + controller=self.resources['snapshots'], + collection={'detail': 'GET'}) diff --git a/nova/api/openstack/volume/versions.py b/nova/api/openstack/volume/versions.py index d4839ece471a..f1c39a59c80f 100644 --- a/nova/api/openstack/volume/versions.py +++ b/nova/api/openstack/volume/versions.py @@ -22,8 +22,8 @@ from nova.api.openstack import wsgi VERSIONS = { - "v1": { - "id": "v1", + "v1.0": { + "id": "v1.0", "status": "CURRENT", "updated": "2012-01-04T11:33:21Z", "links": [ @@ -72,7 +72,7 @@ class VolumeVersionV1(object): atom=versions.VersionAtomSerializer) def show(self, req): builder = views_versions.get_view_builder(req) - return builder.build_version(VERSIONS['v2.0']) + return builder.build_version(VERSIONS['v1.0']) def create_resource(): diff --git a/nova/tests/api/openstack/volume/test_router.py b/nova/tests/api/openstack/volume/test_router.py new file mode 100644 index 000000000000..1f37ab7a1482 --- /dev/null +++ b/nova/tests/api/openstack/volume/test_router.py @@ -0,0 +1,96 @@ +# Copyright 2011 Denali Systems, Inc. +# 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. + + +from nova.api.openstack import volume +from nova.api.openstack.volume import snapshots +from nova.api.openstack.volume import volumes +from nova.api.openstack import wsgi +from nova import flags +from nova import log as logging +from nova import test +from nova.tests.api.openstack import fakes + +FLAGS = flags.FLAGS + +LOG = logging.getLogger(__name__) + + +class FakeController(object): + def index(self, req): + return {} + + def detail(self, req): + return {} + + +def create_resource(): + return wsgi.Resource(FakeController()) + + +class VolumeRouterTestCase(test.TestCase): + def setUp(self): + super(VolumeRouterTestCase, self).setUp() + # NOTE(vish): versions is just returning text so, no need to stub. + self.stubs.Set(snapshots, 'create_resource', create_resource) + self.stubs.Set(volumes, 'create_resource', create_resource) + self.app = volume.APIRouter() + + def test_versions(self): + req = fakes.HTTPRequest.blank('') + req.method = 'GET' + req.content_type = 'application/json' + response = req.get_response(self.app) + self.assertEqual(302, response.status_int) + req = fakes.HTTPRequest.blank('/') + req.method = 'GET' + req.content_type = 'application/json' + response = req.get_response(self.app) + self.assertEqual(200, response.status_int) + + def test_volumes(self): + req = fakes.HTTPRequest.blank('/fake/volumes') + req.method = 'GET' + req.content_type = 'application/json' + response = req.get_response(self.app) + self.assertEqual(200, response.status_int) + + def test_volumes_detail(self): + req = fakes.HTTPRequest.blank('/fake/volumes/detail') + req.method = 'GET' + req.content_type = 'application/json' + response = req.get_response(self.app) + self.assertEqual(200, response.status_int) + + def test_types(self): + req = fakes.HTTPRequest.blank('/fake/types') + req.method = 'GET' + req.content_type = 'application/json' + response = req.get_response(self.app) + self.assertEqual(200, response.status_int) + + def test_snapshots(self): + req = fakes.HTTPRequest.blank('/fake/snapshots') + req.method = 'GET' + req.content_type = 'application/json' + response = req.get_response(self.app) + self.assertEqual(200, response.status_int) + + def test_snapshots_detail(self): + req = fakes.HTTPRequest.blank('/fake/snapshots/detail') + req.method = 'GET' + req.content_type = 'application/json' + response = req.get_response(self.app) + self.assertEqual(200, response.status_int) diff --git a/nova/tests/api/openstack/volume/test_snapshots.py b/nova/tests/api/openstack/volume/test_snapshots.py index 0ef112ee940b..ff7e1e047472 100644 --- a/nova/tests/api/openstack/volume/test_snapshots.py +++ b/nova/tests/api/openstack/volume/test_snapshots.py @@ -18,6 +18,7 @@ import datetime from lxml import etree import webob +from nova.api.openstack import volume as openstack_volume from nova.api.openstack.volume import snapshots from nova import exception from nova import flags