From 6d7125bdbce1c665c9c5e37e1f9928281279d475 Mon Sep 17 00:00:00 2001 From: lakshman Date: Fri, 2 Dec 2016 07:19:45 -0500 Subject: [PATCH] Do not manage VG with > 1 volume in Kaminario driver Currently, if we want to manage a volume in the K2 array, we rename the volume and associated VG in K2 according to cv-CinderVolumeId for volume and cvg-CinderVolumeId for VG. So, if K2 volume is managed by cinder, then for any future reference for the managed volume, cv-CinderVolumeId and cvg-CinderVolumeId must exist on K2 array. But if a VG in K2 have more than one volume and we try to manage another volume in the same VG, then it will rename the VG and any future reference for another managed volume will result in error. Change-Id: I0db48d11d812ea802d11165a959ff5b46a4d6af3 Closes-Bug: #1646766 Co-Authored-By: Nikesh Mahalka Co-Authored-By: Ido Benda --- .../unit/volume/drivers/test_kaminario.py | 6 +++++ .../drivers/kaminario/kaminario_common.py | 25 +++++++++++++------ ...r-driver-bug-1646766-fe810f5801d24f2f.yaml | 5 ++++ 3 files changed, 29 insertions(+), 7 deletions(-) create mode 100644 releasenotes/notes/kaminario-cinder-driver-bug-1646766-fe810f5801d24f2f.yaml diff --git a/cinder/tests/unit/volume/drivers/test_kaminario.py b/cinder/tests/unit/volume/drivers/test_kaminario.py index 38acc5eba53..4115e4beca6 100644 --- a/cinder/tests/unit/volume/drivers/test_kaminario.py +++ b/cinder/tests/unit/volume/drivers/test_kaminario.py @@ -313,6 +313,12 @@ class TestKaminarioISCSI(test.TestCase): self.driver.manage_existing, self.vol, {'source-name': 'test'}) + def test_manage_vg_volumes(self): + self.driver.nvol = 2 + self.assertRaises(exception.ManageExistingInvalidReference, + self.driver.manage_existing, self.vol, + {'source-name': 'test'}) + def test_manage_existing_get_size(self): """Test manage_existing_get_size.""" self.driver.client.search().hits[0].size = units.Mi diff --git a/cinder/volume/drivers/kaminario/kaminario_common.py b/cinder/volume/drivers/kaminario/kaminario_common.py index 405df0af4b5..db50a86795d 100644 --- a/cinder/volume/drivers/kaminario/kaminario_common.py +++ b/cinder/volume/drivers/kaminario/kaminario_common.py @@ -1026,18 +1026,28 @@ class KaminarioCinderDriver(cinder.volume.driver.ISCSIDriver): vg_new_name = self.get_volume_group_name(volume.id) vg_name = None is_dedup = self._get_is_dedup(volume.get('volume_type')) + reason = None try: LOG.debug("Searching volume: %s in K2.", vol_name) vol = self.client.search("volumes", name=vol_name).hits[0] vg = vol.volume_group + nvol = self.client.search("volumes", volume_group=vg).total vg_replica = self._get_replica_status(vg.name) vol_map = False if self.client.search("mappings", volume=vol).total != 0: vol_map = True - if is_dedup != vg.is_dedup or vg_replica or vol_map: + if is_dedup != vg.is_dedup: + reason = 'dedup type mismatch for K2 volume group.' + elif vg_replica: + reason = 'replication enabled K2 volume group.' + elif vol_map: + reason = 'attached K2 volume.' + elif nvol != 1: + reason = 'multiple volumes in K2 volume group.' + if reason: raise exception.ManageExistingInvalidReference( existing_ref=existing_ref, - reason=_('Manage volume type invalid.')) + reason=_('Unable to manage K2 volume due to: %s') % reason) vol.name = new_name vg_name = vg.name LOG.debug("Manage new volume name: %s", new_name) @@ -1046,7 +1056,11 @@ class KaminarioCinderDriver(cinder.volume.driver.ISCSIDriver): vg.save() LOG.debug("Manage volume: %s in K2.", vol_name) vol.save() - except Exception as ex: + except exception.ManageExistingInvalidReference: + LOG.exception(_LE("manage volume: %s failed."), vol_name) + raise + except Exception: + LOG.exception(_LE("manage volume: %s failed."), vol_name) vg_rs = self.client.search("volume_groups", name=vg_new_name) if hasattr(vg_rs, 'hits') and vg_rs.total != 0: vg = vg_rs.hits[0] @@ -1054,10 +1068,7 @@ class KaminarioCinderDriver(cinder.volume.driver.ISCSIDriver): vg.name = vg_name LOG.debug("Updating vg new name to old name: %s ", vg_name) vg.save() - LOG.exception(_LE("manage volume: %s failed."), vol_name) - raise exception.ManageExistingInvalidReference( - existing_ref=existing_ref, - reason=six.text_type(ex.message)) + raise @kaminario_logger def manage_existing_get_size(self, volume, existing_ref): diff --git a/releasenotes/notes/kaminario-cinder-driver-bug-1646766-fe810f5801d24f2f.yaml b/releasenotes/notes/kaminario-cinder-driver-bug-1646766-fe810f5801d24f2f.yaml new file mode 100644 index 00000000000..533750c5c6c --- /dev/null +++ b/releasenotes/notes/kaminario-cinder-driver-bug-1646766-fe810f5801d24f2f.yaml @@ -0,0 +1,5 @@ +--- +fixes: + - Fixed issue of managing a VG with more than one + volume in Kaminario FC and iSCSI Cinder drivers. +