]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
VMware:Replace vCenter calls with oslo.vmware calls
authorVipin Balachandran <vbala@vmware.com>
Wed, 15 Jul 2015 08:14:09 +0000 (13:44 +0530)
committerVipin Balachandran <vbala@vmware.com>
Thu, 23 Jul 2015 13:07:09 +0000 (18:37 +0530)
Currently we call vCenter APIs to find storage policy
associated with a volume. There are methods defined
in oslo.vmware to query storage policies. This patch
replaces vCenter API calls with oslo.vmware method
calls.

Change-Id: I54e18e50e8423de51c43a277e701ddc9a9aef6da

cinder/tests/unit/test_vmware_volumeops.py
cinder/volume/drivers/vmware/volumeops.py

index be37cb77f9376556f75264cd7f9bb5c44ff59b24..1b871cfc5b1d52e77314966465a1ed26a191bf18 100644 (file)
@@ -1443,51 +1443,35 @@ class VolumeOpsTestCase(test.TestCase):
                                            datacenter=dc_ref)
         self.session.wait_for_task.assert_called_once_with(task)
 
-    def test_get_profile(self):
-        server_obj = mock.Mock()
-        self.session.pbm.client.factory.create.return_value = server_obj
+    @mock.patch('oslo_vmware.pbm.get_profiles_by_ids')
+    @mock.patch('oslo_vmware.pbm.get_profiles')
+    def test_get_profile(self, get_profiles, get_profiles_by_ids):
 
         profile_ids = [mock.sentinel.profile_id]
+        get_profiles.return_value = profile_ids
+
         profile_name = mock.sentinel.profile_name
         profile = mock.Mock()
         profile.name = profile_name
-        self.session.invoke_api.side_effect = [profile_ids, [profile]]
+        get_profiles_by_ids.return_value = [profile]
 
-        value = mock.sentinel.value
-        backing = mock.Mock(value=value)
+        backing = mock.sentinel.backing
         self.assertEqual(profile_name, self.vops.get_profile(backing))
+        get_profiles.assert_called_once_with(self.session, backing)
+        get_profiles_by_ids.assert_called_once_with(self.session, profile_ids)
 
-        pbm = self.session.pbm
-        profile_manager = pbm.service_content.profileManager
-        exp_calls = [mock.call(pbm, 'PbmQueryAssociatedProfile',
-                               profile_manager, entity=server_obj),
-                     mock.call(pbm, 'PbmRetrieveContent', profile_manager,
-                               profileIds=profile_ids)]
-        self.assertEqual(exp_calls, self.session.invoke_api.call_args_list)
-
-        self.assertEqual(value, server_obj.key)
-        self.assertEqual('virtualMachine', server_obj.objectType)
-        self.session.invoke_api.side_effect = None
-
-    def test_get_profile_with_no_profile(self):
-        server_obj = mock.Mock()
-        self.session.pbm.client.factory.create.return_value = server_obj
+    @mock.patch('oslo_vmware.pbm.get_profiles_by_ids')
+    @mock.patch('oslo_vmware.pbm.get_profiles')
+    def test_get_profile_with_no_profile(self, get_profiles,
+                                         get_profiles_by_ids):
 
-        self.session.invoke_api.side_effect = [[]]
+        get_profiles.return_value = []
 
-        value = mock.sentinel.value
-        backing = mock.Mock(value=value)
+        backing = mock.sentinel.backing
         self.assertIsNone(self.vops.get_profile(backing))
 
-        pbm = self.session.pbm
-        profile_manager = pbm.service_content.profileManager
-        exp_calls = [mock.call(pbm, 'PbmQueryAssociatedProfile',
-                               profile_manager, entity=server_obj)]
-        self.assertEqual(exp_calls, self.session.invoke_api.call_args_list)
-
-        self.assertEqual(value, server_obj.key)
-        self.assertEqual('virtualMachine', server_obj.objectType)
-        self.session.invoke_api.side_effect = None
+        get_profiles.assert_called_once_with(self.session, backing)
+        self.assertFalse(get_profiles_by_ids.called)
 
     def test_extend_virtual_disk(self):
         """Test volumeops.extend_virtual_disk."""
index 358cfd636ba877ed5c24fbbef55655436e9168af..4e4e61e0bb8bf6d06530a5ff3b5f8e649bb657a6 100644 (file)
@@ -21,6 +21,7 @@ Implements operations on volumes residing on VMware datastores.
 from oslo_log import log as logging
 from oslo_utils import units
 from oslo_vmware import exceptions
+from oslo_vmware import pbm
 from oslo_vmware import vim_util
 from six.moves import urllib
 
@@ -1396,23 +1397,9 @@ class VMwareVolumeOps(object):
         :param backing: backing reference
         :return: profile name
         """
-        pbm = self._session.pbm
-        profile_manager = pbm.service_content.profileManager
-
-        object_ref = pbm.client.factory.create('ns0:PbmServerObjectRef')
-        object_ref.key = backing.value
-        object_ref.objectType = 'virtualMachine'
-
-        profile_ids = self._session.invoke_api(pbm,
-                                               'PbmQueryAssociatedProfile',
-                                               profile_manager,
-                                               entity=object_ref)
+        profile_ids = pbm.get_profiles(self._session, backing)
         if profile_ids:
-            profiles = self._session.invoke_api(pbm,
-                                                'PbmRetrieveContent',
-                                                profile_manager,
-                                                profileIds=profile_ids)
-            return profiles[0].name
+            return pbm.get_profiles_by_ids(self._session, profile_ids)[0].name
 
     def _get_all_clusters(self):
         clusters = {}