Do not throw an exception if stack outputs is not set

In some rare cases, stack output is not set and this line throws
an exception. This causes stack deletion to fail.

Change-Id: I7710f160ee881e355e3a3541fe8729b06ff29b38
Closes-Bug: #1638741
Co-Authored-By: Crag Wolfe <cwolfe@redhat.com>
This commit is contained in:
Abhishek Chanda 2016-11-08 23:56:45 +00:00 committed by Crag Wolfe
parent 055b8ce884
commit 349e67b451
2 changed files with 13 additions and 1 deletions

View File

@ -596,7 +596,7 @@ class StackResource(resource.Resource):
dict(stack_identity))
if not stack:
return
outputs = stack[0][rpc_api.STACK_OUTPUTS]
outputs = stack[0].get(rpc_api.STACK_OUTPUTS) or {}
self._outputs = {o[rpc_api.OUTPUT_KEY]: o[rpc_api.OUTPUT_VALUE]
for o in outputs if rpc_api.OUTPUT_ERROR not in o}

View File

@ -643,6 +643,18 @@ class StackResourceAttrTest(StackResourceBaseTest):
self.parent_resource.get_output,
"key")
def test_get_output_key_no_outputs_from_rpc(self):
self.parent_resource.nested_identifier = mock.Mock()
self.parent_resource.nested_identifier.return_value = {'foo': 'bar'}
self.parent_resource._rpc_client = mock.MagicMock()
output = {}
self.parent_resource._rpc_client.show_stack.return_value = [output]
self.assertRaises(exception.InvalidTemplateAttribute,
self.parent_resource.get_output,
"key")
def test_resolve_attribute_string(self):
self.parent_resource.nested_identifier = mock.Mock()
self.parent_resource.nested_identifier.return_value = {'foo': 'bar'}