From 4ddd4cb2bd6ec723d5d2137c85114a323d42a897 Mon Sep 17 00:00:00 2001 From: Steven Hardy Date: Fri, 18 Sep 2015 15:49:12 +0100 Subject: [PATCH] Always return default via template-validate "Default" Currently we redefine the value of Default when a user value is provided, which means the data returned doesn't match the schema defined in the template. Instead always return the actual default and add a "Value" key that contains the user value, if provided. Change-Id: If4ed0b733d4e61c84167063c36cdcb234b001136 Closes-Bug: #1497310 --- heat/engine/api.py | 7 +++++-- heat/rpc/api.py | 4 ++-- heat/tests/test_validate.py | 7 +++++-- .../functional/test_template_validate.py | 14 ++++++++++++++ 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/heat/engine/api.py b/heat/engine/api.py index 0cd5f1770..c8c0d08be 100644 --- a/heat/engine/api.py +++ b/heat/engine/api.py @@ -458,8 +458,11 @@ def format_validate_parameter(param): rpc_api.PARAM_LABEL: param.label() } - if param.has_value(): - res[rpc_api.PARAM_DEFAULT] = param.value() + if param.has_default(): + res[rpc_api.PARAM_DEFAULT] = param.default() + + if param.user_value: + res[rpc_api.PARAM_VALUE] = param.user_value constraint_description = [] diff --git a/heat/rpc/api.py b/heat/rpc/api.py index 9db5ee329..ae1d59f20 100644 --- a/heat/rpc/api.py +++ b/heat/rpc/api.py @@ -180,13 +180,13 @@ VALIDATE_PARAM_KEYS = ( PARAM_ALLOWED_VALUES, PARAM_ALLOWED_PATTERN, PARAM_MAX_LENGTH, PARAM_MIN_LENGTH, PARAM_MAX_VALUE, PARAM_MIN_VALUE, PARAM_DESCRIPTION, PARAM_CONSTRAINT_DESCRIPTION, PARAM_LABEL, - PARAM_CUSTOM_CONSTRAINT + PARAM_CUSTOM_CONSTRAINT, PARAM_VALUE ) = ( 'Type', 'Default', 'NoEcho', 'AllowedValues', 'AllowedPattern', 'MaxLength', 'MinLength', 'MaxValue', 'MinValue', 'Description', 'ConstraintDescription', 'Label', - 'CustomConstraint' + 'CustomConstraint', 'Value' ) VALIDATE_PARAM_TYPES = ( diff --git a/heat/tests/test_validate.py b/heat/tests/test_validate.py index a97d8a7e4..520f33474 100644 --- a/heat/tests/test_validate.py +++ b/heat/tests/test_validate.py @@ -1004,8 +1004,10 @@ class ValidateTest(common.HeatTestCase): env_params = {'net_name': 'betternetname'} engine = service.EngineService('a', 't') res = dict(engine.validate_template(None, t, env_params)) - self.assertEqual('betternetname', + self.assertEqual('defaultnet', res['Parameters']['net_name']['Default']) + self.assertEqual('betternetname', + res['Parameters']['net_name']['Value']) def test_validate_parameters_env_provided(self): t = template_format.parse(test_template_no_default) @@ -1013,7 +1015,8 @@ class ValidateTest(common.HeatTestCase): engine = service.EngineService('a', 't') res = dict(engine.validate_template(None, t, env_params)) self.assertEqual('betternetname', - res['Parameters']['net_name']['Default']) + res['Parameters']['net_name']['Value']) + self.assertNotIn('Default', res['Parameters']['net_name']) def test_validate_hot_empty_parameters_valid(self): t = template_format.parse( diff --git a/heat_integrationtests/functional/test_template_validate.py b/heat_integrationtests/functional/test_template_validate.py index 9dd0947bf..91e3e6a98 100644 --- a/heat_integrationtests/functional/test_template_validate.py +++ b/heat_integrationtests/functional/test_template_validate.py @@ -74,6 +74,20 @@ resources: 'Type': 'Number'}}} self.assertEqual(expected, ret) + def test_template_validate_override_default(self): + env = {'parameters': {'aparam': 5}} + ret = self.client.stacks.validate(template=self.random_template, + environment=env) + expected = {'Description': 'the stack description', + 'Parameters': { + 'aparam': {'Default': 10, + 'Value': 5, + 'Description': 'the param description', + 'Label': 'aparam', + 'NoEcho': 'false', + 'Type': 'Number'}}} + self.assertEqual(expected, ret) + def test_template_validate_basic_required_param(self): tmpl = self.random_template.replace('default: 10', '') ret = self.client.stacks.validate(template=tmpl)