nested stacks don't provide a nested link if there is no inner resources

Bug #1416917 reported by Angus Salkeld
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack Heat
Fix Released
Medium
Angus Salkeld

Bug Description

I ran into this in a functional test.

stack:
  resources:
    a_nested_stack:
      resources: # <- none

now if you get "a_nested_stack" it's links don't have a "nested", this is because
the Stack class has a len() method and python defines it's boolean values like this:

"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 the following retruns false even though these is a valid nested stack

  if stack.nested():
      # never runs

see: https://github.com/openstack/heat/blob/master/heat/engine/api.py#L180

We need to go though and make sure we are not using "if <stack object>" as meaning "if <stack object> is not None".

Angus Salkeld (asalkeld)
Changed in heat:
importance: Undecided → Medium
assignee: nobody → Angus Salkeld (asalkeld)
status: New → Triaged
Angus Salkeld (asalkeld)
Changed in heat:
milestone: none → kilo-2
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to heat (master)

Fix proposed to branch: master
Review: https://review.openstack.org/152071

Changed in heat:
status: Triaged → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to heat (master)

Reviewed: https://review.openstack.org/152071
Committed: https://git.openstack.org/cgit/openstack/heat/commit/?id=734f777da48cc008d8da4bf197c7a87a03be8846
Submitter: Jenkins
Branch: master

commit 734f777da48cc008d8da4bf197c7a87a03be8846
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: Ibdd1cb5dee6ce8e58f7d8f2586a495caded79134
    Closes-bug: 1416917

Changed in heat:
status: In Progress → Fix Committed
Thierry Carrez (ttx)
Changed in heat:
status: Fix Committed → Fix Released
Thierry Carrez (ttx)
Changed in heat:
milestone: kilo-2 → 2015.1.0
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.