From f911ebbd670babc8052ec13bf829f6b3216db9c3 Mon Sep 17 00:00:00 2001 From: Thomas Herve Date: Tue, 20 Jun 2017 16:21:11 +0200 Subject: [PATCH] Ignore string default for software config input We recently (I87edc0d8f1fba2fb61276c682a60c1b2241b5705) enforced default type for software config input, whereas it was always a string before. It causes issues with upgrades, as we used to store "" as a default for all configs regarless of their type, and it failed when we started validating. This identifies this case and skip validation. Change-Id: I8a4f4e834b0862ecef4b97f208f4b03be3572e86 Closes-Bug: #1697627 --- heat/engine/software_config_io.py | 15 ++++++++++----- heat/tests/engine/service/test_software_config.py | 8 ++++++++ 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/heat/engine/software_config_io.py b/heat/engine/software_config_io.py index 5685fc3b79..8ca2d28f7b 100644 --- a/heat/engine/software_config_io.py +++ b/heat/engine/software_config_io.py @@ -129,11 +129,16 @@ class InputConfig(IOConfig): def __init__(self, value=_no_value, **config): if TYPE in config and DEFAULT in config: - self.schema = copy.deepcopy(self.schema) - config_param = parameters.Schema.from_dict( - 'config', {'Type': config[TYPE]}) - self.schema[DEFAULT] = properties.Schema.from_parameter( - config_param) + if config[DEFAULT] == '' and config[TYPE] != STRING_TYPE: + # This is a legacy path, because default used to be of string + # type, so we need to skip schema validation in this case. + pass + else: + self.schema = copy.deepcopy(self.schema) + config_param = parameters.Schema.from_dict( + 'config', {'Type': config[TYPE]}) + self.schema[DEFAULT] = properties.Schema.from_parameter( + config_param) super(InputConfig, self).__init__(**config) self._value = value diff --git a/heat/tests/engine/service/test_software_config.py b/heat/tests/engine/service/test_software_config.py index ee474b9f02..c99d15565e 100644 --- a/heat/tests/engine/service/test_software_config.py +++ b/heat/tests/engine/service/test_software_config.py @@ -1058,3 +1058,11 @@ class SoftwareConfigIOSchemaTest(common.HeatTestCase): inp = swc_io.InputConfig(name=name, type='Number', default='0') self.assertEqual(0, inp.default()) + + def test_input_config_value_ignore_string(self): + name = 'baz' + inp = swc_io.InputConfig(name=name, type='Number', + default='') + + self.assertEqual({'type': 'Number', 'name': 'baz', 'default': ''}, + inp.as_dict())