Change type validate method of template resource

The type of template Resource property schema converted from parameter
is the same as input parameter type, including Number/String/Map/List.
Resource property schema type includes
Integer/String/Number/Boolean/Map/List. The Integer type is converted
from Number type, while Boolean type from String type.

Change-Id: Ic8ba281b5fb6e17a25fb8b5ba6a1102c827e42b9
Closes-Bug:#1317129
This commit is contained in:
Yaoguo Jiang 2014-05-31 08:23:42 +00:00 committed by Steve Baker
parent 7aa79d3430
commit e29fa7c10f
3 changed files with 50 additions and 1 deletions

View File

@ -147,6 +147,24 @@ class Schema(constr.Schema):
constraints=param.constraints,
update_allowed=True)
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

@ -356,6 +356,37 @@ class ProviderTemplateTest(HeatTestCase):
self.assertRaises(exception.StackValidationFailed,
temp_res.validate)
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',