]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
creating separate v1 and v2 stubs and general fakes
authorMike Perez <thingee@gmail.com>
Sat, 1 Dec 2012 00:23:37 +0000 (16:23 -0800)
committerMike Perez <thingee@gmail.com>
Fri, 7 Dec 2012 02:05:30 +0000 (18:05 -0800)
For now contribs will use v2, but in the future will test against all
supported versions.

Change-Id: I47c30f8c2fc8a89f92065122bf1ca6aec1ce8b2d

19 files changed:
cinder/tests/api/contrib/test_admin_actions.py
cinder/tests/api/contrib/test_extended_snapshot_attributes.py
cinder/tests/api/contrib/test_types_extra_specs.py
cinder/tests/api/contrib/test_types_manage.py
cinder/tests/api/contrib/test_volume_actions.py
cinder/tests/api/contrib/test_volume_host_attribute.py
cinder/tests/api/contrib/test_volume_tenant_attribute.py
cinder/tests/api/fakes.py [moved from cinder/tests/api/openstack/fakes.py with 56% similarity]
cinder/tests/api/openstack/test_wsgi.py
cinder/tests/api/test_router.py
cinder/tests/api/v1/stubs.py [new file with mode: 0644]
cinder/tests/api/v1/test_snapshots.py
cinder/tests/api/v1/test_types.py
cinder/tests/api/v1/test_volumes.py
cinder/tests/api/v2/stubs.py [new file with mode: 0644]
cinder/tests/api/v2/test_snapshots.py
cinder/tests/api/v2/test_types.py
cinder/tests/api/v2/test_volumes.py
cinder/tests/image/test_glance.py

index 56c628b2a1dee6ebe7866a9ead3454901d6eadab..c99ab65ea538bba9ceb908aa7c3241b0c15d0080 100644 (file)
@@ -5,7 +5,8 @@ from cinder import db
 from cinder import exception
 from cinder.openstack.common import jsonutils
 from cinder import test
-from cinder.tests.api.openstack import fakes
+from cinder.tests.api import fakes
+from cinder.tests.api.v2 import stubs
 from cinder.volume import api as volume_api
 
 
@@ -13,7 +14,7 @@ def app():
     # no auth, just let environ['cinder.context'] pass through
     api = fakes.router.APIRouter()
     mapper = fakes.urlmap.URLMap()
-    mapper['/v1'] = api
+    mapper['/v2'] = api
     return mapper
 
 
@@ -29,7 +30,7 @@ class AdminActionsTest(test.TestCase):
         ctx = context.RequestContext('admin', 'fake', True)
         # current status is available
         volume = db.volume_create(ctx, {'status': 'available'})
-        req = webob.Request.blank('/v1/fake/volumes/%s/action' % volume['id'])
+        req = webob.Request.blank('/v2/fake/volumes/%s/action' % volume['id'])
         req.method = 'POST'
         req.headers['content-type'] = 'application/json'
         # request status of 'error'
@@ -47,7 +48,7 @@ class AdminActionsTest(test.TestCase):
         # current status is 'error'
         volume = db.volume_create(context.get_admin_context(),
                                   {'status': 'error'})
-        req = webob.Request.blank('/v1/fake/volumes/%s/action' % volume['id'])
+        req = webob.Request.blank('/v2/fake/volumes/%s/action' % volume['id'])
         req.method = 'POST'
         req.headers['content-type'] = 'application/json'
         # request changing status to available
@@ -67,7 +68,7 @@ class AdminActionsTest(test.TestCase):
         ctx = context.RequestContext('admin', 'fake', True)
         # current status is available
         volume = db.volume_create(ctx, {'status': 'available'})
-        req = webob.Request.blank('/v1/fake/volumes/%s/action' % volume['id'])
+        req = webob.Request.blank('/v2/fake/volumes/%s/action' % volume['id'])
         req.method = 'POST'
         req.headers['content-type'] = 'application/json'
         # malformed request body
@@ -86,7 +87,7 @@ class AdminActionsTest(test.TestCase):
         ctx = context.RequestContext('admin', 'fake', True)
         # current status is available
         volume = db.volume_create(ctx, {'status': 'available'})
-        req = webob.Request.blank('/v1/fake/volumes/%s/action' % volume['id'])
+        req = webob.Request.blank('/v2/fake/volumes/%s/action' % volume['id'])
         req.method = 'POST'
         req.headers['content-type'] = 'application/json'
         # 'invalid' is not a valid status
@@ -104,7 +105,7 @@ class AdminActionsTest(test.TestCase):
         # admin context
         ctx = context.RequestContext('admin', 'fake', True)
         # missing-volume-id
