Merge "Change type validate method of template resource"

This commit is contained in:
Jenkins 2014-08-23 16:42:10 +00:00 committed by Gerrit Code Review
commit 6e3488be15
3 changed files with 50 additions and 1 deletions

View File

@ -153,6 +153,24 @@ class Schema(constr.Schema):
update_allowed=True,
immutable=False)
def allowed_param_prop_type(self):
"""
Return allowed type of Property Schema converted from parameter.
Especially, when generating Schema from parameter, Integer Property
Schema will be supplied by Number parameter.
"""
param_type_map = {
self.INTEGER: self.NUMBER,
self.STRING: self.STRING,
self.NUMBER: self.NUMBER,
self.BOOLEAN: self.BOOLEAN,
self.LIST: self.LIST,
self.MAP: self.MAP
}
return param_type_map[self.type]
def __getitem__(self, key):
if key == self.UPDATE_ALLOWED:
return self.update_allowed

View File

@ -192,7 +192,7 @@ class TemplateResource(stack_resource.StackResource):
ps = self.properties_schema.get(n)
if (n in self.properties_schema and
(fs.type != ps.type)):
(fs.allowed_param_prop_type() != ps.type)):
# Type mismatch
msg = (_("Property %(n)s type mismatch between facade %(type)s"
" (%(fs_type)s) and provider (%(ps_type)s)") % {

View File

@ -361,6 +361,37 @@ class ProviderTemplateTest(HeatTestCase):
"DummyResource (Map) and provider (String)",
six.text_type(ex))
def test_properties_type_match(self):
provider = {
'HeatTemplateFormatVersion': '2012-12-12',
'Parameters': {
'Length': {'Type': 'Number'},
},
}
files = {'test_resource.template': json.dumps(provider)}
class DummyResource(object):
properties_schema = {"Length":
properties.Schema(properties.Schema.INTEGER)}
attributes_schema = {}
env = environment.Environment()
resource._register_class('DummyResource', DummyResource)
env.load({'resource_registry':
{'DummyResource': 'test_resource.template'}})
stack = parser.Stack(utils.dummy_context(), 'test_stack',
parser.Template(
{'HeatTemplateFormatVersion': '2012-12-12'},
files=files), env=env,
stack_id=str(uuid.uuid4()))
definition = rsrc_defn.ResourceDefinition('test_t_res',
"DummyResource",
{"Length": 10})
temp_res = template_resource.TemplateResource('test_t_res',
definition, stack)
self.assertIsNone(temp_res.validate())
def test_boolean_type_provider(self):
provider = {
'HeatTemplateFormatVersion': '2012-12-12',