Fix empty association attributes

If an association does not exist, the id methods affected
in this patch will currently fail, as it will attempt to
grab an id of a non-existent attribute.

The implemented fix uses the EAFP philosophy.

Change-Id: I97b608bc267963e754d06379d94372d13e7c93fa
This commit is contained in:
Tzu-Mainn Chen 2013-10-16 23:26:35 -04:00
parent 006f9d70c5
commit 352ed23f02
2 changed files with 7 additions and 6 deletions

View File

@ -293,9 +293,9 @@ class Node(StringIdAPIResourceWrapper):
@property
def rack_id(self):
if self._apiresource.rack:
try:
return unicode(self._apiresource.rack['id'])
else:
except AttributeError:
return None
@property
@ -454,9 +454,10 @@ class Rack(StringIdAPIResourceWrapper):
@property
def resource_class_id(self):
rclass = self._apiresource.resource_class
resource_class_id = rclass['id'] if rclass else None
return resource_class_id
try:
return self._apiresource.resource_class['id']
except AttributeError:
return None
@property
def resource_class(self):

View File

@ -123,7 +123,7 @@ def data(TEST):
{"name": "total_memory",
"value": "2",
"unit": "MB"}],
'resource_class': None})
})
TEST.tuskarclient_racks.add(rack_1, rack_2, rack_3)
TEST.tuskar_racks.add(api.Rack(rack_1), api.Rack(rack_2), api.Rack(rack_3))