diff --git a/cinder/tests/unit/test_coprhd.py b/cinder/tests/unit/test_coprhd.py index ea27c630661..5f3d084407d 100644 --- a/cinder/tests/unit/test_coprhd.py +++ b/cinder/tests/unit/test_coprhd.py @@ -16,6 +16,7 @@ from mock import Mock from cinder import context +from cinder import exception from cinder.objects import fields from cinder import test from cinder.volume.drivers.coprhd import common as coprhd_common @@ -263,7 +264,8 @@ def get_test_CG_snap_data(volume_type_id): 'consistencygroup_id': '123456789', 'status': fields.ConsistencyGroupStatus.AVAILABLE, 'snapshots': [], - 'consistencygroup': get_test_CG_data(volume_type_id) + 'consistencygroup': get_test_CG_data(volume_type_id), + 'cgsnapshot_id': '1', } return test_CG_snapshot @@ -641,6 +643,20 @@ class EMCCoprHDFCDriverTest(test.TestCase): self.driver.delete_volume(src_vol_data) self.driver.delete_volume(volume_data) + def test_create_volume_from_cg_snapshot(self): + ctx = context.get_admin_context() + + volume_data = get_test_volume_data(self.volume_type_id) + cg_snap_data = get_test_CG_snap_data(self.volume_type_id) + + self.driver.create_cgsnapshot(ctx, cg_snap_data, []) + self.assertRaises(exception.VolumeBackendAPIException, + self.driver.create_volume_from_snapshot, + volume_data, cg_snap_data) + + self.driver.delete_cgsnapshot(ctx, cg_snap_data, []) + self.driver.delete_volume(volume_data) + def test_extend_volume(self): volume_data = get_test_volume_data(self.volume_type_id) self.driver.create_volume(volume_data) diff --git a/cinder/volume/drivers/coprhd/common.py b/cinder/volume/drivers/coprhd/common.py index 78b4ea1f50c..60793eff5e0 100644 --- a/cinder/volume/drivers/coprhd/common.py +++ b/cinder/volume/drivers/coprhd/common.py @@ -750,6 +750,12 @@ class EMCCoprHDDriverCommon(object): self.create_cloned_volume(volume, snapshot, truncate_name) return + if snapshot.get('cgsnapshot_id'): + raise coprhd_utils.CoprHdError( + coprhd_utils.CoprHdError.SOS_FAILURE_ERR, + _("Volume cannot be created individually from a snapshot " + "that is part of a Consistency Group")) + src_snapshot_name = None src_vol_ref = snapshot['volume'] new_volume_name = self._get_resource_name(volume, truncate_name)