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

fix: display no outputs if outputs are not defined. #1790

Merged
merged 1 commit into from
Feb 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions samcli/lib/deploy/deployer.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,8 @@ def wait_for_execute(self, stack_name, changeset_type):
raise deploy_exceptions.DeployFailedError(stack_name=stack_name, msg=str(ex))

outputs = self.get_stack_outputs(stack_name=stack_name, echo=False)
self._stack_outputs(outputs)
if outputs:
self._display_stack_outputs(outputs)

def create_and_wait_for_changeset(
self, stack_name, cfn_template, parameter_values, capabilities, role_arn, notification_arns, s3_uploader, tags
Expand All @@ -419,7 +420,7 @@ def create_and_wait_for_changeset(
@pprint_column_names(
format_string=OUTPUTS_FORMAT_STRING, format_kwargs=OUTPUTS_DEFAULTS_ARGS, table_header=OUTPUTS_TABLE_HEADER_NAME
)
def _stack_outputs(self, stack_outputs, **kwargs):
def _display_stack_outputs(self, stack_outputs, **kwargs):
for counter, output in enumerate(stack_outputs):
for k, v in [
("Key", output.get("OutputKey")),
Expand Down Expand Up @@ -448,7 +449,7 @@ def get_stack_outputs(self, stack_name, echo=True):
if echo:
sys.stdout.write("\nStack {stack_name} outputs:\n".format(stack_name=stack_name))
sys.stdout.flush()
self._stack_outputs(stack_outputs=outputs)
self._display_stack_outputs(stack_outputs=outputs)
return outputs
except KeyError:
return None
Expand Down
28 changes: 28 additions & 0 deletions tests/unit/lib/deploy/test_deployer.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,3 +598,31 @@ def test_get_stack_outputs_exception(self):

with self.assertRaises(DeployStackOutPutFailedError):
self.deployer.get_stack_outputs(stack_name="test")

@patch("time.sleep")
def test_wait_for_execute_no_outputs(self, patched_time):
self.deployer.describe_stack_events = MagicMock()
self.deployer._client.get_waiter = MagicMock(return_value=MockCreateUpdateWaiter())
self.deployer._display_stack_outputs = MagicMock()
self.deployer.get_stack_outputs = MagicMock(return_value=None)
self.deployer.wait_for_execute("test", "CREATE")
self.assertEqual(self.deployer._display_stack_outputs.call_count, 0)

@patch("time.sleep")
def test_wait_for_execute_with_outputs(self, patched_time):
self.deployer.describe_stack_events = MagicMock()
outputs = {
"Stacks": [
{
"Outputs": [
{"OutputKey": "Key1", "OutputValue": "Value1", "Description": "output for s3"},
{"OutputKey": "Key2", "OutputValue": "Value2", "Description": "output for kms"},
]
}
]
}
self.deployer._client.get_waiter = MagicMock(return_value=MockCreateUpdateWaiter())
self.deployer._display_stack_outputs = MagicMock()
self.deployer.get_stack_outputs = MagicMock(return_value=outputs["Stacks"][0]["Outputs"])
self.deployer.wait_for_execute("test", "CREATE")
self.assertEqual(self.deployer._display_stack_outputs.call_count, 1)