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(cli): add Cloud Assembly backwards compat tests #4625

Merged
merged 4 commits into from
Oct 25, 2019

Conversation

rix0rrr
Copy link
Contributor

@rix0rrr rix0rrr commented Oct 22, 2019

Make sure that the CLI will continue to be able to load old cloud
assemblies. We do this by using the CLI feature that it can directly
load Cloud Assemblies through its --app argument, hard copying
a couple of cloud assemblies into the test set and trying to synth
those.

In addition to adding a test for loading v0.36.0 assemblies, also
add tests for 2 common context provider requests (AZs and VPC),
to make sure new CLIs will continue to be able to handle these
context lookup requests.

Fixes #4475, pre-emptively adds a regression test for #4544.


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

Make sure that the CLI will continue to be able to load old cloud
assemblies. We do this by using the CLI feature that it can directly
load Cloud Assemblies through its `--app` argument, hard copying
a couple of cloud assemblies into the test set and trying to synth
those.

In addition to adding a test for loading v0.36.0 assemblies, also
add tests for 2 common context provider requests (AZs and VPC),
to make sure new CLIs will continue to be able to handle these
context lookup requests.

Fixes #4475, pre-emptively adds a regression test for #4544.
@mergify
Copy link
Contributor

mergify bot commented Oct 22, 2019

Thanks so much for taking the time to contribute to the AWS CDK ❤️

We will shortly assign someone to review this pull request and help get it
merged. In the meantime, please take a minute to make sure you follow this
checklist
:

  • PR title type(scope): text
    • type: fix, feat, refactor go into CHANGELOG, chore is hidden
    • scope: name of module without aws- or cdk- prefix or postfix (e.g. s3 instead of aws-s3-deployment)
    • text: use all lower-case, do not end with a period, do not include issue refs
  • PR Description
    • Rationale: describe rationale of change and approach taken
    • Issues: indicate issues fixed via: fixes #xxx or closes #xxx
    • Breaking?: last paragraph: BREAKING CHANGE: <describe what changed + link for details>
  • Testing
    • Unit test added. Prefer to add a new test rather than modify existing tests
    • CLI or init templates change? Re-run/add CLI integration tests
  • Documentation
    • README: update module README to describe new features
    • API docs: public APIs must be documented. Copy from official AWS docs when possible
    • Design: for significant features, follow design process

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@nija-at nija-at added the pr/do-not-merge This PR should not be merged at this time. label Oct 22, 2019
Copy link
Contributor

@nija-at nija-at left a comment

Choose a reason for hiding this comment

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

Am I right in assuming that at least one test case will need to be added here for every cx-api version bump? If so, should we enforce that, i.e. fail if cx-api version is > 1.10?

add tests for 2 common context provider requests (AZs and VPC)

I'm not familiar with these, so someone familiar should take a look as well.

Comment on lines +7 to +8
tmpdir=$(dirname $(mktemp -u))
casmdir=$tmpdir/cdk-integ-cx
Copy link
Contributor

Choose a reason for hiding this comment

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

Could just be casmdir=$(mktemp -d). Everything else should work AFAICT

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But no. I want a predictable dir, for the following reasons:

  • If I do a random dir every time, I have to clean it up after every test.
  • If I have to clean it up after every test, I can't inspect the state of the directory after a failing test.

Instead, I have a directory that's the same every time which gets reset every time.

This is just a complex way of writing casmdir=/tmp/cdk-integ-cx, but in a way that is compatible across systems where the tempdir doesn't necessarily live at /tmp (for example MacOS or Windows).

Comment on lines 15 to 18
echo "ASSEMBLY ${1}"
rm -rf $casmdir
mkdir -p $casmdir
cp -R $1/* $casmdir
Copy link
Contributor

Choose a reason for hiding this comment

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

If you instead do a mktemp each time, instead of clobbering, we would retain (temporarily) all of the artifacts, making it easier to debug when they fail.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure I follow. If a test succeeds, the artifacts can be clobbered, if a test fails they won't be?

Comment on lines +23 to +25
for template in $casmdir/*.js; do
node $template > ${template%.js}
done
Copy link
Contributor

Choose a reason for hiding this comment

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

Avoid loops in bash where possible; they are not very efficient but more importantly unnatural to shell scripting.

Instead use pipes. Something like, ls -1 $casmdir/*.js | xargs -I{} node {} ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Please don't make me do that.

This is readable, writable and clear. All that find and xargs magic makes it horrible and unreadable. I dare you to write the same command with xargs, including the shell redirect to individual files. Show me what it looks like and we'll compare quality.

Copy link
Contributor

Choose a reason for hiding this comment

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

For the records, for loops have been natural to my shell scripting since longer than I can remember...

# tempdir. Evaluate .js files found their (interpret them
# as templates).
function prepare_cloud_assembly() {
echo "ASSEMBLY ${1}"
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor: Ideally assign $1 at the top to a local var with an appropriate name and then use them

local sourcedir=$1

Better readability when there are no named parameters.

# Echo the TEST_ACCOUNT, TEST_REGION vars to make bash abort if they're not set.
echo "Running backwards compatibility test (account ${TEST_ACCOUNT}, region ${TEST_REGION})"

for assembly in ${scriptdir}/cloud-assemblies/*; do
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment as the for loop, but I understand you might want to keep this one for readability.

If it were up to me, I would group what is in the loop into a function and then use pipes and xargs. I'll leave it to you to decide.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think this code can be conveniently rewritten to use xargs.

@@ -0,0 +1 @@
{"version":"0.36.0"}
Copy link
Contributor

Choose a reason for hiding this comment

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

A bit confused - Isn't cdk.out a directory that contains the manifest and template?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes it is. I think this file exists for backwards compatibility with some old version. Elad will know.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that is correct.

Copy link
Contributor

Choose a reason for hiding this comment

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

Indeed. It is there since old CLIs would look for this file name in the output directory. The version field here will tell them that they can't do anything besides yelling. I assume we can probably get rid of it by now...

Comment on lines 33 to 34
cat $stderrfile >&2
echo "There was an error executing the context provider!" >&2
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think the messaging include which test case failed; and we should include it.

Also, it's good practice to put a sample of the output when tests fail into the PR description; just to validate that the messaging looks good.

@SomayaB SomayaB added in-progress This issue is being actively worked on. contribution/core This is a PR that came from AWS. and removed in-progress This issue is being actively worked on. labels Oct 22, 2019
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

Copy link
Contributor

@eladb eladb left a comment

Choose a reason for hiding this comment

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

I really like this approach! How can we make sure that whenever we do a bump of the protocol version we add another "old" cloud assembly to the list?

@@ -0,0 +1 @@
{"version":"0.36.0"}
Copy link
Contributor

Choose a reason for hiding this comment

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

Indeed. It is there since old CLIs would look for this file name in the output directory. The version field here will tell them that they can't do anything besides yelling. I assume we can probably get rid of it by now...

@@ -0,0 +1 @@
{"version":"0.36.0"}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that is correct.

@rix0rrr rix0rrr requested a review from nija-at October 25, 2019 08:49
@rix0rrr rix0rrr removed the pr/do-not-merge This PR should not be merged at this time. label Oct 25, 2019
@mergify
Copy link
Contributor

mergify bot commented Oct 25, 2019

Thank you for contributing! Your pull request is now being automatically merged.

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify mergify bot merged commit 5d2e5e3 into master Oct 25, 2019
@mergify mergify bot deleted the huijbers/cli-cx-backwards-compat branch October 25, 2019 13:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution/core This is a PR that came from AWS.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CLI should have backwards compatibility test on CX protocol version
6 participants