-        req = webob.Request.blank('/v1/fake/volumes/%s/action' %
+        req = webob.Request.blank('/v2/fake/volumes/%s/action' %
                                   'missing-volume-id')
         req.method = 'POST'
         req.headers['content-type'] = 'application/json'
@@ -125,7 +126,7 @@ class AdminActionsTest(test.TestCase):
         # current status is available
         volume = db.volume_create(ctx, {'status': 'available',
                                         'attach_status': 'attached'})
-        req = webob.Request.blank('/v1/fake/volumes/%s/action' % volume['id'])
+        req = webob.Request.blank('/v2/fake/volumes/%s/action' % volume['id'])
         req.method = 'POST'
         req.headers['content-type'] = 'application/json'
         # request update attach_status to detached
@@ -149,7 +150,7 @@ class AdminActionsTest(test.TestCase):
         # current status is available
         volume = db.volume_create(ctx, {'status': 'available',
                                         'attach_status': 'detached'})
-        req = webob.Request.blank('/v1/fake/volumes/%s/action' % volume['id'])
+        req = webob.Request.blank('/v2/fake/volumes/%s/action' % volume['id'])
         req.method = 'POST'
         req.headers['content-type'] = 'application/json'
         # 'invalid' is not a valid attach_status
@@ -173,7 +174,7 @@ class AdminActionsTest(test.TestCase):
         volume = db.volume_create(ctx, {})
         snapshot = db.snapshot_create(ctx, {'status': 'error_deleting',
                                             'volume_id': volume['id']})
-        req = webob.Request.blank('/v1/fake/snapshots/%s/action' %
+        req = webob.Request.blank('/v2/fake/snapshots/%s/action' %
                                   snapshot['id'])
         req.method = 'POST'
         req.headers['content-type'] = 'application/json'
@@ -195,7 +196,7 @@ class AdminActionsTest(test.TestCase):
         volume = db.volume_create(ctx, {})
         snapshot = db.snapshot_create(ctx, {'status': 'available',
                                             'volume_id': volume['id']})
-        req = webob.Request.blank('/v1/fake/snapshots/%s/action' %
+        req = webob.Request.blank('/v2/fake/snapshots/%s/action' %
                                   snapshot['id'])
         req.method = 'POST'
         req.headers['content-type'] = 'application/json'
@@ -216,7 +217,7 @@ class AdminActionsTest(test.TestCase):
         ctx = context.RequestContext('admin', 'fake', True)
         # current status is creating
         volume = db.volume_create(ctx, {'status': 'creating'})
-        req = webob.Request.blank('/v1/fake/volumes/%s/action' % volume['id'])
+        req = webob.Request.blank('/v2/fake/volumes/%s/action' % volume['id'])
         req.method = 'POST'
         req.headers['content-type'] = 'application/json'
         req.body = jsonutils.dumps({'os-force_delete': {}})
@@ -236,7 +237,7 @@ class AdminActionsTest(test.TestCase):
         snapshot = db.snapshot_create(ctx, {'status': 'creating',
                                             'volume_size': 1,
                                             'volume_id': volume['id']})
-        path = '/v1/fake/snapshots/%s/action' % snapshot['id']
+        path = '/v2/fake/snapshots/%s/action' % snapshot['id']
         req = webob.Request.blank(path)
         req.method = 'POST'
         req.headers['content-type'] = 'application/json'
@@ -264,15 +265,15 @@ class AdminActionsTest(test.TestCase):
         self.volume_api.reserve_volume(ctx, volume)
         self.volume_api.initialize_connection(ctx, volume, {})
         mountpoint = '/dev/vbd'
-        self.volume_api.attach(ctx, volume, fakes.FAKE_UUID, mountpoint)
+        self.volume_api.attach(ctx, volume, stubs.FAKE_UUID, mountpoint)
         # volume is attached
         volume = db.volume_get(ctx, volume['id'])
         self.assertEquals(volume['status'], 'in-use')
-        self.assertEquals(volume['instance_uuid'], fakes.FAKE_UUID)
+        self.assertEquals(volume['instance_uuid'], stubs.FAKE_UUID)
         self.assertEquals(volume['mountpoint'], mountpoint)
         self.assertEquals(volume['attach_status'], 'attached')
         # build request to force detach
-        req = webob.Request.blank('/v1/fake/volumes/%s/action' % volume['id'])
+        req = webob.Request.blank('/v2/fake/volumes/%s/action' % volume['id'])
         req.method = 'POST'
         req.headers['content-type'] = 'application/json'
         # request status of 'error'
index fdac9d709332875b7866fd29487ca6d077e1d18e..d8e7ceda94606ff505f5615a1010d71e62e60457 100644 (file)
@@ -21,7 +21,7 @@ from cinder import exception
 from cinder import flags
 from cinder.openstack.common import jsonutils
 from cinder import test
-from cinder.tests.api.openstack import fakes
+from cinder.tests.api import fakes
 from cinder import volume
 
 
@@ -82,7 +82,7 @@ class ExtendedSnapshotAttributesTest(test.TestCase):
         self.assertEqual(snapshot.get('%sprogress' % self.prefix), progress)
 
     def test_show(self):
-        url = '/v1/fake/snapshots/%s' % UUID2
+        url = '/v2/fake/snapshots/%s' % UUID2
         res = self._make_request(url)
 
         self.assertEqual(res.status_int, 200)
@@ -91,7 +91,7 @@ class ExtendedSnapshotAttributesTest(test.TestCase):
                                       progress='0%')
 
     def test_detail(self):
-        url = '/v1/fake/snapshots/detail'
+        url = '/v2/fake/snapshots/detail'
         res = self._make_request(url)
 
         self.assertEqual(res.status_int, 200)
@@ -106,7 +106,7 @@ class ExtendedSnapshotAttributesTest(test.TestCase):
             raise exception.InstanceNotFound()
 
         self.stubs.Set(volume.api.API, 'get_snapshot', fake_snapshot_get)
-        url = '/v1/fake/snapshots/70f6db34-de8d-4fbd-aafb-4065bdfa6115'
+        url = '/v2/fake/snapshots/70f6db34-de8d-4fbd-aafb-4065bdfa6115'
         res = self._make_request(url)
 
         self.assertEqual(res.status_int, 404)
index 47414d556a0995e90b975f47551f008c5b5c6ca3..15baea7d529feb8be9179bf3f6024fd969fba558 100644 (file)
@@ -22,7 +22,7 @@ import webob
 
 from cinder.api.contrib import types_extra_specs
 from cinder import test
-from cinder.tests.api.openstack import fakes
+from cinder.tests.api import fakes
 import cinder.wsgi
 
 
@@ -62,7 +62,7 @@ class VolumeTypesExtraSpecsTest(test.TestCase):
     def setUp(self):
         super(VolumeTypesExtraSpecsTest, self).setUp()
         self.stubs.Set(cinder.db, 'volume_type_get', volume_type_get)
-        self.api_path = '/v1/fake/os-volume-types/1/extra_specs'
+        self.api_path = '/v2/fake/os-volume-types/1/extra_specs'
         self.controller = types_extra_specs.VolumeTypeExtraSpecsController()
 
     def test_index(self):
index 9e5be71ad5627405ef9cadfb924cf3a76d1dcbf2..14fa778d070d6bd39b881a258f82aec37e98940d 100644 (file)
@@ -18,7 +18,7 @@ import webob
 from cinder.api.contrib import types_manage
 from cinder import exception
 from cinder import test
-from cinder.tests.api.openstack import fakes
+from cinder.tests.api import fakes
 from cinder.volume import volume_types
 
 
@@ -65,7 +65,7 @@ class VolumeTypesManageApiTest(test.TestCase):
         self.stubs.Set(volume_types, 'destroy',
                        return_volume_types_destroy)
 
-        req = fakes.HTTPRequest.blank('/v1/fake/types/1')
+        req = fakes.HTTPRequest.blank('/v2/fake/types/1')
         self.controller._delete(req, 1)
 
     def test_volume_types_delete_not_found(self):
@@ -74,7 +74,7 @@ class VolumeTypesManageApiTest(test.TestCase):
         self.stubs.Set(volume_types, 'destroy',
                        return_volume_types_destroy)
 
-        req = fakes.HTTPRequest.blank('/v1/fake/types/777')
+        req = fakes.HTTPRequest.blank('/v2/fake/types/777')
         self.assertRaises(webob.exc.HTTPNotFound, self.controller._delete,
                           req, '777')
 
@@ -86,7 +86,7 @@ class VolumeTypesManageApiTest(test.TestCase):
 
         body = {"volume_type": {"name": "vol_type_1",
                                 "extra_specs": {"key1": "value1"}}}
-        req = fakes.HTTPRequest.blank('/v1/fake/types')
+        req = fakes.HTTPRequest.blank('/v2/fake/types')
         res_dict = self.controller._create(req, body)
 
         self.assertEqual(1, len(res_dict))
index 3e1b9c613f0be13fef7af1a83301bcbc8be0852b..a2b019cd0e872ed88281552ca426e6ad66afc314 100644 (file)
@@ -24,7 +24,8 @@ from cinder import flags
 from cinder.openstack.common import jsonutils
 from cinder.openstack.common.rpc import common as rpc_common
 from cinder import test
-from cinder.tests.api.openstack import fakes
+from cinder.tests.api import fakes
+from cinder.tests.api.v2 import stubs
 from cinder import volume
 from cinder.volume import api as volume_api
 
@@ -58,7 +59,7 @@ class VolumeActionsTest(test.TestCase):
     def test_simple_api_actions(self):
         app = fakes.wsgi_app()
         for _action in self._actions:
-            req = webob.Request.blank('/v1/fake/volumes/%s/action' %
+            req = webob.Request.blank('/v2/fake/volumes/%s/action' %
                                       self.UUID)
             req.method = 'POST'
             req.body = jsonutils.dumps({_action: None})
@@ -73,7 +74,7 @@ class VolumeActionsTest(test.TestCase):
                        fake_initialize_connection)
 
         body = {'os-initialize_connection': {'connector': 'fake'}}
-        req = webob.Request.blank('/v1/fake/volumes/1/action')
+        req = webob.Request.blank('/v2/fake/volumes/1/action')
         req.method = "POST"
         req.body = jsonutils.dumps(body)
         req.headers["content-type"] = "application/json"
@@ -88,7 +89,7 @@ class VolumeActionsTest(test.TestCase):
                        fake_terminate_connection)
 
         body = {'os-terminate_connection': {'connector': 'fake'}}
-        req = webob.Request.blank('/v1/fake/volumes/1/action')
+        req = webob.Request.blank('/v2/fake/volumes/1/action')
         req.method = "POST"
         req.body = jsonutils.dumps(body)
         req.headers["content-type"] = "application/json"
@@ -99,7 +100,7 @@ class VolumeActionsTest(test.TestCase):
     def test_attach(self):
         body = {'os-attach': {'instance_uuid': 'fake',
                               'mountpoint': '/dev/vdc'}}
-        req = webob.Request.blank('/v1/fake/volumes/1/action')
+        req = webob.Request.blank('/v2/fake/volumes/1/action')
         req.method = "POST"
         req.body = jsonutils.dumps(body)
         req.headers["content-type"] = "application/json"
@@ -109,7 +110,7 @@ class VolumeActionsTest(test.TestCase):
 
 
 def stub_volume_get(self, context, volume_id):
-    volume = fakes.stub_volume(volume_id)
+    volume = stubs.stub_volume(volume_id)
     if volume_id == 5:
         volume['status'] = 'in-use'
     else:
@@ -150,7 +151,7 @@ class VolumeImageActionsTest(test.TestCase):
                "image_name": 'image_name',
                "force": True}
         body = {"os-volume_upload_image": vol}
