]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Cleanup for cinder tests with CGSnapshot
authorDaniel Tadrzak <daniel.tadrzak@intel.com>
Fri, 31 Jul 2015 12:31:14 +0000 (14:31 +0200)
committerSzymon Wroblewski <szymon.wroblewski@intel.com>
Tue, 20 Oct 2015 09:08:06 +0000 (11:08 +0200)
Switch cinder tests to use CGSnapshot objects instead of direct
calls to db. Additionally, the patch switches from dict to object notation.

Drivers tests need to be fixed in other patch.

Co-Authored-By: Szymon Wroblewski<szymon.wroblewski@intel.com>
Partial-Implements: blueprint cinder-objects
Change-Id: I40161592c887a386aa7a323381d71f0111d584fa

cinder/tests/unit/api/contrib/test_cgsnapshots.py
cinder/tests/unit/api/contrib/test_consistencygroups.py
cinder/tests/unit/test_storwize_svc.py

index 2eab1e4416351ff2da0473b7921fc1dc86a6ccb3..7ba5bcb9f08941bf12fd2b52ca91e5331eeed6f6 100644 (file)
@@ -27,6 +27,7 @@ from cinder.consistencygroup import api as consistencygroupAPI
 from cinder import context
 from cinder import db
 from cinder import exception
+from cinder import objects
 from cinder import test
 from cinder.tests.unit.api import fakes
 from cinder.tests.unit import utils
@@ -43,37 +44,15 @@ class CgsnapshotsAPITestCase(test.TestCase):
         self.context.project_id = 'fake'
         self.context.user_id = 'fake'
 
-    @staticmethod
-    def _create_cgsnapshot(
-            name='test_cgsnapshot',
-            description='this is a test cgsnapshot',
-            consistencygroup_id='1',
-            status='creating'):
-        """Create a cgsnapshot object."""
-        cgsnapshot = {}
-        cgsnapshot['user_id'] = 'fake'
-        cgsnapshot['project_id'] = 'fake'
-        cgsnapshot['consistencygroup_id'] = consistencygroup_id
-        cgsnapshot['name'] = name
-        cgsnapshot['description'] = description
-        cgsnapshot['status'] = status
-        return db.cgsnapshot_create(context.get_admin_context(),
-                                    cgsnapshot)['id']
-
-    @staticmethod
-    def _get_cgsnapshot_attrib(cgsnapshot_id, attrib_name):
-        return db.cgsnapshot_get(context.get_admin_context(),
-                                 cgsnapshot_id)[attrib_name]
-
     def test_show_cgsnapshot(self):
         consistencygroup = utils.create_consistencygroup(self.context)
         volume_id = utils.create_volume(self.context,
                                         consistencygroup_id=
                                         consistencygroup.id)['id']
-        cgsnapshot_id = self._create_cgsnapshot(
-            consistencygroup_id=consistencygroup.id)
+        cgsnapshot = utils.create_cgsnapshot(
+            self.context, consistencygroup_id=consistencygroup.id)
         req = webob.Request.blank('/v2/fake/cgsnapshots/%s' %
-                                  cgsnapshot_id)
+                                  cgsnapshot.id)
         req.method = 'GET'
         req.headers['Content-Type'] = 'application/json'
         res = req.get_response(fakes.wsgi_app())
@@ -87,8 +66,7 @@ class CgsnapshotsAPITestCase(test.TestCase):
                          res_dict['cgsnapshot']['name'])
         self.assertEqual('creating', res_dict['cgsnapshot']['status'])
 
-        db.cgsnapshot_destroy(context.get_admin_context(),
-                              cgsnapshot_id)
+        cgsnapshot.destroy()
         db.volume_destroy(context.get_admin_context(),
                           volume_id)
         consistencygroup.destroy()
@@ -98,21 +76,21 @@ class CgsnapshotsAPITestCase(test.TestCase):
         volume_id = utils.create_volume(self.context,
                                         consistencygroup_id=
                                         consistencygroup.id)['id']
-        cgsnapshot_id = self._create_cgsnapshot(
-            consistencygroup_id=consistencygroup.id)
+        cgsnapshot = utils.create_cgsnapshot(
+            self.context, consistencygroup_id=consistencygroup.id)
         req = webob.Request.blank('/v2/fake/cgsnapshots/%s' %
-                                  cgsnapshot_id)
+                                  cgsnapshot.id)
         req.method = 'GET'
         req.headers['Content-Type'] = 'application/xml'
         req.headers['Accept'] = 'application/xml'
         res = req.get_response(fakes.wsgi_app())
         self.assertEqual(200, res.status_int)
         dom = minidom.parseString(res.body)
-        cgsnapshot = dom.getElementsByTagName('cgsnapshot')
-        name = cgsnapshot.item(0).getAttribute('name')
-        self.assertEqual('test_cgsnapshot', name.strip())
-        db.cgsnapshot_destroy(context.get_admin_context(),
-                              cgsnapshot_id)
+
+        cgsnapshots = dom.getElementsByTagName('cgsnapshot')
+        name = cgsnapshots.item(0).getAttribute('name')
+        self.assertEqual("test_cgsnapshot", name.strip())
+        cgsnapshot.destroy()
         db.volume_destroy(context.get_admin_context(),
                           volume_id)
         consistencygroup.destroy()
@@ -134,12 +112,12 @@ class CgsnapshotsAPITestCase(test.TestCase):
         volume_id = utils.create_volume(self.context,
                                         consistencygroup_id=
                                         consistencygroup.id)['id']
-        cgsnapshot_id1 = self._create_cgsnapshot(
-            consistencygroup_id=consistencygroup.id)
-        cgsnapshot_id2 = self._create_cgsnapshot(
-            consistencygroup_id=consistencygroup.id)
-        cgsnapshot_id3 = self._create_cgsnapshot(
-            consistencygroup_id=consistencygroup.id)
+        cgsnapshot1 = utils.create_cgsnapshot(
+            self.context, consistencygroup_id=consistencygroup.id)
+        cgsnapshot2 = utils.create_cgsnapshot(
+            self.context, consistencygroup_id=consistencygroup.id)
+        cgsnapshot3 = utils.create_cgsnapshot(
+            self.context, consistencygroup_id=consistencygroup.id)
 
         req = webob.Request.blank('/v2/fake/cgsnapshots')
         req.method = 'GET'
@@ -148,25 +126,22 @@ class CgsnapshotsAPITestCase(test.TestCase):
         res_dict = json.loads(res.body)
 
         self.assertEqual(200, res.status_int)
-        self.assertEqual(cgsnapshot_id1,
+        self.assertEqual(cgsnapshot1.id,
                          res_dict['cgsnapshots'][0]['id'])
         self.assertEqual('test_cgsnapshot',
                          res_dict['cgsnapshots'][0]['name'])
-        self.assertEqual(cgsnapshot_id2,
+        self.assertEqual(cgsnapshot2.id,
                          res_dict['cgsnapshots'][1]['id'])
         self.assertEqual('test_cgsnapshot',
                          res_dict['cgsnapshots'][1]['name'])
-        self.assertEqual(cgsnapshot_id3,
+        self.assertEqual(cgsnapshot3.id,
                          res_dict['cgsnapshots'][2]['id'])
         self.assertEqual('test_cgsnapshot',
                          res_dict['cgsnapshots'][2]['name'])
 
-        db.cgsnapshot_destroy(context.get_admin_context(),
-                              cgsnapshot_id3)
-        db.cgsnapshot_destroy(context.get_admin_context(),
-                              cgsnapshot_id2)
-        db.cgsnapshot_destroy(context.get_admin_context(),
-                              cgsnapshot_id1)
+        cgsnapshot3.destroy()
+        cgsnapshot2.destroy()
+        cgsnapshot1.destroy()
         db.volume_destroy(context.get_admin_context(),
                           volume_id)
         consistencygroup.destroy()
@@ -176,12 +151,12 @@ class CgsnapshotsAPITestCase(test.TestCase):
         volume_id = utils.create_volume(self.context,
                                         consistencygroup_id=
                                         consistencygroup.id)['id']
-        cgsnapshot_id1 = self._create_cgsnapshot(consistencygroup_id=
-                                                 consistencygroup.id)
-        cgsnapshot_id2 = self._create_cgsnapshot(consistencygroup_id=
-                                                 consistencygroup.id)
-        cgsnapshot_id3 = self._create_cgsnapshot(consistencygroup_id=
-                                                 consistencygroup.id)
+        cgsnapshot1 = utils.create_cgsnapshot(
+            self.context, consistencygroup_id=consistencygroup.id)
+        cgsnapshot2 = utils.create_cgsnapshot(
+            self.context, consistencygroup_id=consistencygroup.id)
+        cgsnapshot3 = utils.create_cgsnapshot(
+            self.context, consistencygroup_id=consistencygroup.id)
 
         req = webob.Request.blank('/v2/fake/cgsnapshots')
         req.method = 'GET'
@@ -193,19 +168,16 @@ class CgsnapshotsAPITestCase(test.TestCase):
         dom = minidom.parseString(res.body)
         cgsnapshot_list = dom.getElementsByTagName('cgsnapshot')
 
-        self.assertEqual(cgsnapshot_id1,
+        self.assertEqual(cgsnapshot1.id,
                          cgsnapshot_list.item(0).getAttribute('id'))
-        self.assertEqual(cgsnapshot_id2,
+        self.assertEqual(cgsnapshot2.id,
                          cgsnapshot_list.item(1).getAttribute('id'))
-        self.assertEqual(cgsnapshot_id3,
+        self.assertEqual(cgsnapshot3.id,
                          cgsnapshot_list.item(2).getAttribute('id'))
 
-        db.cgsnapshot_destroy(context.get_admin_context(),
-                              cgsnapshot_id3)
-        db.cgsnapshot_destroy(context.get_admin_context(),
-                              cgsnapshot_id2)
-        db.cgsnapshot_destroy(context.get_admin_context(),
-                              cgsnapshot_id1)
+        cgsnapshot3.destroy()
+        cgsnapshot2.destroy()
+        cgsnapshot1.destroy()
         db.volume_destroy(context.get_admin_context(),
                           volume_id)
         consistencygroup.destroy()
@@ -215,12 +187,12 @@ class CgsnapshotsAPITestCase(test.TestCase):
         volume_id = utils.create_volume(self.context,
                                         consistencygroup_id=
                                         consistencygroup.id)['id']
-        cgsnapshot_id1 = self._create_cgsnapshot(consistencygroup_id=
-                                                 consistencygroup.id)
-        cgsnapshot_id2 = self._create_cgsnapshot(consistencygroup_id=
-                                                 consistencygroup.id)
-        cgsnapshot_id3 = self._create_cgsnapshot(consistencygroup_id=
-                                                 consistencygroup.id)
+        cgsnapshot1 = utils.create_cgsnapshot(
+            self.context, consistencygroup_id=consistencygroup.id)
+        cgsnapshot2 = utils.create_cgsnapshot(
+            self.context, consistencygroup_id=consistencygroup.id)
+        cgsnapshot3 = utils.create_cgsnapshot(
+            self.context, consistencygroup_id=consistencygroup.id)
 
         req = webob.Request.blank('/v2/fake/cgsnapshots/detail')
         req.method = 'GET'
@@ -234,7 +206,7 @@ class CgsnapshotsAPITestCase(test.TestCase):
                          res_dict['cgsnapshots'][0]['description'])
         self.assertEqual('test_cgsnapshot',
                          res_dict['cgsnapshots'][0]['name'])
-        self.assertEqual(cgsnapshot_id1,
+        self.assertEqual(cgsnapshot1.id,
                          res_dict['cgsnapshots'][0]['id'])
         self.assertEqual('creating',
                          res_dict['cgsnapshots'][0]['status'])
@@ -243,7 +215,7 @@ class CgsnapshotsAPITestCase(test.TestCase):
                          res_dict['cgsnapshots'][1]['description'])
         self.assertEqual('test_cgsnapshot',
                          res_dict['cgsnapshots'][1]['name'])
-        self.assertEqual(cgsnapshot_id2,
+        self.assertEqual(cgsnapshot2.id,
                          res_dict['cgsnapshots'][1]['id'])
         self.assertEqual('creating',
                          res_dict['cgsnapshots'][1]['status'])
@@ -252,16 +224,14 @@ class CgsnapshotsAPITestCase(test.TestCase):
                          res_dict['cgsnapshots'][2]['description'])
         self.assertEqual('test_cgsnapshot',
                          res_dict['cgsnapshots'][2]['name'])
-        self.assertEqual(cgsnapshot_id3,
+        self.assertEqual(cgsnapshot3.id,
                          res_dict['cgsnapshots'][2]['id'])
         self.assertEqual('creating',
                          res_dict['cgsnapshots'][2]['status'])
-        db.cgsnapshot_destroy(context.get_admin_context(),
-                              cgsnapshot_id3)
-        db.cgsnapshot_destroy(context.get_admin_context(),
-                              cgsnapshot_id2)
-        db.cgsnapshot_destroy(context.get_admin_context(),
-                              cgsnapshot_id1)
+
+        cgsnapshot3.destroy()
+        cgsnapshot2.destroy()
+        cgsnapshot1.destroy()
         db.volume_destroy(context.get_admin_context(),
                           volume_id)
         consistencygroup.destroy()
@@ -271,12 +241,12 @@ class CgsnapshotsAPITestCase(test.TestCase):
         volume_id = utils.create_volume(self.context,
                                         consistencygroup_id=
                                         consistencygroup.id)['id']
-        cgsnapshot_id1 = self._create_cgsnapshot(consistencygroup_id=
-                                                 consistencygroup.id)
-        cgsnapshot_id2 = self._create_cgsnapshot(consistencygroup_id=
-                                                 consistencygroup.id)
-        cgsnapshot_id3 = self._create_cgsnapshot(consistencygroup_id=
-                                                 consistencygroup.id)
+        cgsnapshot1 = utils.create_cgsnapshot(
+            self.context, consistencygroup_id=consistencygroup.id)
+        cgsnapshot2 = utils.create_cgsnapshot(
+            self.context, consistencygroup_id=consistencygroup.id)
+        cgsnapshot3 = utils.create_cgsnapshot(
+            self.context, consistencygroup_id=consistencygroup.id)
 
         req = webob.Request.blank('/v2/fake/cgsnapshots/detail')
         req.method = 'GET'
@@ -288,39 +258,45 @@ class CgsnapshotsAPITestCase(test.TestCase):
         dom = minidom.parseString(res.body)
         cgsnapshot_detail = dom.getElementsByTagName('cgsnapshot')
 
-        self.assertEqual('this is a test cgsnapshot',
-                         cgsnapshot_detail.item(0).getAttribute('description'))
-        self.assertEqual('test_cgsnapshot',
-                         cgsnapshot_detail.item(0).getAttribute('name'))
-        self.assertEqual(cgsnapshot_id1,
-                         cgsnapshot_detail.item(0).getAttribute('id'))
-        self.assertEqual('creating',
-                         cgsnapshot_detail.item(0).getAttribute('status'))
-
-        self.assertEqual('this is a test cgsnapshot',
-                         cgsnapshot_detail.item(1).getAttribute('description'))
-        self.assertEqual('test_cgsnapshot',
-                         cgsnapshot_detail.item(1).getAttribute('name'))
-        self.assertEqual(cgsnapshot_id2,
-                         cgsnapshot_detail.item(1).getAttribute('id'))
-        self.assertEqual('creating',
-                         cgsnapshot_detail.item(1).getAttribute('status'))
-
-        self.assertEqual('this is a test cgsnapshot',
-                         cgsnapshot_detail.item(2).getAttribute('description'))
-        self.assertEqual('test_cgsnapshot',
-                         cgsnapshot_detail.item(2).getAttribute('name'))
-        self.assertEqual(cgsnapshot_id3,
-                         cgsnapshot_detail.item(2).getAttribute('id'))
-        self.assertEqual('creating',
-                         cgsnapshot_detail.item(2).getAttribute('status'))
-
-        db.cgsnapshot_destroy(context.get_admin_context(),
-                              cgsnapshot_id3)
-        db.cgsnapshot_destroy(context.get_admin_context(),
-                              cgsnapshot_id2)
-        db.cgsnapshot_destroy(context.get_admin_context(),
-                              cgsnapshot_id1)
+        self.assertEqual(
+            'this is a test cgsnapshot',
+            cgsnapshot_detail.item(0).getAttribute('description'))
+        self.assertEqual(
+            'test_cgsnapshot',
+            cgsnapshot_detail.item(0).getAttribute('name'))
+        self.assertEqual(
+            cgsnapshot1.id,
+            cgsnapshot_detail.item(0).getAttribute('id'))
+        self.assertEqual(
+            'creating', cgsnapshot_detail.item(0).getAttribute('status'))
+
+        self.assertEqual(
+            'this is a test cgsnapshot',
+            cgsnapshot_detail.item(1).getAttribute('description'))
+        self.assertEqual(
+            'test_cgsnapshot',
+            cgsnapshot_detail.item(1).getAttribute('name'))
+        self.assertEqual(
+            cgsnapshot2.id,
+            cgsnapshot_detail.item(1).getAttribute('id'))
+        self.assertEqual(
+            'creating', cgsnapshot_detail.item(1).getAttribute('status'))
+
+        self.assertEqual(
+            'this is a test cgsnapshot',
+            cgsnapshot_detail.item(2).getAttribute('description'))
+        self.assertEqual(
+            'test_cgsnapshot',
+            cgsnapshot_detail.item(2).getAttribute('name'))
+        self.assertEqual(
+            cgsnapshot3.id,
+            cgsnapshot_detail.item(2).getAttribute('id'))
+        self.assertEqual(
+            'creating', cgsnapshot_detail.item(2).getAttribute('status'))
+
+        cgsnapshot3.destroy()
+        cgsnapshot2.destroy()
+        cgsnapshot1.destroy()
         db.volume_destroy(context.get_admin_context(),
                           volume_id)
         consistencygroup.destroy()
@@ -328,8 +304,6 @@ class CgsnapshotsAPITestCase(test.TestCase):
     @mock.patch(
         'cinder.api.openstack.wsgi.Controller.validate_name_and_description')
     def test_create_cgsnapshot_json(self, mock_validate):
-        cgsnapshot_id = "1"
-
         consistencygroup = utils.create_consistencygroup(self.context)
         utils.create_volume(
             self.context, consistencygroup_id=consistencygroup.id)
@@ -350,8 +324,10 @@ class CgsnapshotsAPITestCase(test.TestCase):
         self.assertIn('id', res_dict['cgsnapshot'])
         self.assertTrue(mock_validate.called)
 
-        db.cgsnapshot_destroy(context.get_admin_context(), cgsnapshot_id)
         consistencygroup.destroy()
+        cgsnapshot = objects.CGSnapshot.get_by_id(
+            context.get_admin_context(), res_dict['cgsnapshot']['id'])
+        cgsnapshot.destroy()
 
     def test_create_cgsnapshot_with_no_body(self):
         # omit body from the request
@@ -425,21 +401,21 @@ class CgsnapshotsAPITestCase(test.TestCase):
         volume_id = utils.create_volume(
             self.context,
             consistencygroup_id=consistencygroup.id)['id']
-        cgsnapshot_id = self._create_cgsnapshot(
+        cgsnapshot = utils.create_cgsnapshot(
+            self.context,
             consistencygroup_id=consistencygroup.id,
             status='available')
         req = webob.Request.blank('/v2/fake/cgsnapshots/%s' %
-                                  cgsnapshot_id)
+                                  cgsnapshot.id)
         req.method = 'DELETE'
         req.headers['Content-Type'] = 'application/json'
         res = req.get_response(fakes.wsgi_app())
 
+        cgsnapshot = objects.CGSnapshot.get_by_id(self.context, cgsnapshot.id)
         self.assertEqual(202, res.status_int)
-        self.assertEqual('deleting', self._get_cgsnapshot_attrib(cgsnapshot_id,
-                         'status'))
+        self.assertEqual('deleting', cgsnapshot.status)
 
-        db.cgsnapshot_destroy(context.get_admin_context(),
-                              cgsnapshot_id)
+        cgsnapshot.destroy()
         db.volume_destroy(context.get_admin_context(),
                           volume_id)
         consistencygroup.destroy()
@@ -459,11 +435,14 @@ class CgsnapshotsAPITestCase(test.TestCase):
     def test_delete_cgsnapshot_with_Invalidcgsnapshot(self):
         consistencygroup = utils.create_consistencygroup(self.context)
         volume_id = utils.create_volume(
-            self.context, consistencygroup_id=consistencygroup.id)['id']
-        cgsnapshot_id = self._create_cgsnapshot(
-            consistencygroup_id=consistencygroup.id, status='invalid')
+            self.context,
+            consistencygroup_id=consistencygroup.id)['id']
+        cgsnapshot = utils.create_cgsnapshot(
+            self.context,
+            consistencygroup_id=consistencygroup.id,
+            status='invalid')
         req = webob.Request.blank('/v2/fake/cgsnapshots/%s' %
-                                  cgsnapshot_id)
+                                  cgsnapshot.id)
         req.method = 'DELETE'
         req.headers['Content-Type'] = 'application/json'
         res = req.get_response(fakes.wsgi_app())
@@ -474,8 +453,7 @@ class CgsnapshotsAPITestCase(test.TestCase):
         self.assertEqual('Invalid cgsnapshot',
                          res_dict['badRequest']['message'])
 
-        db.cgsnapshot_destroy(context.get_admin_context(),
-                              cgsnapshot_id)
+        cgsnapshot.destroy()
         db.volume_destroy(context.get_admin_context(),
                           volume_id)
         consistencygroup.destroy()
index 5a0e846b515bc799f7735ded6b728e4522cba024..2bb047f2ef44062892d13674721f7ecfe9783ed3 100644 (file)
@@ -731,20 +731,19 @@ class ConsistencyGroupsAPITestCase(test.TestCase):
         volume_id = utils.create_volume(
             self.ctxt,
             consistencygroup_id=consistencygroup.id)['id']
-        cgsnapshot_id = utils.create_cgsnapshot(
-            self.ctxt,
-            consistencygroup_id=consistencygroup.id)['id']
+        cgsnapshot = utils.create_cgsnapshot(
+            self.ctxt, consistencygroup_id=consistencygroup.id)
         snapshot = utils.create_snapshot(
             self.ctxt,
             volume_id,
-            cgsnapshot_id=cgsnapshot_id,
+            cgsnapshot_id=cgsnapshot.id,
             status='available')
 
         test_cg_name = 'test cg'
         body = {"consistencygroup-from-src": {"name": test_cg_name,
                                               "description":
                                               "Consistency Group 1",
-                                              "cgsnapshot_id": cgsnapshot_id}}
+                                              "cgsnapshot_id": cgsnapshot.id}}
         req = webob.Request.blank('/v2/fake/consistencygroups/create_from_src')
         req.method = 'POST'
         req.headers['Content-Type'] = 'application/json'
@@ -762,9 +761,9 @@ class ConsistencyGroupsAPITestCase(test.TestCase):
 
         cg_ref.destroy()
         snapshot.destroy()
-        db.cgsnapshot_destroy(self.ctxt.elevated(), cgsnapshot_id)
         db.volume_destroy(self.ctxt.elevated(), volume_id)
         consistencygroup.destroy()
+        cgsnapshot.destroy()
 
     def test_create_consistencygroup_from_src_cg(self):
         self.mock_object(volume_api.API, "create", stubs.stub_volume_create)
@@ -873,20 +872,19 @@ class ConsistencyGroupsAPITestCase(test.TestCase):
         volume_id = utils.create_volume(
             self.ctxt,
             consistencygroup_id=consistencygroup.id)['id']
-        cgsnapshot_id = utils.create_cgsnapshot(
-            self.ctxt,
-            consistencygroup_id=consistencygroup.id)['id']
+        cgsnapshot = utils.create_cgsnapshot(
+            self.ctxt, consistencygroup_id=consistencygroup.id)
         snapshot = utils.create_snapshot(
             self.ctxt,
             volume_id,
-            cgsnapshot_id=cgsnapshot_id,
+            cgsnapshot_id=cgsnapshot.id,
             status='available')
 
         test_cg_name = 'test cg'
         body = {"consistencygroup-from-src": {"name": test_cg_name,
                                               "description":
                                               "Consistency Group 1",
-                                              "cgsnapshot_id": cgsnapshot_id}}
+                                              "cgsnapshot_id": cgsnapshot.id}}
         req = webob.Request.blank('/v2/fake/consistencygroups/create_from_src')
         req.method = 'POST'
         req.headers['Content-Type'] = 'application/json'
