From: Walter A. Boring IV Date: Fri, 4 Sep 2015 00:05:44 +0000 (-0700) Subject: 3PAR Add update_migrated_volume to drivers X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=18f85a9dc391719fb1becb63ac3b8505e0460c51;p=openstack-build%2Fcinder-build.git 3PAR Add update_migrated_volume to drivers The 3PAR drivers were missing the method update_migrated_volume, which would then cause all sorts of problems after a volume was migrated into a 3PAR array. Change-Id: Iab9b3ef1812bc7e8249c802f0c699787b0a58af6 Closes-Bug: 1492023 --- diff --git a/cinder/tests/unit/test_hp3par.py b/cinder/tests/unit/test_hp3par.py index 40451afe3..d3533c263 100644 --- a/cinder/tests/unit/test_hp3par.py +++ b/cinder/tests/unit/test_hp3par.py @@ -1735,6 +1735,45 @@ class HP3PARBaseDriver(object): expected = [] mock_client.assert_has_calls(expected) + def test_update_migrated_volume(self): + mock_client = self.setup_driver() + fake_old_volume = {'id': self.VOLUME_ID} + provider_location = 'foo' + fake_new_volume = {'id': self.CLONE_ID, + '_name_id': self.CLONE_ID, + 'provider_location': provider_location} + original_volume_status = 'available' + with mock.patch.object(hpcommon.HP3PARCommon, + '_create_client') as mock_create_client: + mock_create_client.return_value = mock_client + actual_update = self.driver.update_migrated_volume( + context.get_admin_context(), fake_old_volume, + fake_new_volume, original_volume_status) + + expected_update = {'_name_id': None, + 'provider_location': None} + self.assertEqual(expected_update, actual_update) + + def test_update_migrated_volume_attached(self): + mock_client = self.setup_driver() + fake_old_volume = {'id': self.VOLUME_ID} + provider_location = 'foo' + fake_new_volume = {'id': self.CLONE_ID, + '_name_id': self.CLONE_ID, + 'provider_location': provider_location} + original_volume_status = 'in-use' + + with mock.patch.object(hpcommon.HP3PARCommon, + '_create_client') as mock_create_client: + mock_create_client.return_value = mock_client + actual_update = self.driver.update_migrated_volume( + context.get_admin_context(), fake_old_volume, + fake_new_volume, original_volume_status) + + expected_update = {'_name_id': fake_new_volume['_name_id'], + 'provider_location': provider_location} + self.assertEqual(expected_update, actual_update) + def test_attach_volume(self): # setup_mock_client drive with default configuration # and return the mock HTTP 3PAR client diff --git a/cinder/volume/drivers/san/hp/hp_3par_common.py b/cinder/volume/drivers/san/hp/hp_3par_common.py index ea31a735d..9c5606f83 100644 --- a/cinder/volume/drivers/san/hp/hp_3par_common.py +++ b/cinder/volume/drivers/san/hp/hp_3par_common.py @@ -201,10 +201,11 @@ class HP3PARCommon(object): 2.0.49 - Added client CPG stats to driver volume stats. bug #1482741 2.0.50 - Add over subscription support 2.0.51 - Adds consistency group support + 2.0.52 - Added update_migrated_volume. bug # 1492023 """ - VERSION = "2.0.51" + VERSION = "2.0.52" stats = {} @@ -1900,6 +1901,41 @@ class HP3PARCommon(object): dbg_ret) return ret + def update_migrated_volume(self, context, volume, new_volume, + original_volume_status): + """Rename the new (temp) volume to it's original name. + + + This method tries to rename the new volume to it's original + name after the migration has completed. + + """ + LOG.debug("Update volume name for %(id)s", {'id': new_volume['id']}) + name_id = None + provider_location = None + if original_volume_status == 'available': + # volume isn't attached and can be updated + original_name = self._get_3par_vol_name(volume['id']) + current_name = self._get_3par_vol_name(new_volume['id']) + try: + volumeMods = {'newName': original_name} + self.client.modifyVolume(current_name, volumeMods) + LOG.info(_LI("Volume name changed from %(tmp)s to %(orig)s"), + {'tmp': current_name, 'orig': original_name}) + except Exception as e: + LOG.error(_LE("Changing the volume name from %(tmp)s to " + "%(orig)s failed because %(reason)s"), + {'tmp': current_name, 'orig': original_name, + 'reason': e}) + name_id = new_volume['_name_id'] or new_volume['id'] + provider_location = new_volume['provider_location'] + else: + # the backend can't change the name. + 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 _convert_to_base_volume(self, volume, new_cpg=None): try: type_info = self.get_volume_settings_from_type(volume) diff --git a/cinder/volume/drivers/san/hp/hp_3par_fc.py b/cinder/volume/drivers/san/hp/hp_3par_fc.py index 6ea71f8d0..a3c0234ff 100644 --- a/cinder/volume/drivers/san/hp/hp_3par_fc.py +++ b/cinder/volume/drivers/san/hp/hp_3par_fc.py @@ -89,10 +89,11 @@ class HP3PARFCDriver(driver.TransferVD, 2.0.18 - Changed initialize_connection to use getHostVLUNs. #1475064 2.0.19 - Adds consistency group support 2.0.20 - Update driver to use ABC metaclasses + 2.0.21 - Added update_migrated_volume. bug # 1492023 """ - VERSION = "2.0.20" + VERSION = "2.0.21" def __init__(self, *args, **kwargs): super(HP3PARFCDriver, self).__init__(*args, **kwargs) @@ -542,6 +543,16 @@ class HP3PARFCDriver(driver.TransferVD, finally: self._logout(common) + def update_migrated_volume(self, context, volume, new_volume, + original_volume_status): + """Update the name of the migrated volume to it's new ID.""" + common = self._login() + try: + return common.update_migrated_volume(context, volume, new_volume, + original_volume_status) + finally: + self._logout(common) + def get_pool(self, volume): common = self._login() try: diff --git a/cinder/volume/drivers/san/hp/hp_3par_iscsi.py b/cinder/volume/drivers/san/hp/hp_3par_iscsi.py index 54b61479c..cb7ab18d5 100644 --- a/cinder/volume/drivers/san/hp/hp_3par_iscsi.py +++ b/cinder/volume/drivers/san/hp/hp_3par_iscsi.py @@ -99,10 +99,11 @@ class HP3PARISCSIDriver(driver.TransferVD, 2.0.20 - Adding changes to support 3PAR iSCSI multipath. 2.0.21 - Adds consistency group support 2.0.22 - Update driver to use ABC metaclasses + 2.0.23 - Added update_migrated_volume. bug # 1492023 """ - VERSION = "2.0.22" + VERSION = "2.0.23" def __init__(self, *args, **kwargs): super(HP3PARISCSIDriver, self).__init__(*args, **kwargs) @@ -839,6 +840,16 @@ class HP3PARISCSIDriver(driver.TransferVD, finally: self._logout(common) + def update_migrated_volume(self, context, volume, new_volume, + original_volume_status): + """Update the name of the migrated volume to it's new ID.""" + common = self._login() + try: + return common.update_migrated_volume(context, volume, new_volume, + original_volume_status) + finally: + self._logout(common) + def get_pool(self, volume): common = self._login() try: