Skip to content

Commit

Permalink
Merge branch 'ah/1451-bugfix-clienterror' into release-candidate-4.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-harvey-z3q committed Jun 4, 2024
2 parents e8ca941 + 0eba7f7 commit c69ffe8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 29 deletions.
32 changes: 8 additions & 24 deletions sceptre/plan/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,16 +307,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 @@ -368,15 +363,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 @@ -804,16 +795,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 @@ -571,14 +571,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 @@ -934,13 +935,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 @@ -953,7 +954,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

0 comments on commit c69ffe8

Please sign in to comment.