Number conversion doesn't work in template

Bug #1226494 reported by Mitsuru Kanabuchi
16
This bug affects 3 people
Affects Status Importance Assigned to Milestone
OpenStack Heat
Fix Released
High
Mitsuru Kanabuchi

Bug Description

This bug is similar : https://bugs.launchpad.net/heat/+bug/1226483

I tried to use Number type parameter in template.
But it doesn't work, the following error occurs:

==================================================
$ heat stack-create -f num.template -P "v_ip_version=4" test2
ERROR: Property error : r_subnet: ip_version value is not an integer
==================================================

The template file is:
==================================================
{
  "AWSTemplateFormatVersion" : "2010-09-09",
  "Parameters" : {
    "v_ip_version" : {
      "Type" : "Number"
    }
  },
  "Resources" : {
    "r_net": {
      "Type": "OS::Neutron::Net",
      "Properties": {
        "name": "r_net"
      }
    },
    "r_subnet": {
      "Type": "OS::Neutron::Subnet",
      "Properties": {
        "network_id": { "Ref" : "r_net" },
        "ip_version": { "Ref" : "v_ip_version" },
        "cidr": "192.168.0.0/24"
      }
    }
  }
}
==================================================

I think, Class NumberParam have to return casted value, like follows.

==================================================
class NumberParam(Parameter):
    '''A template parameter of type "Number".'''

    def __int__(self):
        '''Return an integer representation of the parameter'''
        return int(self.value())

    def __float__(self):
        '''Return a float representation of the parameter'''
        return float(self.value())

+ def value(self):
+ return int(self.user_value or self.default())

    def validate(self, val):
        self.schema.validate(self.name, val)
==================================================

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/50910

Changed in heat:
assignee: nobody → Mitsuru Kanabuchi (kanabuchi)
status: New → In Progress
Steven Hardy (shardy)
Changed in heat:
milestone: none → icehouse-1
importance: Undecided → High
Steven Hardy (shardy)
tags: added: havana-rc-potential
tags: added: havana-backport-potential
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to heat (master)

Reviewed: https://review.openstack.org/50910
Committed: http://github.com/openstack/heat/commit/ce62192a76a6e01b735a502c70d66d5b6eefe423
Submitter: Jenkins
Branch: master

commit ce62192a76a6e01b735a502c70d66d5b6eefe423
Author: Mitsuru Kanabuchi <email address hidden>
Date: Thu Oct 10 20:42:42 2013 +0900

    Return Integer or Float casted value in NumberParam

    Integer value used in parameter, so failed validation in properties.
    The solution here is return Integer casted value or Float casted value
    as value of NumberParam.

    The method of which type choose for cast is same of Property.str_to_num.

    Fixes bug #1226494

    Change-Id: I9f7d894ffae8a728dce783d5881af3d377268b93

Changed in heat:
status: In Progress → Fix Committed
Steven Hardy (shardy)
Changed in heat:
milestone: icehouse-1 → havana-rc2
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to heat (milestone-proposed)

Fix proposed to branch: milestone-proposed
Review: https://review.openstack.org/51364

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

Reviewed: https://review.openstack.org/51364
Committed: http://github.com/openstack/heat/commit/d9efd01f1f75b663485999ce67beeeed9298010d
Submitter: Jenkins
Branch: milestone-proposed

commit d9efd01f1f75b663485999ce67beeeed9298010d
Author: Mitsuru Kanabuchi <email address hidden>
Date: Thu Oct 10 20:42:42 2013 +0900

    Return Integer or Float casted value in NumberParam

    Integer value used in parameter, so failed validation in properties.
    The solution here is return Integer casted value or Float casted value
    as value of NumberParam.

    The method of which type choose for cast is same of Property.str_to_num.

    Fixes bug #1226494

    Change-Id: I9f7d894ffae8a728dce783d5881af3d377268b93

Changed in heat:
status: Fix Committed → Fix Released
Thierry Carrez (ttx)
Changed in heat:
milestone: havana-rc2 → 2013.2
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.