Update template paths for environment-mapped TemplateResources
When updating a template resource, we weren't taking into account the possibility that the new environment could be mapping the resource to a different template path. This change ensures we recalculate the template name from the new environment before reloading the template during an update. Co-Authored-By: Angus Salkeld <asalkeld@mirantis.com> Change-Id: I5f84f6fd60925d3dba0b8e8dec867657c8c5c9ef Closes-Bug: #1452534 (cherry picked from commits686f317cca
and8c37b56ace
)
This commit is contained in:
parent
d8d82bdbdc
commit
aa4b90df9d
|
@ -50,9 +50,21 @@ class TemplateResource(stack_resource.StackResource):
|
|||
self.stack = stack
|
||||
self.validation_exception = None
|
||||
|
||||
tri = stack.env.get_resource_info(
|
||||
json_snippet['Type'],
|
||||
resource_name=name,
|
||||
tri = self._get_resource_info(json_snippet)
|
||||
|
||||
self.properties_schema = {}
|
||||
self.attributes_schema = {}
|
||||
|
||||
# run Resource.__init__() so we can call self.nested()
|
||||
super(TemplateResource, self).__init__(name, json_snippet, stack)
|
||||
self.resource_info = tri
|
||||
if self.validation_exception is None:
|
||||
self._generate_schema(self.t)
|
||||
|
||||
def _get_resource_info(self, rsrc_defn):
|
||||
tri = self.stack.env.get_resource_info(
|
||||
rsrc_defn.resource_type,
|
||||
resource_name=rsrc_defn.name,
|
||||
registry_type=environment.TemplateResourceInfo)
|
||||
if tri is None:
|
||||
self.validation_exception = ValueError(_(
|
||||
|
@ -65,13 +77,7 @@ class TemplateResource(stack_resource.StackResource):
|
|||
else:
|
||||
self.allowed_schemes = ('http', 'https', 'file')
|
||||
|
||||
# run Resource.__init__() so we can call self.nested()
|
||||
self.properties_schema = {}
|
||||
self.attributes_schema = {}
|
||||
super(TemplateResource, self).__init__(name, json_snippet, stack)
|
||||
self.resource_info = tri
|
||||
if self.validation_exception is None:
|
||||
self._generate_schema(self.t)
|
||||
return tri
|
||||
|
||||
@staticmethod
|
||||
def get_template_file(template_name, allowed_schemes):
|
||||
|
@ -258,6 +264,7 @@ 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())
|
||||
|
|
|
@ -120,6 +120,36 @@ resource_registry:
|
|||
self._stack_delete(nested_ident)
|
||||
self._stack_delete(stack_identifier)
|
||||
|
||||
def test_change_in_file_path(self):
|
||||
stack_identifier = self.stack_create(
|
||||
template=self.template,
|
||||
files={'nested.yaml': self.nested_templ},
|
||||
environment=self.env_templ)
|
||||
stack = self.client.stacks.get(stack_identifier)
|
||||
secret_out1 = self._stack_output(stack, 'secret-out')
|
||||
|
||||
nested_templ_2 = '''
|
||||
heat_template_version: 2013-05-23
|
||||
resources:
|
||||
secret2:
|
||||
type: OS::Heat::RandomString
|
||||
outputs:
|
||||
value:
|
||||
value: freddy
|
||||
'''
|
||||
env_templ_2 = '''
|
||||
resource_registry:
|
||||
"OS::Heat::RandomString": new/nested.yaml
|
||||
'''
|
||||
self.update_stack(stack_identifier,
|
||||
template=self.template,
|
||||
files={'new/nested.yaml': nested_templ_2},
|
||||
environment=env_templ_2)
|
||||
stack = self.client.stacks.get(stack_identifier)
|
||||
secret_out2 = self._stack_output(stack, 'secret-out')
|
||||
self.assertNotEqual(secret_out1, secret_out2)
|
||||
self.assertEqual('freddy', secret_out2)
|
||||
|
||||
|
||||
class NestedAttributesTest(test.HeatIntegrationTest):
|
||||
"""Prove that we can use the template resource references."""
|
||||
|
|
Loading…
Reference in New Issue