]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
VMware: Add missing storage profile requirement
authorVipin Balachandran <vbala@vmware.com>
Thu, 27 Nov 2014 14:55:42 +0000 (20:25 +0530)
committerVipin Balachandran <vbala@vmware.com>
Wed, 3 Dec 2014 07:21:10 +0000 (12:51 +0530)
If a storage profile is part of a volume type, it should be used as a
requirement for datastore selection-- only datastores which satisfy the
storage profile should be used for backing VM creation. Currently in
retype API, if storage profiles in old and new volume types are same,
it is not passed as a requirement. Hence, the backing VM corresponding
to the volume might end up in a datastore which doesn't satisfy the
storage profile. This patch fixes the problem.

Closes-Bug: #1398293
Change-Id: I49161e9fc5a8f2749ee6097fa5a136b78dfcf3ab

cinder/tests/test_vmware_vmdk.py
cinder/volume/drivers/vmware/vmdk.py

index eea42dc85fcadbdc753609823d381dcebd8fd5d1..6140fc25f11b3f25cf95796bc4230255a32cb1fd 100644 (file)
@@ -133,6 +133,8 @@ class FakeObj(object):
         self.obj = obj
 
 
+# TODO(vbala) Split test methods handling multiple cases into multiple methods,
+# each handling a specific case.
 class VMwareEsxVmdkDriverTestCase(test.TestCase):
     """Test class for VMwareEsxVmdkDriver."""
 
@@ -1531,6 +1533,27 @@ class VMwareEsxVmdkDriverTestCase(test.TestCase):
         vops.change_backing_profile.assert_called_once_with(backing,
                                                             profile_id)
 
+        # Modify the previous case with no profile change.
+        get_volume_type_extra_specs.side_effect = [vmdk.THICK_VMDK_TYPE,
+                                                   vmdk.THIN_VMDK_TYPE,
+                                                   'gold-1',
+                                                   'gold-1']
+        ds_sel.select_datastore.reset_mock()
+        vops.relocate_backing.reset_mock()
+        vops.move_backing_to_folder.reset_mock()
+        vops.change_backing_profile.reset_mock()
+
+        self.assertTrue(self._driver.retype(context, vol, new_type, diff,
+                                            host))
+        exp_req = {hub.DatastoreSelector.HARD_ANTI_AFFINITY_DS: [ds_value],
+                   hub.DatastoreSelector.PROFILE_NAME: 'gold-1',
+                   hub.DatastoreSelector.SIZE_BYTES: units.Gi}
+        ds_sel.select_datastore.assert_called_once_with(exp_req)
+        vops.relocate_backing.assert_called_once_with(
+            backing, candidate_ds, rp, host, vmdk.THIN_VMDK_TYPE)
+        vops.move_backing_to_folder.assert_called_once_with(backing, folder)
+        self.assertFalse(vops.change_backing_profile.called)
+
         # Test with disk type conversion, profile change, backing with
         # no snapshots and candidate datastore which is same as the backing
         # datastore.
index 633759fd3758a08f5a5c3288d3c4efbc6d1d5a43..9cfa8f26d8d35cbfb9297d68a6360e8bbdbf927c 100644 (file)
@@ -1459,11 +1459,7 @@ class VMwareEsxVmdkDriver(driver.VolumeDriver):
                 req[hub.DatastoreSelector.HARD_ANTI_AFFINITY_DS] = (
                     [datastore.value])
 
-            if need_profile_change:
-                LOG.debug("Backing: %(backing)s needs a profile change to: "
-                          "%(profile)s.",
-                          {'backing': backing,
-                           'profile': new_profile})
+            if new_profile:
                 req[hub.DatastoreSelector.PROFILE_NAME] = new_profile
 
             # Select datastore satisfying the requirements.
@@ -1530,6 +1526,10 @@ class VMwareEsxVmdkDriver(driver.VolumeDriver):
 
         # Update the backing's storage profile if needed.
         if need_profile_change:
+            LOG.debug("Backing: %(backing)s needs a profile change to:"
+                      " %(profile)s.",
+                      {'backing': backing,
+                       'profile': new_profile})
             profile_id = None
             if new_profile is not None:
                 profile_id = self.ds_sel.get_profile_id(new_profile)