@@ -901,24 +899,24 @@ class ConsistencyGroupsAPITestCase(test.TestCase):
         self.assertIn(msg, res_dict['badRequest']['message'])
 
         snapshot.destroy()
-        db.cgsnapshot_destroy(self.ctxt.elevated(), cgsnapshot_id)
         db.volume_destroy(self.ctxt.elevated(), volume_id)
         consistencygroup.destroy()
+        cgsnapshot.destroy()
 
     def test_create_consistencygroup_from_src_cgsnapshot_empty(self):
         consistencygroup = utils.create_consistencygroup(self.ctxt)
         volume_id = utils.create_volume(
             self.ctxt,
             consistencygroup_id=consistencygroup.id)['id']
-        cgsnapshot_id = utils.create_cgsnapshot(
+        cgsnapshot = utils.create_cgsnapshot(
             self.ctxt,
-            consistencygroup_id=consistencygroup.id)['id']
+            consistencygroup_id=consistencygroup.id)
 
         test_cg_name = 'test cg'
         body = {"consistencygroup-from-src": {"name": test_cg_name,
                                               "description":
                                               "Consistency Group 1",
-                                              "cgsnapshot_id": cgsnapshot_id}}
+                                              "cgsnapshot_id": cgsnapshot.id}}
         req = webob.Request.blank('/v2/fake/consistencygroups/create_from_src')
         req.method = 'POST'
         req.headers['Content-Type'] = 'application/json'
