From 7ca6005d4714f2f322daf8f3858032f3f8758d9c Mon Sep 17 00:00:00 2001 From: Peng Wang Date: Thu, 11 Jan 2018 19:41:13 -0700 Subject: [PATCH] DS8K: block in-use volume to be added to consistency group In DS8K, adding the in-use volume into consistency group will failed. Fix this issue by blocking user to add the attached volume into consistency group. Change-Id: Id7f0e336183f03c5687389dce0f71c5a773889d6 Closes-Bug: 1742845 --- .../volume/drivers/ibm/test_ds8k_proxy.py | 37 +++++++++++++++++++ .../drivers/ibm/ibm_storage/ds8k_proxy.py | 14 +++++++ 2 files changed, 51 insertions(+) diff --git a/cinder/tests/unit/volume/drivers/ibm/test_ds8k_proxy.py b/cinder/tests/unit/volume/drivers/ibm/test_ds8k_proxy.py index 52e0d831fc3..3f1a2d36af4 100644 --- a/cinder/tests/unit/volume/drivers/ibm/test_ds8k_proxy.py +++ b/cinder/tests/unit/volume/drivers/ibm/test_ds8k_proxy.py @@ -2999,6 +2999,43 @@ class DS8KProxyTest(test.TestCase): self.driver.delete_group, self.ctxt, group, [volume]) + def test_add_in_use_vol_into_group_by_using_update_group(self): + self.driver = FakeDS8KProxy(self.storage_info, self.logger, + self.exception, self) + self.driver.setup(self.ctxt) + group_type = group_types.create( + self.ctxt, + 'group', + {'consistent_group_snapshot_enabled': ' True'} + ) + group = self._create_group(host=TEST_GROUP_HOST, + group_type_id=group_type.id) + location = six.text_type({'vol_hex_id': TEST_VOLUME_ID}) + volume = self._create_volume(provider_location=location, + status='in-use') + self.assertRaises(exception.VolumeDriverException, + self.driver.update_group, + self.ctxt, group, [volume], []) + + def test_remove_in_use_vol_from_group_by_using_update_group(self): + self.driver = FakeDS8KProxy(self.storage_info, self.logger, + self.exception, self) + self.driver.setup(self.ctxt) + group_type = group_types.create( + self.ctxt, + 'group', + {'consistent_group_snapshot_enabled': ' True'} + ) + group = self._create_group(host=TEST_GROUP_HOST, + group_type_id=group_type.id) + location = six.text_type({'vol_hex_id': TEST_VOLUME_ID}) + volume = self._create_volume(provider_location=location, + status='in-use', + group_id=group.id) + self.assertRaises(exception.VolumeDriverException, + self.driver.update_group, + self.ctxt, group, [], [volume]) + def test_update_replication_group_is_not_implemented(self): """update replication group is not implemented.""" self.configuration.replication_device = [TEST_REPLICATION_DEVICE] diff --git a/cinder/volume/drivers/ibm/ibm_storage/ds8k_proxy.py b/cinder/volume/drivers/ibm/ibm_storage/ds8k_proxy.py index b8bcba637f7..18f5cee433d 100644 --- a/cinder/volume/drivers/ibm/ibm_storage/ds8k_proxy.py +++ b/cinder/volume/drivers/ibm/ibm_storage/ds8k_proxy.py @@ -1195,6 +1195,13 @@ class DS8KProxy(proxy.IBMStorageProxy): @proxy.logger def _add_volumes_into_consisgroup(self, grp, add_volumes): add_volumes_update = [] + for vol in add_volumes: + if vol.status == 'in-use': + msg = (_("add volume %(vol)s into group %(grp)s failed " + "since this volume is 'in-use' status") + % {'vol': vol.id, 'grp': grp.id}) + LOG.error(msg) + raise exception.VolumeDriverException(message=msg) new_add_luns, old_add_luns = ( self._clone_lun_for_consisgroup(add_volumes, grp)) for new_add_lun, old_add_lun in zip(new_add_luns, old_add_luns): @@ -1208,6 +1215,13 @@ class DS8KProxy(proxy.IBMStorageProxy): def _remove_volumes_from_consisgroup(self, grp, add_volumes, remove_volumes): remove_volumes_update = [] + for vol in remove_volumes: + if vol.status == 'in-use': + msg = (_("remove volume %(vol)s from group %(grp)s failed " + "since this volume is 'in-use' status") + % {'vol': vol.id, 'grp': grp.id}) + LOG.error(msg) + raise exception.VolumeDriverException(message=msg) new_remove_luns, old_remove_luns = ( self._clone_lun_for_consisgroup(remove_volumes)) for new_remove_lun, old_remove_lun in zip(new_remove_luns,