Fix property validation for TemplateResource during update

This fix adds schema regeneration before props are validated
for TemplateResource during stack-update.

Change-Id: Ia79a25083489f48ed7332fbbd089a0090452cdc4
Closes-Bug: #1452983
Closes-Bug: #1453923
This commit is contained in:
Rabi Mishra 2015-05-13 16:39:04 +05:30
parent 17ff1592f5
commit 141597f032
3 changed files with 113 additions and 5 deletions

View File

@ -746,6 +746,8 @@ class Resource(object):
before_props = before.properties(self.properties_schema,
self.context)
# Regenerate the schema, else validation would fail
self.regenerate_info_schema(after)
after_props = after.properties(self.properties_schema,
self.context)
@ -1062,6 +1064,16 @@ class Resource(object):
# By default, no attributes resolve
pass
def regenerate_info_schema(self, definition):
"""
Default implementation; should be overridden by resources that would
require schema refresh during update, ex. TemplateResource
:definition: Resource Definition
"""
# By default, do not regenerate
pass
def state_reset(self):
"""
Reset state to (INIT, COMPLETE)

View File

@ -161,6 +161,10 @@ class TemplateResource(stack_resource.StackResource):
self._parsed_nested = template_format.parse(self.template_data())
return self._parsed_nested
def regenerate_info_schema(self, definition):
self._get_resource_info(definition)
self._generate_schema(definition)
def implementation_signature(self):
self._generate_schema(self.t)
return super(TemplateResource, self).implementation_signature()
@ -267,8 +271,6 @@ class TemplateResource(stack_resource.StackResource):
self.metadata_set(self.t.metadata())
def handle_update(self, json_snippet, tmpl_diff, prop_diff):
self._get_resource_info(json_snippet)
self._generate_schema(json_snippet)
return self.update_with_template(self.child_template(),
self.child_params())

View File

@ -251,6 +251,22 @@ Resources:
Type: the.yaml
Properties:
one: my_name
two: your_name
Outputs:
identifier:
Value: {Ref: the_nested}
value:
Value: {'Fn::GetAtt': [the_nested, the_str]}
'''
main_template_change_prop = '''
HeatTemplateFormatVersion: '2012-12-12'
Resources:
the_nested:
Type: the.yaml
Properties:
one: updated_name
two: your_name
Outputs:
identifier:
@ -259,13 +275,30 @@ Outputs:
Value: {'Fn::GetAtt': [the_nested, the_str]}
'''
main_template_2 = '''
main_template_add_prop = '''
HeatTemplateFormatVersion: '2012-12-12'
Resources:
the_nested:
Type: the.yaml
Properties:
one: updated_name
one: my_name
two: your_name
three: third_name
Outputs:
identifier:
Value: {Ref: the_nested}
value:
Value: {'Fn::GetAtt': [the_nested, the_str]}
'''
main_template_remove_prop = '''
HeatTemplateFormatVersion: '2012-12-12'
Resources:
the_nested:
Type: the.yaml
Properties:
one: my_name
Outputs:
identifier:
@ -280,6 +313,10 @@ Parameters:
one:
Default: foo
Type: String
two:
Default: bar
Type: String
Resources:
NestedResource:
Type: OS::Heat::RandomString
@ -289,6 +326,7 @@ Outputs:
the_str:
Value: {'Fn::GetAtt': [NestedResource, value]}
'''
prop_change_tmpl = '''
HeatTemplateFormatVersion: '2012-12-12'
Parameters:
@ -298,6 +336,46 @@ Parameters:
two:
Default: foo
Type: String
Resources:
NestedResource:
Type: OS::Heat::RandomString
Properties:
salt: {Ref: two}
Outputs:
the_str:
Value: {'Fn::GetAtt': [NestedResource, value]}
'''
prop_add_tmpl = '''
HeatTemplateFormatVersion: '2012-12-12'
Parameters:
one:
Default: yikes
Type: String
two:
Default: foo
Type: String
three:
Default: bar
Type: String
Resources:
NestedResource:
Type: OS::Heat::RandomString
Properties:
salt: {Ref: three}
Outputs:
the_str:
Value: {'Fn::GetAtt': [NestedResource, value]}
'''
prop_remove_tmpl = '''
HeatTemplateFormatVersion: '2012-12-12'
Parameters:
one:
Default: yikes
Type: String
Resources:
NestedResource:
Type: OS::Heat::RandomString
@ -307,12 +385,17 @@ Outputs:
the_str:
Value: {'Fn::GetAtt': [NestedResource, value]}
'''
attr_change_tmpl = '''
HeatTemplateFormatVersion: '2012-12-12'
Parameters:
one:
Default: foo
Type: String
two:
Default: bar
Type: String
Resources:
NestedResource:
Type: OS::Heat::RandomString
@ -324,12 +407,17 @@ Outputs:
something_else:
Value: just_a_string
'''
content_change_tmpl = '''
HeatTemplateFormatVersion: '2012-12-12'
Parameters:
one:
Default: foo
Type: String
two:
Default: bar
Type: String
Resources:
NestedResource:
Type: OS::Heat::RandomString
@ -345,7 +433,7 @@ Outputs:
('no_changes', dict(template=main_template,
provider=initial_tmpl,
expect=NOCHANGE)),
('main_tmpl_change', dict(template=main_template_2,
('main_tmpl_change', dict(template=main_template_change_prop,
provider=initial_tmpl,
expect=UPDATE)),
('provider_change', dict(template=main_template,
@ -353,6 +441,12 @@ Outputs:
expect=UPDATE)),
('provider_props_change', dict(template=main_template,
provider=prop_change_tmpl,
expect=UPDATE)),
('provider_props_add', dict(template=main_template_add_prop,
provider=prop_add_tmpl,
expect=UPDATE)),
('provider_props_remove', dict(template=main_template_remove_prop,
provider=prop_remove_tmpl,
expect=NOCHANGE)),
('provider_attr_change', dict(template=main_template,
provider=attr_change_tmpl,