]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
VNX driver needs to return snapshot objects
authorTina <tina.tang@emc.com>
Thu, 6 Aug 2015 02:04:29 +0000 (22:04 -0400)
committerTina <tina.tang@emc.com>
Thu, 6 Aug 2015 03:00:20 +0000 (23:00 -0400)
Use snapshot objects instead of snapshot dictionaries of
create_cgsnapshot and delete_cgsnapshot.

Change-Id: I0794e1c30a1ef8f0a4bdf82c6cb850ae4415d164
Partially-Closes-Bug: #1458125

cinder/tests/unit/test_emc_vnxdirect.py
cinder/volume/drivers/emc/emc_vnx_cli.py

index 7b50c54ebd20e41543f5baa20b169464566660af..6161110857fd0a29064f0d891729cba3335164f0 100644 (file)
@@ -21,6 +21,7 @@ import six
 
 from cinder import exception
 from cinder import test
+from cinder.tests.unit import fake_snapshot
 from cinder.tests.unit import utils
 from cinder.volume import configuration as conf
 from cinder.volume.drivers.emc import emc_cli_fc
@@ -3369,15 +3370,18 @@ Time Remaining:  0 second(s)
             mock.call(*self.testData.LUN_DELETE_CMD('vol1'))]
         fake_cli.assert_has_calls(expect_cmd)
 
-    def test_create_cgsnapshot(self):
+    @mock.patch(
+        'cinder.objects.snapshot.SnapshotList.get_all_for_cgsnapshot')
+    def test_create_cgsnapshot(self, get_all_for_cgsnapshot):
         cgsnapshot = self.testData.test_cgsnapshot['id']
         cg_name = self.testData.test_cgsnapshot['consistencygroup_id']
         commands = [self.testData.CREATE_CG_SNAPSHOT(cg_name, cgsnapshot)]
         results = [SUCCEED]
         fake_cli = self.driverSetup(commands, results)
-        self.driver.db = mock.MagicMock()
-        self.driver.db.volume_get_all_by_group.return_value =\
-            self.testData.SNAPS_IN_SNAP_GROUP()
+        snapshot_obj = fake_snapshot.fake_snapshot_obj(
+            self.testData.SNAPS_IN_SNAP_GROUP())
+        snapshot_obj.consistencygroup_id = cg_name
+        get_all_for_cgsnapshot.return_value = [snapshot_obj]
         self.driver.create_cgsnapshot(None, self.testData.test_cgsnapshot)
         expect_cmd = [
             mock.call(
@@ -3385,14 +3389,18 @@ Time Remaining:  0 second(s)
                     cg_name, cgsnapshot))]
         fake_cli.assert_has_calls(expect_cmd)
 
-    def test_delete_cgsnapshot(self):
+    @mock.patch(
+        'cinder.objects.snapshot.SnapshotList.get_all_for_cgsnapshot')
+    def test_delete_cgsnapshot(self, get_all_for_cgsnapshot):
         snap_name = self.testData.test_cgsnapshot['id']
         commands = [self.testData.DELETE_CG_SNAPSHOT(snap_name)]
         results = [SUCCEED]
         fake_cli = self.driverSetup(commands, results)
-        self.driver.db = mock.MagicMock()
-        self.driver.db.snapshot_get_all_for_cgsnapshot.return_value =\
-            self.testData.SNAPS_IN_SNAP_GROUP()
+        snapshot_obj = fake_snapshot.fake_snapshot_obj(
+            self.testData.SNAPS_IN_SNAP_GROUP())
+        cg_name = self.testData.test_cgsnapshot['consistencygroup_id']
+        snapshot_obj.consistencygroup_id = cg_name
+        get_all_for_cgsnapshot.return_value = [snapshot_obj]
         self.driver.delete_cgsnapshot(None,
                                       self.testData.test_cgsnapshot)
         expect_cmd = [
index 434701ba76957c15da6d3321b4baca9eae07fa07..4084796b49d5665281f6ff0de06f21f3af17afd8 100644 (file)
@@ -40,6 +40,7 @@ from taskflow.types import failure
 
 from cinder import exception
 from cinder.i18n import _, _LE, _LI, _LW
+from cinder import objects
 from cinder import utils
 from cinder.volume import configuration as config
 from cinder.volume.drivers.san import san
@@ -2623,7 +2624,7 @@ class EMCVnxCliBase(object):
     def create_cgsnapshot(self, driver, context, cgsnapshot):
         """Creates a cgsnapshot (snap group)."""
         cgsnapshot_id = cgsnapshot['id']
-        snapshots = driver.db.snapshot_get_all_for_cgsnapshot(
+        snapshots = objects.SnapshotList().get_all_for_cgsnapshot(
             context, cgsnapshot_id)
 
         model_update = {}
@@ -2647,7 +2648,7 @@ class EMCVnxCliBase(object):
     def delete_cgsnapshot(self, driver, context, cgsnapshot):
         """Deletes a cgsnapshot (snap group)."""
         cgsnapshot_id = cgsnapshot['id']
-        snapshots = driver.db.snapshot_get_all_for_cgsnapshot(
+        snapshots = objects.SnapshotList().get_all_for_cgsnapshot(
             context, cgsnapshot_id)
 
         model_update = {}