From e641467f9e05d7d273770d7d96e487453062f257 Mon Sep 17 00:00:00 2001 From: Sabari Kumar Murugesan Date: Thu, 3 Apr 2014 18:12:28 -0700 Subject: [PATCH] Fix vim25:InvalidRequest when no profiles exist Currently, we don't check if there are any existing profiles in pbm.get_all_profiles. As a result, we send a malformed request to PBMRetrieveContent resulting in vim25:InvalidRequest. Change-Id: I882c97a8050f8c2d49a4ce1de0f166e457ce68f2 Closes-Bug: #1302271 --- oslo/vmware/pbm.py | 12 +++++++----- tests/test_pbm.py | 12 ++++++++++++ 2 files changed, 19 insertions(+), 5 deletions(-) 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