From 6f98f143bf4f3b0e37f8a67ad5a5b6284f5bd401 Mon Sep 17 00:00:00 2001 From: Shay Halsband Date: Tue, 19 Jul 2016 18:38:06 +0300 Subject: [PATCH] XtremIO: Implement update_migrated_volume - Rename volume after migration to keep the original uuid Change-Id: Ifefa32f83b05524c357e81dd942284d65f827395 Closes-bug: #1513760 --- .../volume/drivers/emc/test_emc_xtremio.py | 27 +++++++++++++++++++ cinder/volume/drivers/emc/xtremio.py | 21 +++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/cinder/tests/unit/volume/drivers/emc/test_emc_xtremio.py b/cinder/tests/unit/volume/drivers/emc/test_emc_xtremio.py index c1164236cba..d6827f52c2c 100644 --- a/cinder/tests/unit/volume/drivers/emc/test_emc_xtremio.py +++ b/cinder/tests/unit/volume/drivers/emc/test_emc_xtremio.py @@ -495,6 +495,33 @@ class EMCXIODriverISCSITestCase(BaseEMCXIODriverTestCase): self.driver.client.handle_errors, response, '', '') + def test_update_migrated_volume(self, req): + original = self.data.test_volume + new = self.data.test_volume2 + update = (self.driver. + update_migrated_volume({}, + original, new, 'available')) + req.assert_called_once_with('volumes', 'PUT', + {'name': original['id']}, new['id'], + None, 'v2') + self.assertEqual({'_name_id': None, + 'provider_location': None}, update) + + def test_update_migrated_volume_failed_rename(self, req): + req.side_effect = exception.VolumeBackendAPIException( + data='failed rename') + original = self.data.test_volume + new = copy.deepcopy(self.data.test_volume2) + fake_provider = '__provider' + new['provider_location'] = fake_provider + new['_name_id'] = None + update = (self.driver. + update_migrated_volume({}, + original, new, 'available')) + self.assertEqual({'_name_id': new['id'], + 'provider_location': fake_provider}, + update) + # ##### Connection ##### def test_no_portals_configured(self, req): req.side_effect = xms_request diff --git a/cinder/volume/drivers/emc/xtremio.py b/cinder/volume/drivers/emc/xtremio.py index c101af62892..6c5ec1eeafe 100644 --- a/cinder/volume/drivers/emc/xtremio.py +++ b/cinder/volume/drivers/emc/xtremio.py @@ -469,6 +469,27 @@ class XtremIOVolumeDriver(san.SanDriver): except exception.NotFound: LOG.info(_LI("snapshot %s doesn't exist"), snapshot.id) + def update_migrated_volume(self, ctxt, volume, new_volume, + original_volume_status): + # as the volume name is used to id the volume we need to rename it + name_id = None + provider_location = None + current_name = new_volume['id'] + original_name = volume['id'] + try: + data = {'name': original_name} + self.client.req('volumes', 'PUT', data, name=current_name) + except exception.VolumeBackendAPIException: + LOG.error(_LE('Unable to rename the logical volume ' + 'for volume: %s'), original_name) + # If the rename fails, _name_id should be set to the new + # volume id and provider_location should be set to the + # one from the new volume as well. + name_id = new_volume['_name_id'] or new_volume['id'] + provider_location = new_volume['provider_location'] + + return {'_name_id': name_id, 'provider_location': provider_location} + def _update_volume_stats(self): sys = self.client.get_cluster() physical_space = int(sys["ud-ssd-space"]) / units.Mi