Handle TemplateResouces with the wrong template extension
Change-Id: Ifcd7a5728fcdb61146ad6461697756ea46e9ab96
This commit is contained in:
@@ -46,6 +46,15 @@ class TemplateResource(stack_resource.StackResource):
|
||||
tri = stack.env.get_resource_info(
|
||||
json_snippet['Type'],
|
||||
registry_type=environment.TemplateResourceInfo)
|
||||
if tri is None:
|
||||
self.validation_exception = ValueError(_(
|
||||
'Only Templates with an extension of .yaml or '
|
||||
'.template are supported'))
|
||||
self.properties_schema = {}
|
||||
self.attributes_schema = {}
|
||||
super(TemplateResource, self).__init__(name, json_snippet, stack)
|
||||
return
|
||||
|
||||
self.template_name = tri.template_name
|
||||
if tri.user_resource:
|
||||
self.allowed_schemes = ('http', 'https')
|
||||
|
||||
@@ -492,6 +492,28 @@ class ProviderTemplateTest(HeatTestCase):
|
||||
self.assertRaises(exception.StackValidationFailed, temp_res.validate)
|
||||
self.m.VerifyAll()
|
||||
|
||||
def test_user_template_retrieve_fail_ext(self):
|
||||
# make sure that a TemplateResource defined in the user environment
|
||||
# fails gracefully if the template file is the wrong extension
|
||||
# we should be able to create the TemplateResource object, but
|
||||
# validation should fail, when the second attempt to access it is
|
||||
# made in validate()
|
||||
env = environment.Environment()
|
||||
test_templ_name = 'http://heatr/letter_to_granny.docx'
|
||||
env.load({'resource_registry':
|
||||
{'Test::Flippy': test_templ_name}})
|
||||
stack = parser.Stack(utils.dummy_context(), 'test_stack',
|
||||
parser.Template({}), env=env,
|
||||
stack_id=uuidutils.generate_uuid())
|
||||
|
||||
self.m.ReplayAll()
|
||||
|
||||
temp_res = template_resource.TemplateResource('test_t_res',
|
||||
{"Type": 'Test::Flippy'},
|
||||
stack)
|
||||
self.assertRaises(exception.StackValidationFailed, temp_res.validate)
|
||||
self.m.VerifyAll()
|
||||
|
||||
def create_stack(self, template):
|
||||
t = template_format.parse(template)
|
||||
stack = self.parse_stack(t)
|
||||
|
||||
Reference in New Issue
Block a user