Merge "Raise InvalidTemplateReference for missing resources"

This commit is contained in:
Jenkins 2014-04-30 16:51:25 +00:00 committed by Gerrit Code Review
commit 44f91f0186
3 changed files with 14 additions and 10 deletions

View File

@ -85,8 +85,9 @@ class ParamRef(function.Function):
try: try:
return self.parameters[param_name] return self.parameters[param_name]
except (KeyError, ValueError): except KeyError:
raise exception.UserParameterMissing(key=param_name) raise exception.InvalidTemplateReference(resource=param_name,
key='unknown')
class ResourceRef(function.Function): class ResourceRef(function.Function):
@ -98,10 +99,14 @@ class ResourceRef(function.Function):
{ "Ref" : "<resource_name>" } { "Ref" : "<resource_name>" }
''' '''
def _resource(self): def _resource(self, path='unknown'):
resource_name = function.resolve(self.args) resource_name = function.resolve(self.args)
return self.stack[resource_name] try:
return self.stack[resource_name]
except KeyError:
raise exception.InvalidTemplateReference(resource=resource_name,
key=path)
def result(self): def result(self):
return self._resource().FnGetRefId() return self._resource().FnGetRefId()
@ -150,15 +155,14 @@ class GetAtt(function.Function):
return resource_name, attribute return resource_name, attribute
def _resource(self): def _resource(self, path='unknown'):
resource_name = function.resolve(self._resource_name) resource_name = function.resolve(self._resource_name)
try: try:
return self.stack[resource_name] return self.stack[resource_name]
except KeyError: except KeyError:
raise exception.InvalidTemplateAttribute( raise exception.InvalidTemplateReference(resource=resource_name,
resource=resource_name, key=path)
key=function.resolve(self._attribute))
def result(self): def result(self):
attribute = function.resolve(self._attribute) attribute = function.resolve(self._attribute)

View File

@ -220,7 +220,7 @@ class Parameter(object):
if self.has_default(): if self.has_default():
return self.default() return self.default()
raise KeyError(_('Missing parameter %s') % self.name) raise exception.UserParameterMissing(key=self.name)
def hidden(self): def hidden(self):
''' '''

View File

@ -649,7 +649,7 @@ class StackTest(test_parser.StackTest):
self.stack.state) self.stack.state)
snippet = {'Value': {'get_attr': ['resource2', 'who_cares']}} snippet = {'Value': {'get_attr': ['resource2', 'who_cares']}}
self.assertRaises(exception.InvalidTemplateAttribute, self.assertRaises(exception.InvalidTemplateReference,
self.resolve, snippet) self.resolve, snippet)
@utils.stack_delete_after @utils.stack_delete_after