Later specified environment with parameter_defaults values of 0 do not override earlier non-0 values

Bug #1669442 reported by James Slagle
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack Heat
Fix Released
Medium
Thomas Herve

Bug Description

When using multiple environments with -e, and you have a parameter value specified via parameter_defaults, and it's value is 0 (the non-quoted number), it will not override earlier non-zero values.

Here is a test reproducer:

[root@tripleo-09 test]# cat template.yaml
heat_template_version: ocata

parameters:

  param1:
    type: number
    default: 0

resources:

  param1_value:
    type: OS::Heat::Value
    properties:
      value:
        {get_param: param1}

[root@tripleo-09 test]# cat env1.yaml
parameter_defaults:
  param1: 1

[root@tripleo-09 test]# cat env2.yaml
parameter_defaults:
  param1: 0

My create command:
[root@tripleo-09 test]# openstack stack create test --wait -t template.yaml -e env1.yaml -e env2.yaml

Notice env2.yaml is specified last.

The result:

[root@tripleo-09 test]# openstack stack resource show test param1_value
+------------------------+-------------------------------------------------------------------------------------+
| Field | Value |
+------------------------+-------------------------------------------------------------------------------------+
| attributes | {u'value': u'1'} |
| creation_time | 2017-03-02T14:01:42Z |
| description | |
| links | [{u'href': u'http://192.168.25.10:8004/v1/df4517693d6f44c8adc911f8ba0579d0/stacks/t |
| | est/49406476-bf1a-4abb-91ab-37fc6c3d0a4e/resources/param1_value', u'rel': u'self'}, |
| | {u'href': u'http://192.168.25.10:8004/v1/df4517693d6f44c8adc911f8ba0579d0/stacks/te |
| | st/49406476-bf1a-4abb-91ab-37fc6c3d0a4e', u'rel': u'stack'}] |
| logical_resource_id | param1_value |
| physical_resource_id | test-param1_value-wrxf72k66px2 |
| required_by | [] |
| resource_name | param1_value |
| resource_status | CREATE_COMPLETE |
| resource_status_reason | state changed |
| resource_type | OS::Heat::Value |
| updated_time | 2017-03-02T14:01:42Z |
+------------------------+-------------------------------------------------------------------------------------+

The value is 1, when it should be 0.

If you quote the value in env2.yaml so it looks like:
[root@tripleo-09 test]# cat env2.yaml
parameter_defaults:
  param1: "0"

Then you get the expected value of 0 after a stack create:
[root@tripleo-09 test]# openstack stack resource show test param1_value
+------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Field | Value |
+------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| attributes | {u'value': 0} |
| creation_time | 2017-03-02T14:06:03Z |
| description | |
| links | [{u'href': u'http://192.168.25.10:8004/v1/df4517693d6f44c8adc911f8ba0579d0/stacks/test/cd23f838-566b-4c9f-bc2f-2259753509b3/resources/param1_value', u'rel': u'self'}, {u'href': |
| | u'http://192.168.25.10:8004/v1/df4517693d6f44c8adc911f8ba0579d0/stacks/test/cd23f838-566b-4c9f-bc2f-2259753509b3', u'rel': u'stack'}] |
| logical_resource_id | param1_value |
| physical_resource_id | test-param1_value-6kh4vqc5vfhu |
| required_by | [] |
| resource_name | param1_value |
| resource_status | CREATE_COMPLETE |
| resource_status_reason | state changed |
| resource_type | OS::Heat::Value |
| updated_time | 2017-03-02T14:06:03Z |
+------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

I'd wager that there is some logic somewhere that is applying some "if" logic to the parameter's value to see if it was specified and the non-quoted 0 evalues to false, so the later value is ignored.

When I was debugging client side, I saw the later value of 0 working as expected after template_utils.process_multiple_environments_and_files had been called, in that 0 was shown as the value in parameter_defaults in the returned merged_env.

So, the bug must be server side. Note also that if you do a stack create with --dry-run, you will see the wrong value shown in the parameters of the output.

Thomas Herve (therve)
Changed in heat:
milestone: none → pike-1
assignee: nobody → Thomas Herve (therve)
importance: Undecided → Medium
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/440659

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

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

commit 16999806e6a16548cdf87d9f475ef4dd16f28a5f
Author: Thomas Herve <email address hidden>
Date: Thu Mar 2 17:01:33 2017 +0100

    Handle zero values when merging environments

    When merging multiple envs, 0 values where ignored in later envs, not
    taking precedence. This fixes it by checking for None instead.

    Change-Id: Ia0da6988f92825bcc9a19dd3dcce771baa978a59
    Closes-Bug: #1669442

Changed in heat:
status: In Progress → Fix Released
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix included in openstack/heat 9.0.0.0b1

This issue was fixed in the openstack/heat 9.0.0.0b1 development milestone.

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.