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:
parent
006f9d70c5
commit
352ed23f02
@ -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):
|
||||
|
@ -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))
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user