From ea6ae8bfe135802cfc39ff83e08f5e27bc0bbabf Mon Sep 17 00:00:00 2001 From: hmonika Date: Fri, 22 Apr 2016 18:58:46 +0530 Subject: [PATCH] string parameter type mismatch Added the new method to convert numeric value to string. Change-Id: Ib0b4273d1a77ee599bf21fe8a1059869ade98aef Closes-Bug: #1567373 --- heat/engine/constraints.py | 2 +- heat/engine/parameters.py | 3 +++ heat/tests/test_parameters.py | 16 +++++++++++++++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/heat/engine/constraints.py b/heat/engine/constraints.py index e15e36000..ade24d370 100644 --- a/heat/engine/constraints.py +++ b/heat/engine/constraints.py @@ -195,7 +195,7 @@ class Schema(collections.Mapping): elif self.type == self.NUMBER: return Schema.str_to_num(value) elif self.type == self.STRING: - return str(value) + return six.text_type(value) elif self.type == self.BOOLEAN: return strutils.bool_from_string(str(value), strict=True) except ValueError: diff --git a/heat/engine/parameters.py b/heat/engine/parameters.py index fbf90531c..8c13d6b6b 100644 --- a/heat/engine/parameters.py +++ b/heat/engine/parameters.py @@ -340,6 +340,9 @@ class StringParam(Parameter): def _validate(self, val, context): self.schema.validate_value(val, context) + def value(self): + return self.schema.to_schema_type(super(StringParam, self).value()) + class ParsedParameter(Parameter): """A template parameter with cached parsed value.""" diff --git a/heat/tests/test_parameters.py b/heat/tests/test_parameters.py index 67791f8d5..1ece0367d 100644 --- a/heat/tests/test_parameters.py +++ b/heat/tests/test_parameters.py @@ -73,7 +73,21 @@ class ParameterTestCommon(common.HeatTestCase): expected='True', allowed_value=[False], zero=False, - default=True)) + default=True)), + ('type_int_string', dict(p_type='String', + inst=parameters.StringParam, + value='111', + expected='111', + allowed_value=['111'], + zero='', + default='0')), + ('type_string_json', dict(p_type='Json', + inst=parameters.JsonParam, + value={'1': 1}, + expected='{"1": 1}', + allowed_value=[{'2': '2'}], + zero={}, + default={'3': 3})) ] def test_new_param(self):