diff --git a/oslo/vmware/pbm.py b/oslo/vmware/pbm.py index dbd65cc..c7a5265 100644 --- a/oslo/vmware/pbm.py +++ b/oslo/vmware/pbm.py @@ -83,16 +83,18 @@ def get_all_profiles(session): profile_manager = pbm.service_content.profileManager res_type = pbm.client.factory.create('ns0:PbmProfileResourceType') res_type.resourceType = 'STORAGE' - + profiles = [] profile_ids = session.invoke_api(pbm, 'PbmQueryProfile', profile_manager, resourceType=res_type) LOG.debug(_("Fetched profile IDs: %s."), profile_ids) - return session.invoke_api(pbm, - 'PbmRetrieveContent', - profile_manager, - profileIds=profile_ids) + if profile_ids: + profiles = session.invoke_api(pbm, + 'PbmRetrieveContent', + profile_manager, + profileIds=profile_ids) + return profiles def get_profile_id_by_name(session, profile_name): diff --git a/tests/test_pbm.py b/tests/test_pbm.py index a505443..f84b971 100644 --- a/tests/test_pbm.py +++ b/tests/test_pbm.py @@ -47,6 +47,18 @@ class PBMUtilityTest(base.TestCase): pbm.get_all_profiles(session) self.assertEqual(2, session.invoke_api.call_count) + def test_get_all_profiles_with_no_profiles(self): + session = mock.Mock() + session.pbm = mock.Mock() + session.invoke_api.return_value = [] + profiles = pbm.get_all_profiles(session) + session.invoke_api.assert_called_once_with( + session.pbm, + 'PbmQueryProfile', + session.pbm.service_content.profileManager, + resourceType=session.pbm.client.factory.create()) + self.assertEqual([], profiles) + def _create_profile(self, profile_id, name): profile = mock.Mock() profile.profileId = profile_id