Problem:
If a nested stack has no resources, then we do not get
a "nested" link in the resource information returned by
our API.
Why?
In engine/api.py we have:
if (hasattr(resource, 'nested') and callable(resource.nested) and resource.nested()): res[rpc_api.RES_NESTED_STACK_ID] = dict(resource.nested().identifier())
The problem with this is the python definition of False, from the docs:
"instances of user-defined classes, if the class defines a __nonzero__()
or __len__() method, when that method returns the integer zero or bool
value False. [1]"
So if you have a stack with zero resources (len() returns 0), the
stack will be False :-O
Solution:
Use "if stack is not None:" instead of "if stack".
Reviewed: https:/ /review. openstack. org/152071 /git.openstack. org/cgit/ openstack/ heat/commit/ ?id=734f777da48 cc008d8da4bf197 c7a87a03be8846
Committed: https:/
Submitter: Jenkins
Branch: master
commit 734f777da48cc00 8d8da4bf197c7a8 7a03be8846
Author: Angus Salkeld <email address hidden>
Date: Mon Feb 2 13:12:48 2015 +1000
Use "if stack is not None" and not "if stack"
Problem:
If a nested stack has no resources, then we do not get
a "nested" link in the resource information returned by
our API.
Why?
In engine/api.py we have:
if (hasattr(resource, 'nested') and callable( resource. nested) and
resource. nested( )):
res[ rpc_api. RES_NESTED_ STACK_ID] = dict(resource. nested( ).identifier( ))
The problem with this is the python definition of False, from the docs:
"instances of user-defined classes, if the class defines a __nonzero__()
or __len__() method, when that method returns the integer zero or bool
value False. [1]"
So if you have a stack with zero resources (len() returns 0), the
stack will be False :-O
Solution:
Use "if stack is not None:" instead of "if stack".
Change-Id: Ibdd1cb5dee6ce8 e58f7d8f2586a49 5caded79134
Closes-bug: 1416917