Merge "Don't set any type on input config default"
This commit is contained in:
commit
924b5ff851
|
@ -16,12 +16,14 @@ APIs for dealing with input and output definitions for Software Configurations.
|
|||
"""
|
||||
|
||||
import collections
|
||||
import copy
|
||||
import six
|
||||
|
||||
from heat.common.i18n import _
|
||||
|
||||
from heat.common import exception
|
||||
from heat.engine import constraints
|
||||
from heat.engine import parameters
|
||||
from heat.engine import properties
|
||||
|
||||
|
||||
|
@ -59,7 +61,7 @@ input_config_schema = {
|
|||
constraints=[constraints.AllowedValues(TYPES)]
|
||||
),
|
||||
DEFAULT: properties.Schema(
|
||||
properties.Schema.STRING,
|
||||
properties.Schema.ANY,
|
||||
_('Default value for the input if none is specified.'),
|
||||
),
|
||||
REPLACE_ON_CHANGE: properties.Schema(
|
||||
|
@ -126,6 +128,12 @@ class InputConfig(IOConfig):
|
|||
schema = input_config_schema
|
||||
|
||||
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)
|
||||
super(InputConfig, self).__init__(**config)
|
||||
self._value = value
|
||||
|
||||
|
|
|
@ -949,11 +949,11 @@ class SoftwareConfigIOSchemaTest(common.HeatTestCase):
|
|||
name = 'bar'
|
||||
inp = swc_io.InputConfig(name=name, description='test', type='Number',
|
||||
default=0, replace_on_change=True)
|
||||
self.assertEqual('0', inp.default())
|
||||
self.assertEqual(0, inp.default())
|
||||
self.assertIs(True, inp.replace_on_change())
|
||||
self.assertEqual(name, inp.name())
|
||||
self.assertEqual({'name': name, 'type': 'Number',
|
||||
'description': 'test', 'default': '0',
|
||||
'description': 'test', 'default': 0,
|
||||
'replace_on_change': True},
|
||||
inp.as_dict())
|
||||
self.assertEqual((name, None), inp.input_data())
|
||||
|
@ -962,11 +962,11 @@ class SoftwareConfigIOSchemaTest(common.HeatTestCase):
|
|||
name = 'baz'
|
||||
inp = swc_io.InputConfig(name=name, type='Number',
|
||||
default=0, value=42)
|
||||
self.assertEqual('0', inp.default())
|
||||
self.assertEqual(0, inp.default())
|
||||
self.assertIs(False, inp.replace_on_change())
|
||||
self.assertEqual(name, inp.name())
|
||||
self.assertEqual({'name': name, 'type': 'Number',
|
||||
'default': '0', 'value': 42},
|
||||
'default': 0, 'value': 42},
|
||||
inp.as_dict())
|
||||
self.assertEqual((name, 42), inp.input_data())
|
||||
|
||||
|
@ -1046,3 +1046,15 @@ class SoftwareConfigIOSchemaTest(common.HeatTestCase):
|
|||
def test_check_io_schema_list_mixed(self):
|
||||
self.assertRaises(TypeError, swc_io.check_io_schema_list,
|
||||
[{'name': 'foo'}, ('name', 'bar')])
|
||||
|
||||
def test_input_config_value_json_default(self):
|
||||
name = 'baz'
|
||||
inp = swc_io.InputConfig(name=name, type='Json',
|
||||
default={'a': 1}, value=42)
|
||||
self.assertEqual({'a': 1}, inp.default())
|
||||
|
||||
def test_input_config_value_default_coerce(self):
|
||||
name = 'baz'
|
||||
inp = swc_io.InputConfig(name=name, type='Number',
|
||||
default='0')
|
||||
self.assertEqual(0, inp.default())
|
||||
|
|
Loading…
Reference in New Issue