Skip to content

fix: validate runtime - #22

Merged
sanathkr merged 4 commits into
aws:developfrom
sriram-mv:validate_runtime
Nov 19, 2018
Merged

fix: validate runtime#22
sanathkr merged 4 commits into
aws:developfrom
sriram-mv:validate_runtime

Conversation

@sriram-mv

@sriram-mv sriram-mv commented Nov 15, 2018

Copy link
Copy Markdown
Contributor
  • Based on the language supplied and lambda runtimes, validate the
    host runtime to make sure they are compatible.

Addresses: #11

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

- Based on the language supplied and lambda runtimes, validate the
  host runtime to make sure they are compatible.
Comment thread aws_lambda_builders/runtime.py Outdated
from enum import Enum

from aws_lambda_builders.exceptions import MisMatchRuntimeError
from aws_lambda_builders.workflows.python_pip.runtime_validator import validate_python_cmd

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

no, you can't do this :( Think of anything inside the workflow folder as a whole separate library that you don't have access to. You can only use the interfaces but not individual implementation.

This allows us to evolve the workflows indendepent of the wrapper library

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sounds good, I could move it. My motivation behind this was to have language specific validation logic, live inside that specific language's module.

- move validation out of language specific modules
@sriram-mv sriram-mv changed the title fix: validate runtime [WIP] fix: validate runtime Nov 16, 2018
Comment thread tests/functional/test_cli.py Outdated
"artifacts_dir": self.artifacts_dir,
"scratch_dir": "/ignored",
"manifest_path": "/ignored",
"runtime": None,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I had to explicitly set this to None, matching it to my python runtime didnt work, and I'm not sure why. Integ tests still work.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should set runtime to something like ignored so the validator fails open.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

👍

@sriram-mv sriram-mv changed the title [WIP] fix: validate runtime fix: validate runtime Nov 16, 2018

@sanathkr sanathkr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Couple of comments about failing open

Comment thread aws_lambda_builders/runtime.py Outdated
:raises ValueError: Unsupported Lambda Runtime
:raises MisMatchRuntimeError: Version mismatch of the lanugage vs the required runtime
"""
try:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

you could just do a if key in dict instead of try/catch. That's more pythonic

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

the reason I didnt want that, was the all if elsing inside that function. maybe a decorator would help? I removed the try catch now.

Comment thread aws_lambda_builders/runtime.py Outdated
except KeyError:
# The language is not currently supported, so there is no runtime validation.
return
if not Runtime.has_value(required_runtime):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would just fail open here. I know this is useful to have, but our runtime checks are never going to be perfect given the long list of languages & dependency managers we have. So I'd rather just fail and log a warning instead.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done. warning logged.

self.builder = LambdaBuilder(language="python",
dependency_manager="pip",
application_framework=None)
self.runtime = "{language}{major}.{minor}".format(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nice!! this makes the test work across multiple runtimes :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes! :)

Comment thread aws_lambda_builders/runtime.py Outdated
}


class Runtime(Enum):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

wait, this needs to work in Py2.7. Enum isn't available there and I am not interested in taking a new dependency on Enum because it doesn't offer a whole lot of functionality in this case ;)

Can you refactor this to remove Enum?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sure removed the enum, its a simple class now.

Comment thread aws_lambda_builders/runtime.py Outdated
@@ -0,0 +1,66 @@
"""

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we also call this validate.py instead of runtime? It is more representative of what this file does.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

- add warning logging messages on runtime and language validation.

@sanathkr sanathkr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for making the changes! Looks good

@sanathkr
sanathkr merged commit d1be163 into aws:develop Nov 19, 2018
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.

2 participants