@@ -930,9 +928,9 @@ class ConsistencyGroupsAPITestCase(test.TestCase):
         self.assertEqual(400, res_dict['badRequest']['code'])
         self.assertIsNotNone(res_dict['badRequest']['message'])
 
-        db.cgsnapshot_destroy(self.ctxt.elevated(), cgsnapshot_id)
         db.volume_destroy(self.ctxt.elevated(), volume_id)
         consistencygroup.destroy()
+        cgsnapshot.destroy()
 
     def test_create_consistencygroup_from_src_source_cg_empty(self):
         source_cg = utils.create_consistencygroup(self.ctxt)
@@ -1006,20 +1004,19 @@ class ConsistencyGroupsAPITestCase(test.TestCase):
         volume_id = utils.create_volume(
             self.ctxt,
             consistencygroup_id=consistencygroup.id)['id']
-        cgsnapshot_id = utils.create_cgsnapshot(
-            self.ctxt,
-            consistencygroup_id=consistencygroup.id)['id']
+        cgsnapshot = utils.create_cgsnapshot(
+            self.ctxt, consistencygroup_id=consistencygroup.id)
         snapshot = utils.create_snapshot(
             self.ctxt,
             volume_id,
-            cgsnapshot_id=cgsnapshot_id,
+            cgsnapshot_id=cgsnapshot.id,
             status='available')
 
         test_cg_name = 'test cg'
         body = {"consistencygroup-from-src": {"name": test_cg_name,
                                               "description":
                                               "Consistency Group 1",
-                                              "cgsnapshot_id": cgsnapshot_id}}
+                                              "cgsnapshot_id": cgsnapshot.id}}
         req = webob.Request.blank('/v2/fake/consistencygroups/create_from_src')
         req.method = 'POST'
         req.headers['Content-Type'] = 'application/json'
@@ -1033,9 +1030,9 @@ class ConsistencyGroupsAPITestCase(test.TestCase):
         self.assertEqual(msg, res_dict['badRequest']['message'])
 
         snapshot.destroy()
-        db.cgsnapshot_destroy(self.ctxt.elevated(), cgsnapshot_id)
         db.volume_destroy(self.ctxt.elevated(), volume_id)
         consistencygroup.destroy()
+        cgsnapshot.destroy()
 
     @mock.patch.object(volume_api.API, 'create',
                        side_effect=exception.CinderException(
index 596f8912f87a164f1c119c9d0b7dd1a515a6247c..c2098e6c8401f9774f66acbcaf6fdca7b4e65a01 100644 (file)
@@ -1917,9 +1917,9 @@ class StorwizeSVCDriverTestCase(test.TestCase):
         for volume in volumes:
             testutils.create_snapshot(self.ctxt,
                                       volume['id'],
-                                      cg_snapshot['id'],
-                                      cg_snapshot['name'],
-                                      cg_snapshot['id'],
+                                      cg_snapshot.id,
+                                      cg_snapshot.name,
+                                      cg_snapshot.id,
                                       "creating")
 
         return cg_snapshot