Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Resolve #1451] Stop suppressing ClientError in describe_outputs #1452

Merged
32 changes: 8 additions & 24 deletions sceptre/plan/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,16 +303,11 @@ def describe(self):
:returns: A Stack description.
:rtype: dict
"""
try:
return self.connection_manager.call(
service="cloudformation",
command="describe_stacks",
kwargs={"StackName": self.stack.external_name},
)
except botocore.exceptions.ClientError as e:
if e.response["Error"]["Message"].endswith("does not exist"):
return
raise
return self.connection_manager.call(
service="cloudformation",
command="describe_stacks",
kwargs={"StackName": self.stack.external_name},
)

def describe_events(self):
"""
Expand Down Expand Up @@ -364,15 +359,11 @@ def describe_outputs(self):
"""
Returns the Stack's outputs.

:returns: The Stack's outputs.
:returns: The stack's outputs.
:rtype: list
"""
self.logger.debug("%s - Describing stack outputs", self.stack.name)

try:
response = self._describe()
except botocore.exceptions.ClientError:
return []
response = self.describe()

return {self.stack.name: response["Stacks"][0].get("Outputs", [])}

Expand Down Expand Up @@ -784,16 +775,9 @@ def timed_out(elapsed):

return status

def _describe(self):
return self.connection_manager.call(
service="cloudformation",
command="describe_stacks",
kwargs={"StackName": self.stack.external_name},
)

def _get_status(self):
try:
status = self._describe()["Stacks"][0]["StackStatus"]
status = self.describe()["Stacks"][0]["StackStatus"]
except botocore.exceptions.ClientError as exp:
if exp.response["Error"]["Message"].endswith("does not exist"):
raise StackDoesNotExistError(exp.response["Error"]["Message"])
Expand Down
11 changes: 6 additions & 5 deletions tests/test_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,14 +556,15 @@ def test_describe_resources_sends_correct_request(self):
]
}

@patch("sceptre.plan.actions.StackActions._describe")
@patch("sceptre.plan.actions.StackActions.describe")
def test_describe_outputs_sends_correct_request(self, mock_describe):
mock_describe.return_value = {"Stacks": [{"Outputs": sentinel.outputs}]}
response = self.actions.describe_outputs()

mock_describe.assert_called_once_with()
assert response == {self.stack.name: sentinel.outputs}

@patch("sceptre.plan.actions.StackActions._describe")
@patch("sceptre.plan.actions.StackActions.describe")
def test_describe_outputs_handles_stack_with_no_outputs(self, mock_describe):
mock_describe.return_value = {"Stacks": [{}]}
response = self.actions.describe_outputs()
Expand Down Expand Up @@ -892,13 +893,13 @@ def test_format_parameters_with_none_list_and_string_values(self):
{"ParameterKey": "key2", "ParameterValue": "value4"},
]

@patch("sceptre.plan.actions.StackActions._describe")
@patch("sceptre.plan.actions.StackActions.describe")
def test_get_status_with_created_stack(self, mock_describe):
mock_describe.return_value = {"Stacks": [{"StackStatus": "CREATE_COMPLETE"}]}
status = self.actions.get_status()
assert status == "CREATE_COMPLETE"

@patch("sceptre.plan.actions.StackActions._describe")
@patch("sceptre.plan.actions.StackActions.describe")
def test_get_status_with_non_existent_stack(self, mock_describe):
mock_describe.side_effect = ClientError(
{
Expand All @@ -911,7 +912,7 @@ def test_get_status_with_non_existent_stack(self, mock_describe):
)
assert self.actions.get_status() == "PENDING"

@patch("sceptre.plan.actions.StackActions._describe")
@patch("sceptre.plan.actions.StackActions.describe")
def test_get_status_with_unknown_clinet_error(self, mock_describe):
mock_describe.side_effect = ClientError(
{"Error": {"Code": "DoesNotExistException", "Message": "Boom!"}},
Expand Down