Don't change properties in regenerate_info_schema

The definition of TemplateResource.regenerate_info_schema() has the effect
of changing the semantics of handle_update() in odd ways. For all other
resource types, self.properties is set to the existing properties
definition of the resource at the time that handle_update() is called
(passing the new resource definition as an argument. However,
TemplateResource is an exception because regenerate_info_schema() replaces
self.properties with the new values from the new resource definition.

To reduce confusion and make all resources consistent in their semantics,
this change refactors the change of the properties definition out of the
_generate_schema() method that is called by regenerate_info_schema().

Change-Id: Iab23ae39d05f8290dad02775dddd2e856b29951a
Related-Bug: #1584623
This commit is contained in:
Zane Bitter 2016-08-05 10:26:43 -04:00
parent 05007cf27a
commit 025c4fe1d3
2 changed files with 7 additions and 6 deletions

View File

@ -543,7 +543,7 @@ class Resource(object):
"""
update_allowed_set = set(self.update_allowed_properties)
immutable_set = set()
for (psk, psv) in six.iteritems(self.properties.props):
for (psk, psv) in six.iteritems(after_props.props):
if psv.update_allowed():
update_allowed_set.add(psk)
if psv.immutable():

View File

@ -63,7 +63,8 @@ class TemplateResource(stack_resource.StackResource):
super(TemplateResource, self).__init__(name, json_snippet, stack)
self.resource_info = tri
if self.validation_exception is None:
self._generate_schema(self.t)
self._generate_schema()
self.reparse()
def _get_resource_info(self, rsrc_defn):
try:
@ -103,7 +104,7 @@ class TemplateResource(stack_resource.StackResource):
(attributes.Attributes.schema_from_outputs(
tmpl[tmpl.OUTPUTS])))
def _generate_schema(self, definition):
def _generate_schema(self):
self._parsed_nested = None
try:
tmpl = template.Template(self.child_template())
@ -116,8 +117,6 @@ class TemplateResource(stack_resource.StackResource):
self.properties_schema, self.attributes_schema = self.get_schemas(
tmpl, self.stack.env.param_defaults)
self.properties = definition.properties(self.properties_schema,
self.context)
self.attributes_schema.update(self.base_attributes_schema)
self.attributes = attributes.Attributes(self.name,
self.attributes_schema,
@ -177,7 +176,7 @@ class TemplateResource(stack_resource.StackResource):
def regenerate_info_schema(self, definition):
self._get_resource_info(definition)
self._generate_schema(definition)
self._generate_schema()
def template_data(self):
# we want to have the latest possible template.
@ -289,6 +288,8 @@ class TemplateResource(stack_resource.StackResource):
self.metadata_set(self.t.metadata())
def handle_update(self, json_snippet, tmpl_diff, prop_diff):
self.properties = json_snippet.properties(self.properties_schema,
self.context)
return self.update_with_template(self.child_template(),
self.child_params())