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

Deploy off aws cli #1455

Merged
merged 18 commits into from
Nov 13, 2019
Merged

Conversation

sriram-mv
Copy link
Contributor

@sriram-mv sriram-mv commented Oct 9, 2019

  • Clean output of stack events as deploy progress

  • Clean output of changeset before beginning the deploy process

  • Port from AWS CLI

  • Unit tests added

  • Integration tests added

  • Regression tests added

  • Write Design Document (Do I need to write a design document?)

  • Write unit tests

  • Write/update functional tests

  • Write/update integration tests

  • make pr passes

  • Write documentation

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

This was referenced Oct 18, 2019
@sriram-mv
Copy link
Contributor Author

The number of commits appear huge, but thats because this is based off sam package PR: #1437

This is still very much in WIP.

@@ -140,7 +155,8 @@ def create_changeset(
LOG.debug("Unable to create changeset", exc_info=ex)
raise ex

def describe_changeset(self, change_set_id, stack_name):
@pprint(format_string=DESCRIBE_CHANGESET_FORMAT_STRING, format_kwargs=DESCRIBE_CHANGESET_DEFAULT_ARGS)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

click based decorator to create a table.

- Not breaking parameter overrides formats
- still requires refactoring and error handling
- wire up command.py for `sam deploy`
- move deploy specific exceptions to inherit from UserException
- `sam deploy` now has tables while showcasing the changeset and
  showcasing events happening during deploy.
- fixed unit tests
- linting fixes
- doc strings
- further unit tests and integration tests need to be added.
@sriram-mv sriram-mv changed the title [WIP] : Deploy off aws cli Deploy off aws cli Nov 7, 2019
samcli/cli/types.py Show resolved Hide resolved
value = [value]

while state.rargs and not next_option:
for prefix in self._nargs_parser.prefixes:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have or intend to support any commands where there is a trailing argument that does not have a prefix?

For example, many CLIs have a valid command that works much like the following:

cli commandname --option-one A --option-set B C D --input inputfile.txt outputfile.txt

(Where outputfile.txt is a positional argument that goes at the end of the full command.)

This code would appear to assume we never allow for that pattern. Is this a correct assumption for us?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, one way to codify that would be to add such positional argument to the front of the command. I'm not sure if there are alternate ways to check for unbounded number of arguments for a given option without a breaking change though.

"change set. Specify this flag if you want to view your stack changes"
"before executing the change set. The command creates an AWS CloudForma-"
"tion change set and then exits without executing the change set. After"
"you view the change set, execute it to implement your changes.",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Execute it how? We should make that clear somewhere, probably here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will clarify this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

"""
try:
resp = self._client.describe_stacks(StackName=stack_name)
if len(resp["Stacks"]) != 1:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd actually check that this is equal to zero.

I believe (could be wrong) that certain situations and inputs can lead this number to be greater than one. At the very least, the API documentation lists this as a possibility.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm looking at this as a defensive programming POV - I don't think the logic below needs to change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed.

@sriram-mv
Copy link
Contributor Author

@awood45 addressed your comments.

@jfuss jfuss added area/deploy sam deploy command type/feature Feature request labels Nov 12, 2019
Copy link
Member

@awood45 awood45 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One comment to verify before merging.

@@ -69,7 +69,7 @@ def has_stack(self, stack_name):
"""
try:
resp = self._client.describe_stacks(StackName=stack_name)
if len(resp["Stacks"]) != 1:
if not resp["Stacks"]:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this handle an empty array?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, better question, can we ensure that we test the case of no such stack? Just to be sure for regressions.

self.assertEqual(self.deployer._client, self.cloudformation_client)
self.assertEqual(self.deployer.changeset_prefix, "samcli-cloudformation-package-deploy-")

def test_deployer_has_no_stack(self):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Example of such a test, @awood45

Copy link
Contributor

@sanathkr sanathkr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most comments are minor, something to think about. Just make sure the table formatting doesn't lead to zeros or infinities or crashes. We don't want deploy to crash because of the table print.

samcli/lib/deploy/deployer.py Outdated Show resolved Hide resolved
samcli/lib/deploy/deployer.py Outdated Show resolved Hide resolved
try:
outputs = stacks_description["Stacks"][0]["Outputs"]
if echo:
click.secho("\nStack {stack_name} outputs:\n".format(stack_name=stack_name))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you not use click in this layer? It adds a dependency on click for this module to function. It makes the code less portable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

samcli/lib/deploy/deployer.py Outdated Show resolved Hide resolved
samcli/lib/deploy/deployer.py Outdated Show resolved Hide resolved
usable_width_no_margin = int(width) - 1
usable_width = int((usable_width_no_margin - (margin if margin else min_margin)))

width_per_column = int(usable_width / total_args)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Can this be zero?
  • Can this be infinity?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added ValueError if so.

samcli/commands/_utils/table_print.py Show resolved Hide resolved
samcli/commands/_utils/table_print.py Show resolved Hide resolved
samcli/lib/deploy/deployer.py Outdated Show resolved Hide resolved
samcli/lib/deploy/deployer.py Show resolved Hide resolved
- add retries
- more regression testing
- remove types for capabilities
Copy link
Contributor

@sanathkr sanathkr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for making the changes. This looks good to me.


def _check_stack_complete(self, status):
return "COMPLETE" in status and "CLEANUP" not in status

def wait_for_execute(self, stack_name, changeset_type):

click.secho("\nWaiting for stack create/update to complete\n")
sys.stdout.write("\nWaiting for stack create/update to complete\n")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure these are written to stdout in AWS CLI?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 add flushes

- show cases Add, Modify, Delete with +, * and -
@sriram-mv sriram-mv changed the base branch from develop to release-v0.32.0 November 13, 2019 18:56
@sriram-mv sriram-mv merged commit d51d6f7 into aws:release-v0.32.0 Nov 13, 2019
sriram-mv added a commit that referenced this pull request Nov 20, 2019
* feat: sam deploy without aws cli pre-installed

- Not breaking parameter overrides formats
- still requires refactoring and error handling

* feat: new click types for deploy parameters

* feat: show changeset and stack events

- needs refactoring

* refactor: move deploy classes to lib

- wire up command.py for `sam deploy`
- move deploy specific exceptions to inherit from UserException

* rebase: latest from `sam package` port

* feat: decorator for printing tables

- `sam deploy` now has tables while showcasing the changeset and
  showcasing events happening during deploy.

* fix: wrap text on resource status column on `sam deploy`

- fixed unit tests
- linting fixes
- doc strings
- further unit tests and integration tests need to be added.

* fix: cleaner text formatting for tables

* tests: add unit tests for full suite of `sam deploy`

* tests: add integration tests for `sam deploy`

* tests: regression test suite for `sam deploy`

- exercise all command line parameters for `aws` and `sam`

* fix: deploy command now showcases stack outputs

* fix: address comments

* fix: return stack outputs from `get_stack_outputs`

* fix: width margins on table prints

* fix: address comments

- add retries
- more regression testing
- remove types for capabilities

* tests: tests for pprint of tables

* usability: add table headers

- show cases Add, Modify, Delete with +, * and -
sriram-mv added a commit that referenced this pull request Nov 23, 2019
* feat: sam deploy without aws cli pre-installed

- Not breaking parameter overrides formats
- still requires refactoring and error handling

* feat: new click types for deploy parameters

* feat: show changeset and stack events

- needs refactoring

* refactor: move deploy classes to lib

- wire up command.py for `sam deploy`
- move deploy specific exceptions to inherit from UserException

* rebase: latest from `sam package` port

* feat: decorator for printing tables

- `sam deploy` now has tables while showcasing the changeset and
  showcasing events happening during deploy.

* fix: wrap text on resource status column on `sam deploy`

- fixed unit tests
- linting fixes
- doc strings
- further unit tests and integration tests need to be added.

* fix: cleaner text formatting for tables

* tests: add unit tests for full suite of `sam deploy`

* tests: add integration tests for `sam deploy`

* tests: regression test suite for `sam deploy`

- exercise all command line parameters for `aws` and `sam`

* fix: deploy command now showcases stack outputs

* fix: address comments

* fix: return stack outputs from `get_stack_outputs`

* fix: width margins on table prints

* fix: address comments

- add retries
- more regression testing
- remove types for capabilities

* tests: tests for pprint of tables

* usability: add table headers

- show cases Add, Modify, Delete with +, * and -
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/deploy sam deploy command type/feature Feature request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants