From 50276fd5c5c16942f5f4d3fd7f18d2fbfeaf40b9 Mon Sep 17 00:00:00 2001 From: Vipin Balachandran Date: Tue, 5 Jul 2016 13:42:01 +0530 Subject: [PATCH] VMware: Fix retype when storage policy is enabled If storage policy is enabled, retype checks if the volume is compliant (using is_datastore_compliant method) with the policy mentioned in the new volume type. This check is failing because is_datastore_compliant calls _filter_by_profile passing a list, and this call fails since _filter_by_profile expects a dictionary after change I0c505cbe1c82b9cbd2918a223a53a800a9bc7931. Closes-bug: #1599167 Change-Id: Ia62f5f268c124a3665a7a9e0e2d3c84cb6f2e632 --- .../volume/drivers/vmware/test_vmware_datastore.py | 10 ++++++---- cinder/volume/drivers/vmware/datastore.py | 7 ++++++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/cinder/tests/unit/volume/drivers/vmware/test_vmware_datastore.py b/cinder/tests/unit/volume/drivers/vmware/test_vmware_datastore.py index 8d78a88f3..9ae89d9e0 100644 --- a/cinder/tests/unit/volume/drivers/vmware/test_vmware_datastore.py +++ b/cinder/tests/unit/volume/drivers/vmware/test_vmware_datastore.py @@ -341,19 +341,21 @@ class DatastoreTest(test.TestCase): get_profile_id_by_name.reset_mock() profile_id = mock.sentinel.profile_id get_profile_id_by_name.return_value = profile_id - filter_by_profile.return_value = [] + filter_by_profile.return_value = {} self.assertFalse(self._ds_sel.is_datastore_compliant(datastore, profile_name)) get_profile_id_by_name.assert_called_once_with(self._session, profile_name) - filter_by_profile.assert_called_once_with([datastore], profile_id) + filter_by_profile.assert_called_once_with({datastore: None}, + profile_id) # Test with valid profile and compliant datastore. get_profile_id_by_name.reset_mock() filter_by_profile.reset_mock() - filter_by_profile.return_value = [datastore] + filter_by_profile.return_value = {datastore: None} self.assertTrue(self._ds_sel.is_datastore_compliant(datastore, profile_name)) get_profile_id_by_name.assert_called_once_with(self._session, profile_name) - filter_by_profile.assert_called_once_with([datastore], profile_id) + filter_by_profile.assert_called_once_with({datastore: None}, + profile_id) diff --git a/cinder/volume/drivers/vmware/datastore.py b/cinder/volume/drivers/vmware/datastore.py index 24da57a91..eab7c7675 100644 --- a/cinder/volume/drivers/vmware/datastore.py +++ b/cinder/volume/drivers/vmware/datastore.py @@ -294,7 +294,12 @@ class DatastoreSelector(object): return True profile_id = self.get_profile_id(profile_name) - is_compliant = bool(self._filter_by_profile([datastore], profile_id)) + # _filter_by_profile expects a map of datastore references to its + # properties. It only uses the properties to construct a map of + # filtered datastores to its properties. Here we don't care about + # the datastore property, so pass it as None. + is_compliant = bool(self._filter_by_profile({datastore: None}, + profile_id)) LOG.debug("Compliance is %(is_compliant)s for datastore: " "%(datastore)s against profile: %(profile)s.", {'is_compliant': is_compliant,