Enable resource _show_resource with dict type

Some openstack service python client returns the entity
in dict type when calling .get() method. This patch enables
_show_resource() method to consider this aspect.

Change-Id: I7cea5823c77b04c8ffba34f71952e50765aa9668
This commit is contained in:
Kanagaraj Manickam 2016-12-29 16:01:36 +05:30
parent f39e15d74f
commit c31343fb92
2 changed files with 11 additions and 2 deletions

View File

@ -1895,7 +1895,10 @@ class Resource(object):
try:
obj = getattr(self.client(), self.entity)
resource = obj.get(self.resource_id)
return resource.to_dict()
if type(resource) == dict:
return resource
else:
return resource.to_dict()
except AttributeError as ex:
LOG.warning(_LW("Resolving 'show' attribute has failed : %s"),
ex)

View File

@ -2403,7 +2403,7 @@ class ResourceTest(common.HeatTestCase):
res.resource_id = 'test_resource_id'
res.entity = 'test'
# mock gettring resource info
# mock getting resource info
res.client = mock.Mock()
test_obj = mock.Mock()
test_resource = mock.Mock()
@ -2413,6 +2413,12 @@ class ResourceTest(common.HeatTestCase):
self.assertEqual({'test': 'info'}, res._show_resource())
# mock getting resource info as dict
test_obj.get.return_value = {'test': 'info'}
res.client().test = test_obj
self.assertEqual({'test': 'info'}, res._show_resource())
# check the case where resource entity isn't defined
res.entity = None
self.assertIsNone(res._show_resource())