]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
3PAR Add update_migrated_volume to drivers
authorWalter A. Boring IV <walter.boring@hp.com>
Fri, 4 Sep 2015 00:05:44 +0000 (17:05 -0700)
committerWalter A. Boring IV <walter.boring@hp.com>
Fri, 4 Sep 2015 04:29:28 +0000 (04:29 +0000)
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

cinder/tests/unit/test_hp3par.py
cinder/volume/drivers/san/hp/hp_3par_common.py
cinder/volume/drivers/san/hp/hp_3par_fc.py
cinder/volume/drivers/san/hp/hp_3par_iscsi.py

index 40451afe386216b53bbfbc384948d0d4d4d4a6e2..d3533c263aa07c8ed19fba784732ec6df74d20bd 100644 (file)
@@ -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
index ea31a735dc6421f7acbf7097d1dd1ede96b4b4d4..9c5606f8361a34c6d6dc33cb0769015ad4b4f64d 100644 (file)
@@ -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)
index 6ea71f8d09ae26235826fd5bbd4972500aa1c1ea..a3c0234ff9db6abca2eaf9da8d9e8cd25a4499f7 100644 (file)
@@ -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:
index 54b61479caf78fda6a029e7358896c6b9b7db537..cb7ab18d5d7a10bda1794a6547f6a7d686d51950 100644 (file)
@@ -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: