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. +