Use appropriate exception in StackResource.get_output()
Don't raise InvalidTemplateAttribute in StackResource.get_output() when an output does not exist - it's not the case that get_output() is only used for fetching attributes. Instead, raise NotFound from get_output(), and translate that to InvalidTemplateAttribute in the caller when we are actually fetching an attribute. Change-Id: I4f883e4b583a965785d0a595c8c33b47dc94118c Related-Bug: #1719333
This commit is contained in:
parent
622af9952b
commit
2e4a6e237c
|
@ -85,7 +85,11 @@ class NestedStack(stack_resource.StackResource):
|
|||
if key and not key.startswith('Outputs.'):
|
||||
raise exception.InvalidTemplateAttribute(resource=self.name,
|
||||
key=key)
|
||||
attribute = self.get_output(key.partition('.')[-1])
|
||||
try:
|
||||
attribute = self.get_output(key.partition('.')[-1])
|
||||
except exception.NotFound:
|
||||
raise exception.InvalidTemplateAttribute(resource=self.name,
|
||||
key=key)
|
||||
return attributes.select_from_attribute(attribute, path)
|
||||
|
||||
def get_reference_id(self):
|
||||
|
|
|
@ -628,7 +628,11 @@ backend servers
|
|||
def _resolve_attribute(self, name):
|
||||
"""We don't really support any of these yet."""
|
||||
if name == self.DNS_NAME:
|
||||
return self.get_output('PublicIp')
|
||||
try:
|
||||
return self.get_output('PublicIp')
|
||||
except exception.NotFound:
|
||||
raise exception.InvalidTemplateAttribute(resource=self.name,
|
||||
key=name)
|
||||
elif name in self.attributes_schema:
|
||||
# Not sure if we should return anything for the other attribs
|
||||
# since they aren't really supported in any meaningful way
|
||||
|
|
|
@ -606,10 +606,7 @@ class StackResource(resource.Resource):
|
|||
def get_output(self, op):
|
||||
"""Return the specified Output value from the nested stack.
|
||||
|
||||
If the output key does not exist, raise an InvalidTemplateAttribute
|
||||
exception. (Note that TemplateResource.get_attribute() relies on this
|
||||
particular exception, not KeyError, being raised if the key does not
|
||||
exist.)
|
||||
If the output key does not exist, raise a NotFound exception.
|
||||
"""
|
||||
if (self._outputs is None or
|
||||
(op in self._outputs and
|
||||
|
@ -626,8 +623,8 @@ class StackResource(resource.Resource):
|
|||
self._outputs = {o[rpc_api.OUTPUT_KEY]: o for o in outputs}
|
||||
|
||||
if op not in self._outputs:
|
||||
raise exception.InvalidTemplateAttribute(resource=self.name,
|
||||
key=op)
|
||||
raise exception.NotFound(_('Specified output key %s not '
|
||||
'found.') % op)
|
||||
|
||||
output_data = self._outputs[op]
|
||||
if rpc_api.OUTPUT_ERROR in output_data:
|
||||
|
@ -639,4 +636,8 @@ class StackResource(resource.Resource):
|
|||
return output_data[rpc_api.OUTPUT_VALUE]
|
||||
|
||||
def _resolve_attribute(self, name):
|
||||
return self.get_output(name)
|
||||
try:
|
||||
return self.get_output(name)
|
||||
except exception.NotFound:
|
||||
raise exception.InvalidTemplateAttribute(resource=self.name,
|
||||
key=name)
|
||||
|
|
|
@ -330,7 +330,7 @@ class TemplateResource(stack_resource.StackResource):
|
|||
message=output[rpc_api.OUTPUT_ERROR])
|
||||
except exception.TemplateOutputError as err:
|
||||
LOG.info('%s', err)
|
||||
except (exception.InvalidTemplateAttribute, exception.NotFound):
|
||||
except exception.NotFound:
|
||||
pass
|
||||
else:
|
||||
self._reference_id = output[rpc_api.OUTPUT_VALUE]
|
||||
|
@ -347,4 +347,9 @@ class TemplateResource(stack_resource.StackResource):
|
|||
return grouputils.get_nested_attrs(self, key, False, *path)
|
||||
|
||||
# then look for normal outputs
|
||||
return attributes.select_from_attribute(self.get_output(key), path)
|
||||
try:
|
||||
return attributes.select_from_attribute(self.get_output(key),
|
||||
path)
|
||||
except exception.NotFound:
|
||||
raise exception.InvalidTemplateAttribute(resource=self.name,
|
||||
key=key)
|
||||
|
|
|
@ -689,7 +689,7 @@ class StackResourceAttrTest(StackResourceBaseTest):
|
|||
output = {'outputs': []}
|
||||
self.parent_resource._rpc_client.show_stack.return_value = [output]
|
||||
|
||||
self.assertRaises(exception.InvalidTemplateAttribute,
|
||||
self.assertRaises(exception.NotFound,
|
||||
self.parent_resource.get_output,
|
||||
"key")
|
||||
|
||||
|
@ -701,7 +701,7 @@ class StackResourceAttrTest(StackResourceBaseTest):
|
|||
output = {}
|
||||
self.parent_resource._rpc_client.show_stack.return_value = [output]
|
||||
|
||||
self.assertRaises(exception.InvalidTemplateAttribute,
|
||||
self.assertRaises(exception.NotFound,
|
||||
self.parent_resource.get_output,
|
||||
"key")
|
||||
|
||||
|
|
Loading…
Reference in New Issue