-        req = fakes.HTTPRequest.blank('/v1/tenant1/volumes/%s/action' % id)
+        req = fakes.HTTPRequest.blank('/v2/tenant1/volumes/%s/action' % id)
         res_dict = self.controller._volume_upload_image(req, id, body)
         expected = {'os-volume_upload_image': {'id': id,
                     'updated_at': datetime.datetime(1, 1, 1, 1, 1, 1),
@@ -176,7 +177,7 @@ class VolumeImageActionsTest(test.TestCase):
                "image_name": 'image_name',
                "force": True}
         body = {"os-volume_upload_image": vol}
-        req = fakes.HTTPRequest.blank('/v1/tenant1/volumes/%s/action' % id)
+        req = fakes.HTTPRequest.blank('/v2/tenant1/volumes/%s/action' % id)
         self.assertRaises(webob.exc.HTTPNotFound,
                           self.controller._volume_upload_image,
                           req,
@@ -197,7 +198,7 @@ class VolumeImageActionsTest(test.TestCase):
                "image_name": 'image_name',
                "force": True}
         body = {"os-volume_upload_image": vol}
-        req = fakes.HTTPRequest.blank('/v1/tenant1/volumes/%s/action' % id)
+        req = fakes.HTTPRequest.blank('/v2/tenant1/volumes/%s/action' % id)
         self.assertRaises(webob.exc.HTTPBadRequest,
                           self.controller._volume_upload_image,
                           req,
@@ -218,7 +219,7 @@ class VolumeImageActionsTest(test.TestCase):
                "image_name": 'image_name',
                "force": True}
         body = {"os-volume_upload_image": vol}
-        req = fakes.HTTPRequest.blank('/v1/tenant1/volumes/%s/action' % id)
+        req = fakes.HTTPRequest.blank('/v2/tenant1/volumes/%s/action' % id)
         self.assertRaises(webob.exc.HTTPBadRequest,
                           self.controller._volume_upload_image,
                           req,
@@ -239,7 +240,7 @@ class VolumeImageActionsTest(test.TestCase):
                "image_name": 'image_name',
                "force": True}
         body = {"os-volume_upload_image": vol}
-        req = fakes.HTTPRequest.blank('/v1/tenant1/volumes/%s/action' % id)
+        req = fakes.HTTPRequest.blank('/v2/tenant1/volumes/%s/action' % id)
         self.assertRaises(webob.exc.HTTPBadRequest,
                           self.controller._volume_upload_image,
                           req,
index 61e4cfe8939b7d0a70454ed1d352097545676732..a54c53f93d543e31a5e7c78413bffbdb8387f19c 100644 (file)
@@ -23,7 +23,7 @@ import webob
 
 from cinder import context
 from cinder import test
-from cinder.tests.api.openstack import fakes
+from cinder.tests.api import fakes
 from cinder import volume
 
 
@@ -52,7 +52,7 @@ def app():
     # no auth, just let environ['cinder.context'] pass through
     api = fakes.router.APIRouter()
     mapper = fakes.urlmap.URLMap()
-    mapper['/v1'] = api
+    mapper['/v2'] = api
     return mapper
 
 
@@ -66,7 +66,7 @@ class VolumeHostAttributeTest(test.TestCase):
 
     def test_get_volume_allowed(self):
         ctx = context.RequestContext('admin', 'fake', True)
-        req = webob.Request.blank('/v1/fake/volumes/%s' % self.UUID)
+        req = webob.Request.blank('/v2/fake/volumes/%s' % self.UUID)
         req.method = 'GET'
         req.environ['cinder.context'] = ctx
         res = req.get_response(app())
@@ -75,7 +75,7 @@ class VolumeHostAttributeTest(test.TestCase):
 
     def test_get_volume_unallowed(self):
         ctx = context.RequestContext('non-admin', 'fake', False)
-        req = webob.Request.blank('/v1/fake/volumes/%s' % self.UUID)
+        req = webob.Request.blank('/v2/fake/volumes/%s' % self.UUID)
         req.method = 'GET'
         req.environ['cinder.context'] = ctx
         res = req.get_response(app())
@@ -84,7 +84,7 @@ class VolumeHostAttributeTest(test.TestCase):
 
     def test_list_detail_volumes_allowed(self):
         ctx = context.RequestContext('admin', 'fake', True)
-        req = webob.Request.blank('/v1/fake/volumes/detail')
+        req = webob.Request.blank('/v2/fake/volumes/detail')
         req.method = 'GET'
         req.environ['cinder.context'] = ctx
         res = req.get_response(app())
@@ -93,7 +93,7 @@ class VolumeHostAttributeTest(test.TestCase):
 
     def test_list_detail_volumes_unallowed(self):
         ctx = context.RequestContext('non-admin', 'fake', False)
-        req = webob.Request.blank('/v1/fake/volumes/detail')
+        req = webob.Request.blank('/v2/fake/volumes/detail')
         req.method = 'GET'
         req.environ['cinder.context'] = ctx
         res = req.get_response(app())
@@ -102,7 +102,7 @@ class VolumeHostAttributeTest(test.TestCase):
 
     def test_list_simple_volumes_no_host(self):
         ctx = context.RequestContext('admin', 'fake', True)
-        req = webob.Request.blank('/v1/fake/volumes')
+        req = webob.Request.blank('/v2/fake/volumes')
         req.method = 'GET'
         req.environ['cinder.context'] = ctx
         res = req.get_response(app())
@@ -111,7 +111,7 @@ class VolumeHostAttributeTest(test.TestCase):
 
     def test_get_volume_xml(self):
         ctx = context.RequestContext('admin', 'fake', True)
-        req = webob.Request.blank('/v1/fake/volumes/%s' % self.UUID)
+        req = webob.Request.blank('/v2/fake/volumes/%s' % self.UUID)
         req.method = 'GET'
         req.accept = 'application/xml'
         req.environ['cinder.context'] = ctx
@@ -123,7 +123,7 @@ class VolumeHostAttributeTest(test.TestCase):
 
     def test_list_volumes_detail_xml(self):
         ctx = context.RequestContext('admin', 'fake', True)
-        req = webob.Request.blank('/v1/fake/volumes/detail')
+        req = webob.Request.blank('/v2/fake/volumes/detail')
         req.method = 'GET'
         req.accept = 'application/xml'
         req.environ['cinder.context'] = ctx
index 2904fcc93593a7d70bdb1453ba4f44fd1d9e22c3..e6e10e1e2a759757b1fb383ef098acc9a60e8a9e 100644 (file)
@@ -23,7 +23,7 @@ import webob
 
 from cinder import context
 from cinder import test
-from cinder.tests.api.openstack import fakes
+from cinder.tests.api import fakes
 from cinder import volume
 
 
@@ -55,7 +55,7 @@ def app():
     # no auth, just let environ['cinder.context'] pass through
     api = fakes.router.APIRouter()
     mapper = fakes.urlmap.URLMap()
-    mapper['/v1'] = api
+    mapper['/v2'] = api
     return mapper
 
 
@@ -69,7 +69,7 @@ class VolumeTenantAttributeTest(test.TestCase):
 
     def test_get_volume_allowed(self):
         ctx = context.RequestContext('admin', 'fake', True)
-        req = webob.Request.blank('/v1/fake/volumes/%s' % self.UUID)
+        req = webob.Request.blank('/v2/fake/volumes/%s' % self.UUID)
         req.method = 'GET'
         req.environ['cinder.context'] = ctx
         res = req.get_response(app())
@@ -78,7 +78,7 @@ class VolumeTenantAttributeTest(test.TestCase):
 
     def test_get_volume_unallowed(self):
         ctx = context.RequestContext('non-admin', 'fake', False)
-        req = webob.Request.blank('/v1/fake/volumes/%s' % self.UUID)
+        req = webob.Request.blank('/v2/fake/volumes/%s' % self.UUID)
         req.method = 'GET'
         req.environ['cinder.context'] = ctx
         res = req.get_response(app())
@@ -87,7 +87,7 @@ class VolumeTenantAttributeTest(test.TestCase):
 
     def test_list_detail_volumes_allowed(self):
         ctx = context.RequestContext('admin', 'fake', True)
-        req = webob.Request.blank('/v1/fake/volumes/detail')
+        req = webob.Request.blank('/v2/fake/volumes/detail')
         req.method = 'GET'
         req.environ['cinder.context'] = ctx
         res = req.get_response(app())
@@ -96,7 +96,7 @@ class VolumeTenantAttributeTest(test.TestCase):
 
     def test_list_detail_volumes_unallowed(self):
         ctx = context.RequestContext('non-admin', 'fake', False)
-        req = webob.Request.blank('/v1/fake/volumes/detail')
+        req = webob.Request.blank('/v2/fake/volumes/detail')
         req.method = 'GET'
         req.environ['cinder.context'] = ctx
         res = req.get_response(app())
@@ -105,7 +105,7 @@ class VolumeTenantAttributeTest(test.TestCase):
 
     def test_list_simple_volumes_no_tenant_id(self):
         ctx = context.RequestContext('admin', 'fake', True)
-        req = webob.Request.blank('/v1/fake/volumes')
+        req = webob.Request.blank('/v2/fake/volumes')
         req.method = 'GET'
         req.environ['cinder.context'] = ctx
         res = req.get_response(app())
@@ -114,7 +114,7 @@ class VolumeTenantAttributeTest(test.TestCase):
 
     def test_get_volume_xml(self):
         ctx = context.RequestContext('admin', 'fake', True)
-        req = webob.Request.blank('/v1/fake/volumes/%s' % self.UUID)
+        req = webob.Request.blank('/v2/fake/volumes/%s' % self.UUID)
         req.method = 'GET'
         req.accept = 'application/xml'
         req.environ['cinder.context'] = ctx
@@ -126,7 +126,7 @@ class VolumeTenantAttributeTest(test.TestCase):
 
     def test_list_volumes_detail_xml(self):
         ctx = context.RequestContext('admin', 'fake', True)
-        req = webob.Request.blank('/v1/fake/volumes/detail')
+        req = webob.Request.blank('/v2/fake/volumes/detail')
         req.method = 'GET'
         req.accept = 'application/xml'
         req.environ['cinder.context'] = ctx
similarity index 56%
rename from cinder/tests/api/openstack/fakes.py
rename to cinder/tests/api/fakes.py
index 95433c1ffb6332c572ea2b639fda79da3c7129cf..edcfad0d6e42cd0992daa39084f66f0d666aca5c 100644 (file)
@@ -15,7 +15,6 @@
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
-import datetime
 import uuid
 
 import routes
@@ -27,11 +26,10 @@ from cinder.api.middleware import auth
 from cinder.api.middleware import fault
 from cinder.api.openstack import wsgi as os_wsgi
 from cinder.api import urlmap
-from cinder.api.v1 import limits
-from cinder.api.v1 import router
+from cinder.api.v2 import limits
+from cinder.api.v2 import router
 from cinder.api import versions
 from cinder import context
-from cinder import exception as exc
 from cinder.openstack.common import timeutils
 from cinder import wsgi
 
@@ -61,27 +59,27 @@ def fake_wsgi(self, req):
     return self.application
 
 
-def wsgi_app(inner_app_v1=None, fake_auth=True, fake_auth_context=None,
+def wsgi_app(inner_app_v2=None, fake_auth=True, fake_auth_context=None,
              use_no_auth=False, ext_mgr=None):
-    if not inner_app_v1:
-        inner_app_v1 = router.APIRouter(ext_mgr)
+    if not inner_app_v2:
+        inner_app_v2 = router.APIRouter(ext_mgr)
 
     if fake_auth:
         if fake_auth_context is not None:
             ctxt = fake_auth_context
         else:
             ctxt = context.RequestContext('fake', 'fake', auth_token=True)
-        api_v1 = fault.FaultWrapper(auth.InjectContext(ctxt,
-                                                       inner_app_v1))
+        api_v2 = fault.FaultWrapper(auth.InjectContext(ctxt,
+                                                       inner_app_v2))
     elif use_no_auth:
-        api_v1 = fault.FaultWrapper(auth.NoAuthMiddleware(
-            limits.RateLimitingMiddleware(inner_app_v1)))
+        api_v2 = fault.FaultWrapper(auth.NoAuthMiddleware(
+            limits.RateLimitingMiddleware(inner_app_v2)))
     else:
-        api_v1 = fault.FaultWrapper(auth.AuthMiddleware(
-            limits.RateLimitingMiddleware(inner_app_v1)))
+        api_v2 = fault.FaultWrapper(auth.AuthMiddleware(
+            limits.RateLimitingMiddleware(inner_app_v2)))
 
     mapper = urlmap.URLMap()
-    mapper['/v1'] = api_v1
+    mapper['/v2'] = api_v2
     mapper['/'] = fault.FaultWrapper(versions.Versions())
     return mapper
 
@@ -175,109 +173,3 @@ def get_fake_uuid(token=0):
     if not token in FAKE_UUIDS:
         FAKE_UUIDS[token] = str(uuid.uuid4())
     return FAKE_UUIDS[token]
-
-
-def stub_volume(id, **kwargs):
-    volume = {
-        'id': id,
-        'user_id': 'fakeuser',
-        'project_id': 'fakeproject',
-        'host': 'fakehost',
-        'size': 1,
-        'availability_zone': 'fakeaz',
-        'instance_uuid': 'fakeuuid',
-        'mountpoint': '/',
-        'status': 'fakestatus',
-        'attach_status': 'attached',
-        'bootable': 'false',
-        'name': 'vol name',
-        'display_name': 'displayname',
-        'display_description': 'displaydesc',
-        'created_at': datetime.datetime(1, 1, 1, 1, 1, 1),
-        'snapshot_id': None,
-        'volume_type_id': '3e196c20-3c06-11e2-81c1-0800200c9a66',
-        'volume_metadata': [],
-        'volume_type': {'name': 'vol_type_name'}}
-
-    volume.update(kwargs)
-    return volume
-
-
-def stub_volume_create(self, context, size, name, description, snapshot,
-                       **param):
-    vol = stub_volume('1')
-    vol['size'] = size
-    vol['display_name'] = name
-    vol['display_description'] = description
-    try:
-        vol['snapshot_id'] = snapshot['id']
-    except (KeyError, TypeError):
-        vol['snapshot_id'] = None
-    vol['availability_zone'] = param.get('availability_zone', 'fakeaz')
-    return vol
-
-
-def stub_volume_create_from_image(self, context, size, name, description,
-                                  snapshot, volume_type, metadata,
-                                  availability_zone):
-    vol = stub_volume('1')
-    vol['status'] = 'creating'
-    vol['size'] = size
-    vol['display_name'] = name
-    vol['display_description'] = description
-    vol['availability_zone'] = 'cinder'
-    return vol
-
-
-def stub_volume_update(self, context, *args, **param):
-    pass
-
-
-def stub_volume_delete(self, context, *args, **param):
-    pass
-
-
-def stub_volume_get(self, context, volume_id):
-    return stub_volume(volume_id)
-
-
-def stub_volume_get_notfound(self, context, volume_id):
-    raise exc.NotFound
-
-
-def stub_volume_get_all(context, search_opts=None):
-    return [stub_volume(100, project_id='fake'),
-            stub_volume(101, project_id='superfake'),
-            stub_volume(102, project_id='superduperfake')]
-
-
-def stub_volume_get_all_by_project(self, context, search_opts=None):
-    return [stub_volume_get(self, context, '1')]
-
-
-def stub_snapshot(id, **kwargs):
-    snapshot = {'id': id,
-                'volume_id': 12,
-                'status': 'available',
-                'volume_size': 100,
-                'created_at': None,
-                'display_name': 'Default name',
-                'display_description': 'Default description',
-                'project_id': 'fake'}
-
-    snapshot.update(kwargs)
-    return snapshot
-
-
-def stub_snapshot_get_all(self):
-    return [stub_snapshot(100, project_id='fake'),
-            stub_snapshot(101, project_id='superfake'),
-            stub_snapshot(102, project_id='superduperfake')]
-
-
-def stub_snapshot_get_all_by_project(self, context):
-    return [stub_snapshot(1)]
-
-
-def stub_snapshot_update(self, context, *args, **param):
-    pass
index 152a35793ea06a3bbbec93087c3661e4f517fcf4..9fa89a5bc38e9949619743f38bc750cb2de73c34 100644 (file)
@@ -6,7 +6,7 @@ import webob
 from cinder.api.openstack import wsgi
 from cinder import exception
 from cinder import test
-from cinder.tests.api.openstack import fakes
+from cinder.tests.api import fakes
 
 
 class RequestTest(test.TestCase):
index f26e9220f58e1033a1d4ce956e19626df7991d1f..03e294c71368ee3f7d9149f6bc828400cf02d5d7 100644 (file)
@@ -22,7 +22,7 @@ from cinder.api import versions
 from cinder import flags
 from cinder.openstack.common import log as logging
 from cinder import test
-from cinder.tests.api.openstack import fakes
+from cinder.tests.api import fakes
 
 FLAGS = flags.FLAGS
 
diff --git a/cinder/tests/api/v1/stubs.py b/cinder/tests/api/v1/stubs.py
new file mode 100644 (file)
index 0000000..2d8d140
--- /dev/null
@@ -0,0 +1,129 @@
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+# Copyright 2010 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 datetime
+
+from cinder import exception as exc
+
+FAKE_UUID = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'
+FAKE_UUIDS = {}
+
+
+def stub_volume(id, **kwargs):
+    volume = {
+        'id': id,
+        'user_id': 'fakeuser',
+        'project_id': 'fakeproject',
+        'host': 'fakehost',
+        'size': 1,
+        'availability_zone': 'fakeaz',
+        'instance_uuid': 'fakeuuid',
+        'mountpoint': '/',
+        'status': 'fakestatus',
+        'attach_status': 'attached',
+        'bootable': 'false',
+        'name': 'vol name',
+        'display_name': 'displayname',
+        'display_description': 'displaydesc',
+        'created_at': datetime.datetime(1, 1, 1, 1, 1, 1),
+        'snapshot_id': None,
+        'volume_type_id': '3e196c20-3c06-11e2-81c1-0800200c9a66',
+        'volume_metadata': [],
+        'volume_type': {'name': 'vol_type_name'}}
+
+    volume.update(kwargs)
+    return volume
+
+
+def stub_volume_create(self, context, size, name, description, snapshot,
+                       **param):
+    vol = stub_volume('1')
+    vol['size'] = size
+    vol['display_name'] = name
+    vol['display_description'] = description
+    try:
+        vol['snapshot_id'] = snapshot['id']
+    except (KeyError, TypeError):
+        vol['snapshot_id'] = None
+    vol['availability_zone'] = param.get('availability_zone', 'fakeaz')
+    return vol
+
+
+def stub_volume_create_from_image(self, context, size, name, description,
+                                  snapshot, volume_type, metadata,
+                                  availability_zone):
+    vol = stub_volume('1')
+    vol['status'] = 'creating'
+    vol['size'] = size
+    vol['display_name'] = name
+    vol['display_description'] = description
+    vol['availability_zone'] = 'cinder'
+    return vol
+
+
+def stub_volume_update(self, context, *args, **param):
+    pass
+
+
+def stub_volume_delete(self, context, *args, **param):
+    pass
+
+
+def stub_volume_get(self, context, volume_id):
+    return stub_volume(volume_id)
+
+
+def stub_volume_get_notfound(self, context, volume_id):
+    raise exc.NotFound
+
+
+def stub_volume_get_all(context, search_opts=None):
+    return [stub_volume(100, project_id='fake'),
+            stub_volume(101, project_id='superfake'),
+            stub_volume(102, project_id='superduperfake')]
+
+
+def stub_volume_get_all_by_project(self, context, search_opts=None):
+    return [stub_volume_get(self, context, '1')]
+
+
+def stub_snapshot(id, **kwargs):
+    snapshot = {'id': id,
+                'volume_id': 12,
+                'status': 'available',
+                'volume_size': 100,
+                'created_at': None,
+                'display_name': 'Default name',
+                'display_description': 'Default description',
+                'project_id': 'fake'}
+
+    snapshot.update(kwargs)
+    return snapshot
+
+
+def stub_snapshot_get_all(self):
+    return [stub_snapshot(100, project_id='fake'),
+            stub_snapshot(101, project_id='superfake'),
+            stub_snapshot(102, project_id='superduperfake')]
+
+
+def stub_snapshot_get_all_by_project(self, context):
+    return [stub_snapshot(1)]
+
+
+def stub_snapshot_update(self, context, *args, **param):
+    pass
index 235d41f2abc900b3ffa80b37a61d0804f1edbaab..4bfe3e61295edde54e45d06e3bed2a935705915e 100644 (file)
@@ -24,7 +24,8 @@ from cinder import exception
 from cinder import flags
 from cinder.openstack.common import log as logging
 from cinder import test
-from cinder.tests.api.openstack import fakes
+from cinder.tests.api import fakes
+from cinder.tests.api.v1 import stubs
 from cinder import volume
 
 
@@ -77,13 +78,13 @@ class SnapshotApiTest(test.TestCase):
         self.controller = snapshots.SnapshotsController()
 
         self.stubs.Set(db, 'snapshot_get_all_by_project',
-                       fakes.stub_snapshot_get_all_by_project)
+                       stubs.stub_snapshot_get_all_by_project)
         self.stubs.Set(db, 'snapshot_get_all',
-                       fakes.stub_snapshot_get_all)
+                       stubs.stub_snapshot_get_all)
 
     def test_snapshot_create(self):
         self.stubs.Set(volume.api.API, "create_snapshot", stub_snapshot_create)
-        self.stubs.Set(volume.api.API, 'get', fakes.stub_volume_get)
+        self.stubs.Set(volume.api.API, 'get', stubs.stub_volume_get)
         snapshot = {"volume_id": '12',
                     "force": False,
                     "display_name": "Snapshot Test Name",
@@ -102,7 +103,7 @@ class SnapshotApiTest(test.TestCase):
         self.stubs.Set(volume.api.API,
                        "create_snapshot_force",
                        stub_snapshot_create)
-        self.stubs.Set(volume.api.API, 'get', fakes.stub_volume_get)
+        self.stubs.Set(volume.api.API, 'get', stubs.stub_volume_get)
         snapshot = {"volume_id": '12',
                     "force": True,
                     "display_name": "Snapshot Test Name",
@@ -131,7 +132,7 @@ class SnapshotApiTest(test.TestCase):
     def test_snapshot_update(self):
         self.stubs.Set(volume.api.API, "get_snapshot", stub_snapshot_get)
         self.stubs.Set(volume.api.API, "update_snapshot",
-                       fakes.stub_snapshot_update)
+                       stubs.stub_snapshot_update)
         updates = {"display_name": "Updated Test Name", }
         body = {"snapshot": updates}
         req = fakes.HTTPRequest.blank('/v1/snapshots/%s' % UUID)
@@ -220,11 +221,11 @@ class SnapshotApiTest(test.TestCase):
     def test_snapshot_list_by_status(self):
         def stub_snapshot_get_all_by_project(context, project_id):
             return [
-                fakes.stub_snapshot(1, display_name='backup1',
+                stubs.stub_snapshot(1, display_name='backup1',
                                     status='available'),
-                fakes.stub_snapshot(2, display_name='backup2',
+                stubs.stub_snapshot(2, display_name='backup2',
                                     status='available'),
-                fakes.stub_snapshot(3, display_name='backup3',
+                stubs.stub_snapshot(3, display_name='backup3',
                                     status='creating'),
             ]
         self.stubs.Set(db, 'snapshot_get_all_by_project',
@@ -253,9 +254,9 @@ class SnapshotApiTest(test.TestCase):
     def test_snapshot_list_by_volume(self):
         def stub_snapshot_get_all_by_project(context, project_id):
             return [
-                fakes.stub_snapshot(1, volume_id='vol1', status='creating'),
-                fakes.stub_snapshot(2, volume_id='vol1', status='available'),
-                fakes.stub_snapshot(3, volume_id='vol2', status='available'),
+                stubs.stub_snapshot(1, volume_id='vol1', status='creating'),
+                stubs.stub_snapshot(2, volume_id='vol1', status='available'),
+                stubs.stub_snapshot(3, volume_id='vol2', status='available'),
             ]
         self.stubs.Set(db, 'snapshot_get_all_by_project',
                        stub_snapshot_get_all_by_project)
@@ -282,9 +283,9 @@ class SnapshotApiTest(test.TestCase):
     def test_snapshot_list_by_name(self):
         def stub_snapshot_get_all_by_project(context, project_id):
             return [
-                fakes.stub_snapshot(1, display_name='backup1'),
-                fakes.stub_snapshot(2, display_name='backup2'),
-                fakes.stub_snapshot(3, display_name='backup3'),
+                stubs.stub_snapshot(1, display_name='backup1'),
+                stubs.stub_snapshot(2, display_name='backup2'),
+                stubs.stub_snapshot(3, display_name='backup3'),
             ]
         self.stubs.Set(db, 'snapshot_get_all_by_project',
                        stub_snapshot_get_all_by_project)
index 44361e9d7449675bd1dd853f4ad04fd12195f501..97a10e7917e9fbcfca1c5469960eb425c65d3d48 100644 (file)
@@ -21,7 +21,7 @@ from cinder.api.views import types as views_types
 from cinder import exception
 from cinder.openstack.common import timeutils
 from cinder import test
-from cinder.tests.api.openstack import fakes
+from cinder.tests.api import fakes
 from cinder.volume import volume_types
 
 
index baa46f98cfaba87207fa9d08a48b845a1e891b01..fd5e7f91340677d6cdb65c35a5686d4dbc39b4f3 100644 (file)
@@ -25,7 +25,8 @@ from cinder import db
 from cinder import exception
 from cinder import flags
 from cinder import test
-from cinder.tests.api.openstack import fakes
+from cinder.tests.api import fakes
+from cinder.tests.api.v2 import stubs
 from cinder.tests.image import fake as fake_image
 from cinder.volume import api as volume_api
 
@@ -57,14 +58,14 @@ class VolumeApiTest(test.TestCase):
         fake_image.stub_out_image_service(self.stubs)
         self.controller = volumes.VolumeController(self.ext_mgr)
 
-        self.stubs.Set(db, 'volume_get_all', fakes.stub_volume_get_all)
+        self.stubs.Set(db, 'volume_get_all', stubs.stub_volume_get_all)
         self.stubs.Set(db, 'volume_get_all_by_project',
-                       fakes.stub_volume_get_all_by_project)
-        self.stubs.Set(volume_api.API, 'get', fakes.stub_volume_get)
-        self.stubs.Set(volume_api.API, 'delete', fakes.stub_volume_delete)
+                       stubs.stub_volume_get_all_by_project)
+        self.stubs.Set(volume_api.API, 'get', stubs.stub_volume_get)
+        self.stubs.Set(volume_api.API, 'delete', stubs.stub_volume_delete)
 
     def test_volume_create(self):
-        self.stubs.Set(volume_api.API, "create", fakes.stub_volume_create)
+        self.stubs.Set(volume_api.API, "create", stubs.stub_volume_create)
 
         vol = {"size": 100,
                "display_name": "Volume Test Name",
@@ -122,7 +123,7 @@ class VolumeApiTest(test.TestCase):
                           body)
 
     def test_volume_create_with_image_id(self):
-        self.stubs.Set(volume_api.API, "create", fakes.stub_volume_create)
+        self.stubs.Set(volume_api.API, "create", stubs.stub_volume_create)
         self.ext_mgr.extensions = {'os-image-create': 'fake'}
         test_id = "c905cedb-7281-47e4-8a62-f26bc5fc4c77"
         vol = {"size": '1',
@@ -153,7 +154,7 @@ class VolumeApiTest(test.TestCase):
         self.assertEqual(res_dict, expected)
 
     def test_volume_create_with_image_id_and_snapshot_id(self):
-        self.stubs.Set(volume_api.API, "create", fakes.stub_volume_create)
+        self.stubs.Set(volume_api.API, "create", stubs.stub_volume_create)
         self.stubs.Set(volume_api.API, "get_snapshot", stub_snapshot_get)
         self.ext_mgr.extensions = {'os-image-create': 'fake'}
         vol = {"size": '1',
@@ -170,7 +171,7 @@ class VolumeApiTest(test.TestCase):
                           body)
 
     def test_volume_create_with_image_id_is_integer(self):
-        self.stubs.Set(volume_api.API, "create", fakes.stub_volume_create)
+        self.stubs.Set(volume_api.API, "create", stubs.stub_volume_create)
         self.ext_mgr.extensions = {'os-image-create': 'fake'}
         vol = {"size": '1',
                "display_name": "Volume Test Name",
@@ -185,7 +186,7 @@ class VolumeApiTest(test.TestCase):
                           body)
 
     def test_volume_create_with_image_id_not_uuid_format(self):
-        self.stubs.Set(volume_api.API, "create", fakes.stub_volume_create)
+        self.stubs.Set(volume_api.API, "create", stubs.stub_volume_create)
         self.ext_mgr.extensions = {'os-image-create': 'fake'}
         vol = {"size": '1',
                "display_name": "Volume Test Name",
@@ -200,7 +201,7 @@ class VolumeApiTest(test.TestCase):
                           body)
 
     def test_volume_update(self):
-        self.stubs.Set(volume_api.API, "update", fakes.stub_volume_update)
+        self.stubs.Set(volume_api.API, "update", stubs.stub_volume_update)
         updates = {
             "display_name": "Updated Test Name",
         }
@@ -229,7 +230,7 @@ class VolumeApiTest(test.TestCase):
         self.assertEquals(res_dict, expected)
 
     def test_volume_update_metadata(self):
-        self.stubs.Set(volume_api.API, "update", fakes.stub_volume_update)
+        self.stubs.Set(volume_api.API, "update", stubs.stub_volume_update)
         updates = {
             "metadata": {"qos_max_iops": 2000}
         }
@@ -272,7 +273,7 @@ class VolumeApiTest(test.TestCase):
                           req, '1', body)
 
     def test_update_not_found(self):
-        self.stubs.Set(volume_api.API, "get", fakes.stub_volume_get_notfound)
+        self.stubs.Set(volume_api.API, "get", stubs.stub_volume_get_notfound)
         updates = {
             "display_name": "Updated Test Name",
         }
@@ -284,7 +285,7 @@ class VolumeApiTest(test.TestCase):
 
     def test_volume_list(self):
         self.stubs.Set(volume_api.API, 'get_all',
-                       fakes.stub_volume_get_all_by_project)
+                       stubs.stub_volume_get_all_by_project)
 
         req = fakes.HTTPRequest.blank('/v1/volumes')
         res_dict = self.controller.index(req)
@@ -308,7 +309,7 @@ class VolumeApiTest(test.TestCase):
 
     def test_volume_list_detail(self):
         self.stubs.Set(volume_api.API, 'get_all',
-                       fakes.stub_volume_get_all_by_project)
+                       stubs.stub_volume_get_all_by_project)
         req = fakes.HTTPRequest.blank('/v1/volumes/detail')
         res_dict = self.controller.index(req)
         expected = {'volumes': [{'status': 'fakestatus',
@@ -332,9 +333,9 @@ class VolumeApiTest(test.TestCase):
     def test_volume_list_by_name(self):
         def stub_volume_get_all_by_project(context, project_id):
             return [
-                fakes.stub_volume(1, display_name='vol1'),
-                fakes.stub_volume(2, display_name='vol2'),
-                fakes.stub_volume(3, display_name='vol3'),
+                stubs.stub_volume(1, display_name='vol1'),
+                stubs.stub_volume(2, display_name='vol2'),
+                stubs.stub_volume(3, display_name='vol3'),
             ]
         self.stubs.Set(db, 'volume_get_all_by_project',
                        stub_volume_get_all_by_project)
@@ -356,9 +357,9 @@ class VolumeApiTest(test.TestCase):
     def test_volume_list_by_status(self):
         def stub_volume_get_all_by_project(context, project_id):
             return [
-                fakes.stub_volume(1, display_name='vol1', status='available'),
-                fakes.stub_volume(2, display_name='vol2', status='available'),
-                fakes.stub_volume(3, display_name='vol3', status='in-use'),
+                stubs.stub_volume(1, display_name='vol1', status='available'),
+                stubs.stub_volume(2, display_name='vol2', status='available'),
+                stubs.stub_volume(3, display_name='vol3', status='in-use'),
             ]
         self.stubs.Set(db, 'volume_get_all_by_project',
                        stub_volume_get_all_by_project)
@@ -413,7 +414,7 @@ class VolumeApiTest(test.TestCase):
 
     def test_volume_show_no_attachments(self):
         def stub_volume_get(self, context, volume_id):
-            return fakes.stub_volume(volume_id, attach_status='detached')
+            return stubs.stub_volume(volume_id, attach_status='detached')
 
         self.stubs.Set(volume_api.API, 'get', stub_volume_get)
 
@@ -436,7 +437,7 @@ class VolumeApiTest(test.TestCase):
 
     def test_volume_show_bootable(self):
         def stub_volume_get(self, context, volume_id):
-            return (fakes.stub_volume(volume_id,
+            return (stubs.stub_volume(volume_id,
                     volume_glance_metadata=dict(foo='bar')))
 
         self.stubs.Set(volume_api.API, 'get', stub_volume_get)
@@ -462,7 +463,7 @@ class VolumeApiTest(test.TestCase):
         self.assertEqual(res_dict, expected)
 
     def test_volume_show_no_volume(self):
-        self.stubs.Set(volume_api.API, "get", fakes.stub_volume_get_notfound)
+        self.stubs.Set(volume_api.API, "get", stubs.stub_volume_get_notfound)
 
         req = fakes.HTTPRequest.blank('/v1/volumes/1')
         self.assertRaises(webob.exc.HTTPNotFound,
@@ -476,7 +477,7 @@ class VolumeApiTest(test.TestCase):
         self.assertEqual(resp.status_int, 202)
 
     def test_volume_delete_no_volume(self):
-        self.stubs.Set(volume_api.API, "get", fakes.stub_volume_get_notfound)
+        self.stubs.Set(volume_api.API, "get", stubs.stub_volume_get_notfound)
 
         req = fakes.HTTPRequest.blank('/v1/volumes/1')
         self.assertRaises(webob.exc.HTTPNotFound,
diff --git a/cinder/tests/api/v2/stubs.py b/cinder/tests/api/v2/stubs.py
new file mode 100644 (file)
index 0000000..2d8d140
--- /dev/null
@@ -0,0 +1,129 @@
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+# Copyright 2010 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 datetime
+
+from cinder import exception as exc
+
+FAKE_UUID = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'
+FAKE_UUIDS = {}
+
+
+def stub_volume(id, **kwargs):
+    volume = {
+        'id': id,
+        'user_id': 'fakeuser',
+        'project_id': 'fakeproject',
+        'host': 'fakehost',
+        'size': 1,
+        'availability_zone': 'fakeaz',
+        'instance_uuid': 'fakeuuid',
+        'mountpoint': '/',
+        'status': 'fakestatus',
+        'attach_status': 'attached',
+        'bootable': 'false',
+        'name': 'vol name',
+        'display_name': 'displayname',
+        'display_description': 'displaydesc',
+        'created_at': datetime.datetime(1, 1, 1, 1, 1, 1),
+        'snapshot_id': None,
+        'volume_type_id': '3e196c20-3c06-11e2-81c1-0800200c9a66',
+        'volume_metadata': [],
+        'volume_type': {'name': 'vol_type_name'}}
+
+    volume.update(kwargs)
+    return volume
+
+
+def stub_volume_create(self, context, size, name, description, snapshot,
+                       **param):
+    vol = stub_volume('1')
+    vol['size'] = size
+    vol['display_name'] = name
+    vol['display_description'] = description
+    try:
+        vol['snapshot_id'] = snapshot['id']
+    except (KeyError, TypeError):
+        vol['snapshot_id'] = None
+    vol['availability_zone'] = param.get('availability_zone', 'fakeaz')
+    return vol
+
+
+def stub_volume_create_from_image(self, context, size, name, description,
+                                  snapshot, volume_type, metadata,
+                                  availability_zone):
+    vol = stub_volume('1')
+    vol['status'] = 'creating'
+    vol['size'] = size
+    vol['display_name'] = name
+    vol['display_description'] = description
+    vol['availability_zone'] = 'cinder'
+    return vol
+
+
+def stub_volume_update(self, context, *args, **param):
+    pass
+
+
+def stub_volume_delete(self, context, *args, **param):
+    pass
+
+
+def stub_volume_get(self, context, volume_id):
+    return stub_volume(volume_id)
+
+
+def stub_volume_get_notfound(self, context, volume_id):
+    raise exc.NotFound
+
+
+def stub_volume_get_all(context, search_opts=None):
+    return [stub_volume(100, project_id='fake'),
+            stub_volume(101, project_id='superfake'),
+            stub_volume(102, project_id='superduperfake')]
+
+
+def stub_volume_get_all_by_project(self, context, search_opts=None):
+    return [stub_volume_get(self, context, '1')]
+
+
+def stub_snapshot(id, **kwargs):
+    snapshot = {'id': id,
+                'volume_id': 12,
+                'status': 'available',
+                'volume_size': 100,
+                'created_at': None,
+                'display_name': 'Default name',
+                'display_description': 'Default description',
+                'project_id': 'fake'}
+
+    snapshot.update(kwargs)
+    return snapshot
+
+
+def stub_snapshot_get_all(self):
+    return [stub_snapshot(100, project_id='fake'),
+            stub_snapshot(101, project_id='superfake'),
+            stub_snapshot(102, project_id='superduperfake')]
+
+
+def stub_snapshot_get_all_by_project(self, context):
+    return [stub_snapshot(1)]
+
+
+def stub_snapshot_update(self, context, *args, **param):
+    pass
index 043dee7f325d7e7969ffd5f4e83a806652f08e0a..aa9b1a9b235d51c5c3cf88ba6dfddcc73a4579c1 100644 (file)
@@ -24,7 +24,8 @@ from cinder import exception
 from cinder import flags
 from cinder.openstack.common import log as logging
 from cinder import test
-from cinder.tests.api.openstack import fakes
+from cinder.tests.api import fakes
+from cinder.tests.api.v2 import stubs
 from cinder import volume
 
 
@@ -79,13 +80,13 @@ class SnapshotApiTest(test.TestCase):
         self.controller = snapshots.SnapshotsController()
 
         self.stubs.Set(db, 'snapshot_get_all_by_project',
-                       fakes.stub_snapshot_get_all_by_project)
+                       stubs.stub_snapshot_get_all_by_project)
         self.stubs.Set(db, 'snapshot_get_all',
-                       fakes.stub_snapshot_get_all)
+                       stubs.stub_snapshot_get_all)
 
     def test_snapshot_create(self):
         self.stubs.Set(volume.api.API, "create_snapshot", stub_snapshot_create)
-        self.stubs.Set(volume.api.API, 'get', fakes.stub_volume_get)
+        self.stubs.Set(volume.api.API, 'get', stubs.stub_volume_get)
         snapshot = {
             "volume_id": '12',
             "force": False,
@@ -105,7 +106,7 @@ class SnapshotApiTest(test.TestCase):
     def test_snapshot_create_force(self):
         self.stubs.Set(volume.api.API, "create_snapshot_force",
                        stub_snapshot_create)
-        self.stubs.Set(volume.api.API, 'get', fakes.stub_volume_get)
+        self.stubs.Set(volume.api.API, 'get', stubs.stub_volume_get)
         snapshot = {
             "volume_id": '12',
             "force": True,
@@ -138,7 +139,7 @@ class SnapshotApiTest(test.TestCase):
     def test_snapshot_update(self):
         self.stubs.Set(volume.api.API, "get_snapshot", stub_snapshot_get)
         self.stubs.Set(volume.api.API, "update_snapshot",
-                       fakes.stub_snapshot_update)
+                       stubs.stub_snapshot_update)
         updates = {
             "display_name": "Updated Test Name",
         }
@@ -226,11 +227,11 @@ class SnapshotApiTest(test.TestCase):
     def test_snapshot_list_by_status(self):
         def stub_snapshot_get_all_by_project(context, project_id):
             return [
-                fakes.stub_snapshot(1, display_name='backup1',
+                stubs.stub_snapshot(1, display_name='backup1',
                                     status='available'),
-                fakes.stub_snapshot(2, display_name='backup2',
+                stubs.stub_snapshot(2, display_name='backup2',
                                     status='available'),
-                fakes.stub_snapshot(3, display_name='backup3',
+                stubs.stub_snapshot(3, display_name='backup3',
                                     status='creating'),
             ]
         self.stubs.Set(db, 'snapshot_get_all_by_project',
@@ -259,9 +260,9 @@ class SnapshotApiTest(test.TestCase):
     def test_snapshot_list_by_volume(self):
         def stub_snapshot_get_all_by_project(context, project_id):
             return [
-                fakes.stub_snapshot(1, volume_id='vol1', status='creating'),
-                fakes.stub_snapshot(2, volume_id='vol1', status='available'),
-                fakes.stub_snapshot(3, volume_id='vol2', status='available'),
+                stubs.stub_snapshot(1, volume_id='vol1', status='creating'),
+                stubs.stub_snapshot(2, volume_id='vol1', status='available'),
+                stubs.stub_snapshot(3, volume_id='vol2', status='available'),
             ]
         self.stubs.Set(db, 'snapshot_get_all_by_project',
                        stub_snapshot_get_all_by_project)
@@ -288,9 +289,9 @@ class SnapshotApiTest(test.TestCase):
     def test_snapshot_list_by_name(self):
         def stub_snapshot_get_all_by_project(context, project_id):
             return [
-                fakes.stub_snapshot(1, display_name='backup1'),
-                fakes.stub_snapshot(2, display_name='backup2'),
-                fakes.stub_snapshot(3, display_name='backup3'),
+                stubs.stub_snapshot(1, display_name='backup1'),
+                stubs.stub_snapshot(2, display_name='backup2'),
+                stubs.stub_snapshot(3, display_name='backup3'),
             ]
         self.stubs.Set(db, 'snapshot_get_all_by_project',
                        stub_snapshot_get_all_by_project)
index bdc3fa25e749eb2095b985a31d66fe3786397fad..1a3849f822490a01d688fa435598c79e3912fdd7 100644 (file)
@@ -21,7 +21,7 @@ from cinder.api.views import types as views_types
 from cinder import exception
 from cinder.openstack.common import timeutils
 from cinder import test
-from cinder.tests.api.openstack import fakes
+from cinder.tests.api import fakes
 from cinder.volume import volume_types
 
 
index b4539ebda30334050c64fc1c69fb4f7139b30bc1..b5f52d15ebf66332e8c8245d014be22c097d7e3e 100644 (file)
@@ -25,7 +25,8 @@ from cinder import db
 from cinder import exception
 from cinder import flags
 from cinder import test
-from cinder.tests.api.openstack import fakes
+from cinder.tests.api import fakes
+from cinder.tests.api.v2 import stubs
 from cinder.tests.image import fake as fake_image
 from cinder.volume import api as volume_api
 
@@ -59,14 +60,14 @@ class VolumeApiTest(test.TestCase):
         fake_image.stub_out_image_service(self.stubs)
         self.controller = volumes.VolumeController(self.ext_mgr)
 
-        self.stubs.Set(db, 'volume_get_all', fakes.stub_volume_get_all)
+        self.stubs.Set(db, 'volume_get_all', stubs.stub_volume_get_all)
         self.stubs.Set(db, 'volume_get_all_by_project',
-                       fakes.stub_volume_get_all_by_project)
-        self.stubs.Set(volume_api.API, 'get', fakes.stub_volume_get)
-        self.stubs.Set(volume_api.API, 'delete', fakes.stub_volume_delete)
+                       stubs.stub_volume_get_all_by_project)
+        self.stubs.Set(volume_api.API, 'get', stubs.stub_volume_get)
+        self.stubs.Set(volume_api.API, 'delete', stubs.stub_volume_delete)
 
     def test_volume_create(self):
-        self.stubs.Set(volume_api.API, "create", fakes.stub_volume_create)
+        self.stubs.Set(volume_api.API, "create", stubs.stub_volume_create)
 
         vol = {
             "size": 100,
@@ -135,7 +136,7 @@ class VolumeApiTest(test.TestCase):
                           body)
 
     def test_volume_create_with_image_id(self):
-        self.stubs.Set(volume_api.API, "create", fakes.stub_volume_create)
+        self.stubs.Set(volume_api.API, "create", stubs.stub_volume_create)
         self.ext_mgr.extensions = {'os-image-create': 'fake'}
         vol = {"size": '1',
                "display_name": "Volume Test Name",
@@ -170,7 +171,7 @@ class VolumeApiTest(test.TestCase):
         self.assertEqual(res_dict, expected)
 
     def test_volume_create_with_image_id_and_snapshot_id(self):
-        self.stubs.Set(volume_api.API, "create", fakes.stub_volume_create)
+        self.stubs.Set(volume_api.API, "create", stubs.stub_volume_create)
         self.stubs.Set(volume_api.API, "get_snapshot", stub_snapshot_get)
         self.ext_mgr.extensions = {'os-image-create': 'fake'}
         vol = {
@@ -189,7 +190,7 @@ class VolumeApiTest(test.TestCase):
                           body)
 
     def test_volume_create_with_image_id_is_integer(self):
-        self.stubs.Set(volume_api.API, "create", fakes.stub_volume_create)
+        self.stubs.Set(volume_api.API, "create", stubs.stub_volume_create)
         self.ext_mgr.extensions = {'os-image-create': 'fake'}
         vol = {
             "size": '1',
@@ -206,7 +207,7 @@ class VolumeApiTest(test.TestCase):
                           body)
 
     def test_volume_create_with_image_id_not_uuid_format(self):
-        self.stubs.Set(volume_api.API, "create", fakes.stub_volume_create)
+        self.stubs.Set(volume_api.API, "create", stubs.stub_volume_create)
         self.ext_mgr.extensions = {'os-image-create': 'fake'}
         vol = {
             "size": '1',
@@ -223,7 +224,7 @@ class VolumeApiTest(test.TestCase):
                           body)
 
     def test_volume_update(self):
-        self.stubs.Set(volume_api.API, "update", fakes.stub_volume_update)
+        self.stubs.Set(volume_api.API, "update", stubs.stub_volume_update)
         updates = {
             "display_name": "Updated Test Name",
         }
@@ -255,7 +256,7 @@ class VolumeApiTest(test.TestCase):
         self.assertEquals(res_dict, expected)
 
     def test_volume_update_metadata(self):
-        self.stubs.Set(volume_api.API, "update", fakes.stub_volume_update)
+        self.stubs.Set(volume_api.API, "update", stubs.stub_volume_update)
         updates = {
             "metadata": {"qos_max_iops": 2000}
         }
@@ -299,7 +300,7 @@ class VolumeApiTest(test.TestCase):
                           req, '1', body)
 
     def test_update_not_found(self):
-        self.stubs.Set(volume_api.API, "get", fakes.stub_volume_get_notfound)
+        self.stubs.Set(volume_api.API, "get", stubs.stub_volume_get_notfound)
         updates = {
             "display_name": "Updated Test Name",
         }
@@ -311,7 +312,7 @@ class VolumeApiTest(test.TestCase):
 
     def test_volume_list(self):
         self.stubs.Set(volume_api.API, 'get_all',
-                       fakes.stub_volume_get_all_by_project)
+                       stubs.stub_volume_get_all_by_project)
 
         req = fakes.HTTPRequest.blank('/v2/volumes')
         res_dict = self.controller.index(req)
@@ -343,7 +344,7 @@ class VolumeApiTest(test.TestCase):
 
     def test_volume_list_detail(self):
         self.stubs.Set(volume_api.API, 'get_all',
-                       fakes.stub_volume_get_all_by_project)
+                       stubs.stub_volume_get_all_by_project)
         req = fakes.HTTPRequest.blank('/v2/volumes/detail')
         res_dict = self.controller.index(req)
         expected = {
@@ -375,9 +376,9 @@ class VolumeApiTest(test.TestCase):
     def test_volume_list_by_name(self):
         def stub_volume_get_all_by_project(context, project_id):
             return [
-                fakes.stub_volume(1, display_name='vol1'),
-                fakes.stub_volume(2, display_name='vol2'),
-                fakes.stub_volume(3, display_name='vol3'),
+                stubs.stub_volume(1, display_name='vol1'),
+                stubs.stub_volume(2, display_name='vol2'),
+                stubs.stub_volume(3, display_name='vol3'),
             ]
         self.stubs.Set(db, 'volume_get_all_by_project',
                        stub_volume_get_all_by_project)
@@ -399,9 +400,9 @@ class VolumeApiTest(test.TestCase):
     def test_volume_list_by_status(self):
         def stub_volume_get_all_by_project(context, project_id):
             return [
-                fakes.stub_volume(1, display_name='vol1', status='available'),
-                fakes.stub_volume(2, display_name='vol2', status='available'),
-                fakes.stub_volume(3, display_name='vol3', status='in-use'),
+                stubs.stub_volume(1, display_name='vol1', status='available'),
+                stubs.stub_volume(2, display_name='vol2', status='available'),
+                stubs.stub_volume(3, display_name='vol3', status='in-use'),
             ]
         self.stubs.Set(db, 'volume_get_all_by_project',
                        stub_volume_get_all_by_project)
@@ -462,7 +463,7 @@ class VolumeApiTest(test.TestCase):
 
     def test_volume_show_no_attachments(self):
         def stub_volume_get(self, context, volume_id):
-            return fakes.stub_volume(volume_id, attach_status='detached')
+            return stubs.stub_volume(volume_id, attach_status='detached')
 
         self.stubs.Set(volume_api.API, 'get', stub_volume_get)
 
@@ -486,7 +487,7 @@ class VolumeApiTest(test.TestCase):
         self.assertEqual(res_dict, expected)
 
     def test_volume_show_no_volume(self):
-        self.stubs.Set(volume_api.API, "get", fakes.stub_volume_get_notfound)
+        self.stubs.Set(volume_api.API, "get", stubs.stub_volume_get_notfound)
 
         req = fakes.HTTPRequest.blank('/v2/volumes/1')
         self.assertRaises(webob.exc.HTTPNotFound, self.controller.show,
@@ -498,7 +499,7 @@ class VolumeApiTest(test.TestCase):
         self.assertEqual(resp.status_int, 202)
 
     def test_volume_delete_no_volume(self):
-        self.stubs.Set(volume_api.API, "get", fakes.stub_volume_get_notfound)
+        self.stubs.Set(volume_api.API, "get", stubs.stub_volume_get_notfound)
 
         req = fakes.HTTPRequest.blank('/v2/volumes/1')
         self.assertRaises(webob.exc.HTTPNotFound, self.controller.delete,
index d0402c8bed163f2e622c35a3088426c4406335db..2bffc6ba84a2a5537b40f35082838ca9d8de5242 100644 (file)
@@ -26,7 +26,6 @@ from cinder import context
 from cinder import exception
 from cinder.image import glance
 from cinder import test
-from cinder.tests.api.openstack import fakes
 from cinder.tests.glance import stubs as glance_stubs