From 562e0c54db4cb7737fc0bdf974e34d6c72be063e Mon Sep 17 00:00:00 2001 From: Tina Date: Wed, 5 Aug 2015 22:04:29 -0400 Subject: [PATCH] VNX driver needs to return snapshot objects 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 | 24 ++++++++++++++++-------- cinder/volume/drivers/emc/emc_vnx_cli.py | 5 +++-- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/cinder/tests/unit/test_emc_vnxdirect.py b/cinder/tests/unit/test_emc_vnxdirect.py index 7b50c54eb..616111085 100644 --- a/cinder/tests/unit/test_emc_vnxdirect.py +++ b/cinder/tests/unit/test_emc_vnxdirect.py @@ -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 = [ diff --git a/cinder/volume/drivers/emc/emc_vnx_cli.py b/cinder/volume/drivers/emc/emc_vnx_cli.py index 434701ba7..4084796b4 100644 --- a/cinder/volume/drivers/emc/emc_vnx_cli.py +++ b/cinder/volume/drivers/emc/emc_vnx_cli.py @@ -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 = {} -- 2.45.2