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
This commit is contained in:
parent
c3942d27b2
commit
e641467f9e
@ -83,16 +83,18 @@ def get_all_profiles(session):
|
|||||||
profile_manager = pbm.service_content.profileManager
|
profile_manager = pbm.service_content.profileManager
|
||||||
res_type = pbm.client.factory.create('ns0:PbmProfileResourceType')
|
res_type = pbm.client.factory.create('ns0:PbmProfileResourceType')
|
||||||
res_type.resourceType = 'STORAGE'
|
res_type.resourceType = 'STORAGE'
|
||||||
|
profiles = []
|
||||||
profile_ids = session.invoke_api(pbm,
|
profile_ids = session.invoke_api(pbm,
|
||||||
'PbmQueryProfile',
|
'PbmQueryProfile',
|
||||||
profile_manager,
|
profile_manager,
|
||||||
resourceType=res_type)
|
resourceType=res_type)
|
||||||
LOG.debug(_("Fetched profile IDs: %s."), profile_ids)
|
LOG.debug(_("Fetched profile IDs: %s."), profile_ids)
|
||||||
return session.invoke_api(pbm,
|
if profile_ids:
|
||||||
'PbmRetrieveContent',
|
profiles = session.invoke_api(pbm,
|
||||||
profile_manager,
|
'PbmRetrieveContent',
|
||||||
profileIds=profile_ids)
|
profile_manager,
|
||||||
|
profileIds=profile_ids)
|
||||||
|
return profiles
|
||||||
|
|
||||||
|
|
||||||
def get_profile_id_by_name(session, profile_name):
|
def get_profile_id_by_name(session, profile_name):
|
||||||
|
@ -47,6 +47,18 @@ class PBMUtilityTest(base.TestCase):
|
|||||||
pbm.get_all_profiles(session)
|
pbm.get_all_profiles(session)
|
||||||
self.assertEqual(2, session.invoke_api.call_count)
|
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):
|
def _create_profile(self, profile_id, name):
|
||||||
profile = mock.Mock()
|
profile = mock.Mock()
|
||||||
profile.profileId = profile_id
|
profile.profileId = profile_id
|
||||||
|
Loading…
Reference in New Issue
Block a user