VMware: get_all_cluster_refs_by_name default to {}

Currently get_all_cluster_refs_by_name returns None when no cluster
is found.
driver.py is using the keys() method without checking whether the
object returned is None. This can potentially end up throwing an
AttributeError.

This patch fixes the issue by returning an empty dictionary when no
cluster is found.

Change-Id: I3293c916d79aaa4de8913e8ab9c609c9c0bb023e
Closes-Bug: #1372672
This commit is contained in:
Arnaud Legendre
2014-09-22 15:36:48 -07:00
parent fdcf6b8c79
commit aafe39cd94
2 changed files with 4 additions and 4 deletions

View File

@@ -466,7 +466,7 @@ class VMwareVMUtilTestCase(test.NoDBTestCase):
fake_objects = fake.FakeRetrieveResult()
refs = vm_util.get_all_cluster_refs_by_name(
fake.FakeObjectRetrievalSession(fake_objects), ['fake_cluster'])
self.assertTrue(not refs)
self.assertEqual({}, refs)
def test_get_all_cluster_refs_by_name_exists(self):
fake_objects = fake.FakeRetrieveResult()
@@ -480,7 +480,7 @@ class VMwareVMUtilTestCase(test.NoDBTestCase):
fake_objects.add_object(partialObject(path='cluster'))
refs = vm_util.get_all_cluster_refs_by_name(
fake.FakeObjectRetrievalSession(fake_objects), ['cluster'])
self.assertTrue(not refs)
self.assertEqual({}, refs)
def test_propset_dict_simple(self):
ObjectContent = collections.namedtuple('ObjectContent', ['propSet'])

View File

@@ -1176,10 +1176,10 @@ def get_all_cluster_refs_by_name(session, path_list):
"""
cls = get_all_cluster_mors(session)
if not cls:
return
return {}
res = get_all_res_pool_mors(session)
if not res:
return
return {}
path_list = [path.strip() for path in path_list]
list_obj = []
for entity_path in path_list: