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

chore: run cfn lint on test output #888

Merged
merged 8 commits into from
Apr 13, 2019

Conversation

keetonian
Copy link
Contributor

Description of changes:
Runs CFN lint on the output files of the tests to make sure that they are valid CFN syntax.

Also fixes a parameter in Serverless::Application from NotificationArns->NotificationARNs. This was previously broken and was a bug.

Description of how you validated changes:
Tests run and pass.

Checklist:

  • Write/update tests
  • make pr passes
  • Update documentation

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

@keetonian keetonian changed the title Cfn lint test output chore: run cfn lint on test output Apr 12, 2019
@@ -9,7 +9,7 @@ class NestedStack(Resource):
property_types = {
'TemplateURL': PropertyType(True, is_str()),
'Parameters': PropertyType(False, is_type(dict)),
'NotificationArns': PropertyType(False, list_of(is_str())),
'NotificationARNs': PropertyType(False, list_of(is_str())),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was a bug- the CFN model had an incorrect property name.

# Only run linter on normal/gov partitions. It errors on china regions
if testcase not in LINT_IGNORE_TESTS and partition != 'aws-cn':
matches = runner.run()
print('cfn-lint ({}): {}'.format(expected_filepath, matches))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This section is really what was added, all the rest is updating output files to conform to lint rules.

@keetonian
Copy link
Contributor Author

Reviewers: look at the test_translator.py file under the tests directory and anything else not under the tests directory. All other things in the tests directory are changes forced by the changes to test_translator.py.

@keetonian keetonian closed this Apr 12, 2019
@keetonian keetonian reopened this Apr 12, 2019
@codecov-io
Copy link

Codecov Report

Merging #888 into develop will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@           Coverage Diff            @@
##           develop     #888   +/-   ##
========================================
  Coverage    94.62%   94.62%           
========================================
  Files           69       69           
  Lines         2997     2997           
  Branches       554      554           
========================================
  Hits          2836     2836           
  Misses          85       85           
  Partials        76       76
Impacted Files Coverage Δ
samtranslator/model/cloudformation.py 85.71% <ø> (ø) ⬆️
samtranslator/model/sam_resources.py 95.5% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 92decec...e674b56. Read the comment docs.

else: # deprecation warning catching in py2
import warnings
with warnings.catch_warnings():
warnings.filterwarnings("ignore",category=DeprecationWarning)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

CFN lint throws a DeprecationWarning in python2 here for every cfn node object created (possibly dozens per template), and Travis truncates the test output due to the sheer volume of warnings generated. This is to make travis (and the tox command) play nice with these tests and catch the warning.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Travis errors on the output even though the tests pass.

Copy link
Contributor Author

@keetonian keetonian Apr 12, 2019

Choose a reason for hiding this comment

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

See https://travis-ci.org/awslabs/serverless-application-model/jobs/519380376

"The job exceeded the maximum log length, and has been terminated."

Copy link
Contributor

Choose a reason for hiding this comment

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

How do we work around this?

if output_value.get("Ref") in deployment_logical_id_dict:
output_value["Ref"] = deployment_logical_id_dict[output_value.get("Ref")]
if output_value.get("Value").get("Ref") in deployment_logical_id_dict:
output_value["Value"]["Ref"] = deployment_logical_id_dict[output_value.get("Value").get("Ref")]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The code was (incorrectly) trying to parse outputs in the following manner:

Outputs:
  MyOutput: !Ref Deployment34567

I updated it (and the tests) to be correct:

Outputs:
  MyOutput:
    Value: !Ref Deployment34567

Copy link
Contributor

@honglu honglu left a comment

Choose a reason for hiding this comment

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

Glad this catch a lot of incorrect templates we had!

# Only update the deployment Logical Id hash in Py3.
if sys.version_info.major >= 3:
self._update_logical_id_hash(expected)
self._update_logical_id_hash(output_fragment)
output_template = cfnlint.decode.cfn_json.load(expected_filepath)
else: # deprecation warning catching in py2
import warnings
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it good python style to use import in the middle of the code? Usually those things are at the top of the file I think

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Usually they are, but I feel it's fine in this case because we are only using it in py2.

@keetonian keetonian merged commit d47bb52 into aws:develop Apr 13, 2019
@@ -32,6 +32,12 @@ Resources:
Identity:
Headers:
- Authorization1
MyAuthFn:
Copy link
Contributor

Choose a reason for hiding this comment

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

Where did these new Resources come from?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The new resources are the resources that are referenced in the template but weren't actually in the template. CFN lint does some resource reference resolution to find broken or missing resource references and dependencies. I added in what was necessary to make all of these templates valid.

@keetonian keetonian deleted the cfn-lint-test-output branch June 13, 2019 17:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants