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."""
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
: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 = {}