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
This commit is contained in:
Thomas Herve 2017-06-20 16:21:11 +02:00
parent a5ac2c3b1d
commit f911ebbd67
2 changed files with 18 additions and 5 deletions

View File

@ -129,6 +129,11 @@ class InputConfig(IOConfig):
def __init__(self, value=_no_value, **config):
if TYPE in config and DEFAULT in config:
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]})

View File

@ -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())