Can't use conditions with depends_on

Bug #1649900 reported by Steven Hardy
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack Heat
Fix Released
Medium
Thomas Herve

Bug Description

Trying to use conditional resource creation breaks any serialization via depends_on:

[stack@instack ~]$ heat stack-create tx -f test_conditions.yaml
ERROR: The specified reference "two" (in three) is incorrect.

[stack@instack ~]$ cat test_conditions.yaml
heat_template_version: 2016-10-14

parameters:
  a_param:
    type: string
    default: ''

conditions:
  a_param_is_not_empty:
    not:
      equals:
        - get_param: a_param
        - ''
resources:
  one:
    type: OS::Heat::RandomString

  two:
    depends_on: one
    condition: a_param_is_not_empty
    type: OS::Heat::RandomString

  three:
    depends_on: two
    type: OS::Heat::RandomString

It would be good if we could simply figure out the implicit dependency between "three" and "one" in this case, and make the depends_on via two a pass-through when a_param_is_not_empty evaluates to false.

Trying to work around it by using the "if" function in depends_on doesn't work either:

stack@instack ~]$ heat stack-create tx -f test_conditions2.yaml
ERROR: Resource three depends_on type must be list or string
[stack@instack ~]$ cat test_conditions2.yaml
heat_template_version: 2016-10-14

parameters:
  a_param:
    type: string
    default: ''

conditions:
  a_param_is_not_empty:
    not:
      equals:
        - get_param: a_param
        - ''
resources:
  one:
    type: OS::Heat::RandomString

  two:
    depends_on: one
    condition: a_param_is_not_empty
    type: OS::Heat::RandomString

  three:
    depends_on:
      if:
        - a_param_is_not_empty
        - two
        - one
    type: OS::Heat::RandomString

Revision history for this message
Thomas Herve (therve) wrote :

It's an interesting problem to solve. To me, the first template is not the same as the second, because passthrough isn't the logical behavior to have when a condition is not met. If three depends on two, and two is not created, three shouldn't be created either.

I think it's worth trying to see if we can make the second template work. In the meantime, you should be able to workaround by defining three twice:

three:
  depends_on: one
  condition: {not: a_param_is_not_empty}

three_2:
  depends_on: two
  condition: a_param_is_not_empty

Changed in heat:
assignee: nobody → huangtianhua (huangtianhua)
Thomas Herve (therve)
Changed in heat:
milestone: none → ocata-3
Revision history for this message
Steven Hardy (shardy) wrote :

As a follow-up to this, the workaround in comment #1 doesn't work when you have a chain of dependencies, e.g you can't then have a "four" resource, because it needs to depends_on three or three_two, which gets you back to the original problem I reported.

Thomas Herve (therve)
Changed in heat:
assignee: huangtianhua (huangtianhua) → Thomas Herve (therve)
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/418827

Changed in heat:
status: New → In Progress
Revision history for this message
Zane Bitter (zaneb) wrote :
Revision history for this message
OpenStack Infra (hudson-openstack) wrote :

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

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to heat (master)

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

commit e1aeabaa032c607b07aa835526c06aad0d1e21c5
Author: Thomas Herve <email address hidden>
Date: Thu Jan 12 19:20:35 2017 +0100

    Ignore dependency errors with conditions

    If a resource is conditionally defined, depending on it raises an error
    in the case it's not defined. This patch fixes that by checking if the
    resource is present in the template regardless of the conditions.

    Change-Id: Iefae1fcea720bee4ed69ad1a5fe403d52d54433c
    Closes-Bug: #1649900

Changed in heat:
status: In Progress → Fix Released
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Change abandoned on heat (master)

Change abandoned by Thomas Herve (<email address hidden>) on branch: master
Review: https://review.openstack.org/418827
Reason: superceded

Thomas Herve (therve)
Changed in heat:
importance: Undecided → Critical
importance: Critical → Medium
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix included in openstack/heat 8.0.0.0b3

This issue was fixed in the openstack/heat 8.0.0.0b3 development milestone.

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to heat (stable/newton)

Fix proposed to branch: stable/newton
Review: https://review.openstack.org/452642

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to heat (stable/newton)

Reviewed: https://review.openstack.org/452642
Committed: https://git.openstack.org/cgit/openstack/heat/commit/?id=40ea8371378b64dd042ee6e749718e940105ba2c
Submitter: Jenkins
Branch: stable/newton

commit 40ea8371378b64dd042ee6e749718e940105ba2c
Author: Thomas Herve <email address hidden>
Date: Thu Jan 12 19:20:35 2017 +0100

    Ignore dependency errors with conditions

    If a resource is conditionally defined, depending on it raises an error
    in the case it's not defined. This patch fixes that by checking if the
    resource is present in the template regardless of the conditions.

    Change-Id: Iefae1fcea720bee4ed69ad1a5fe403d52d54433c
    Closes-Bug: #1649900
    (cherry picked from commit e1aeabaa032c607b07aa835526c06aad0d1e21c5)

tags: added: in-stable-newton
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Related fix proposed to heat (master)

Related fix proposed to branch: master
Review: https://review.openstack.org/479367

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix included in openstack/heat 7.0.5

This issue was fixed in the openstack/heat 7.0.5 release.

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Related fix merged to heat (master)

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

commit c25034f5cd2e9182d9846cc39161cbf51deb664d
Author: Zane Bitter <email address hidden>
Date: Fri Jun 30 12:23:15 2017 -0400

    Strip disabled resources from depends_on in add_resource()

    When we add a resource to a template using add_resource(), strip any
    references to resources that are not present in the template from
    'depends_on'. This means that resources that are present and depended on
    but conditionally disabled in the source template will not be depended
    on in the destination template, where they're not present at all (and
    thus would cause errors when the template is used).

    Change-Id: I58a64cd523cc0d1da8cd39793f0c839189458d99
    Closes-Bug: #1701677
    Related-Bug: #1649900

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Related fix proposed to heat (stable/pike)

Related fix proposed to branch: stable/pike
Review: https://review.openstack.org/505668

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Related fix merged to heat (stable/pike)

Reviewed: https://review.openstack.org/505668
Committed: https://git.openstack.org/cgit/openstack/heat/commit/?id=670656703f5662da93bec3eb2584a64ee0418154
Submitter: Jenkins
Branch: stable/pike

commit 670656703f5662da93bec3eb2584a64ee0418154
Author: Zane Bitter <email address hidden>
Date: Fri Jun 30 12:23:15 2017 -0400

    Strip disabled resources from depends_on in add_resource()

    When we add a resource to a template using add_resource(), strip any
    references to resources that are not present in the template from
    'depends_on'. This means that resources that are present and depended on
    but conditionally disabled in the source template will not be depended
    on in the destination template, where they're not present at all (and
    thus would cause errors when the template is used).

    Change-Id: I58a64cd523cc0d1da8cd39793f0c839189458d99
    Closes-Bug: #1701677
    Related-Bug: #1649900
    (cherry picked from commit c25034f5cd2e9182d9846cc39161cbf51deb664d)

tags: added: in-stable-pike
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.