-
Notifications
You must be signed in to change notification settings - Fork 66
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
disable pip red error messages; add pip warning #350
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
aa27fef
disable pip red error messages; add pip warning
troyready f0b4211
omit too-many-lines check from aws_lambda hook
troyready dd51f30
add integration test for red pip error message
troyready e37b91c
Update CHANGELOG.md
troyready 4de2968
Update CHANGELOG.md
troyready File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
142 changes: 81 additions & 61 deletions
142
integration_tests/test_cfngin/tests/16_aws_lambda_hook.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,81 @@ | ||
"""Test AWS Lambda hook.""" | ||
# flake8: noqa | ||
# pylint: disable=invalid-name | ||
from os import path | ||
from os.path import basename | ||
|
||
import boto3 | ||
from send2trash import send2trash | ||
|
||
from integration_tests.test_cfngin.test_cfngin import Cfngin | ||
|
||
FILE_BASENAME = '.'.join(basename(__file__).split('.')[:-1]) | ||
|
||
|
||
class TestAwsLambda(Cfngin): | ||
"""Test AWS Lambda Hook from cfngin. | ||
|
||
Requires valid AWS Credentials. | ||
|
||
""" | ||
|
||
REQUIRED_FIXTURE_FILES = [FILE_BASENAME + '.yaml'] | ||
TEST_NAME = __name__ | ||
|
||
def invoke_lambda(self, client, func_name): | ||
"""Verify lambda function deployed successfully.""" | ||
self.logger.info('Invoking lambda function: %s', func_name) | ||
resp = client.invoke( | ||
FunctionName=func_name, | ||
InvocationType='RequestResponse' | ||
) | ||
|
||
return resp['StatusCode'] | ||
|
||
def _build(self): | ||
"""Execute and assert initial build.""" | ||
self.set_environment('dev') | ||
code, _stdout, _stderr = self.runway_cmd('deploy') | ||
assert code == 0, 'exit code should be zero' | ||
|
||
def run(self): | ||
"""Run test.""" | ||
self.copy_fixtures() | ||
self._build() | ||
|
||
client = boto3.client('lambda', region_name=self.region) | ||
|
||
functions = ['dockerizepip-integrationtest', | ||
'nondockerizepip-integrationtest'] | ||
for func_name in functions: | ||
assert self.invoke_lambda(client, func_name) == 200, \ | ||
f'{self.TEST_NAME}: Execution of lambda {func_name} failed' | ||
|
||
def teardown(self): | ||
"""Teardown test.""" | ||
self.runway_cmd('destroy') | ||
venv_dir = path.join(self.fixture_dir, | ||
'lambda_src/dockerize_src/.venv') | ||
if path.isdir(venv_dir): | ||
send2trash(venv_dir) | ||
self.cleanup_fixtures() | ||
"""Test AWS Lambda hook.""" | ||
# flake8: noqa | ||
# pylint: disable=invalid-name | ||
import os | ||
import pty | ||
import tempfile | ||
|
||
import boto3 | ||
from send2trash import send2trash | ||
|
||
from integration_tests.test_cfngin.test_cfngin import Cfngin | ||
from runway.util import environ | ||
|
||
FILE_BASENAME = '.'.join(os.path.basename(__file__).split('.')[:-1]) | ||
|
||
|
||
class TestAwsLambda(Cfngin): | ||
"""Test AWS Lambda Hook from cfngin. | ||
|
||
Requires valid AWS Credentials. | ||
|
||
""" | ||
|
||
REQUIRED_FIXTURE_FILES = [FILE_BASENAME + '.yaml'] | ||
TEST_NAME = __name__ | ||
|
||
def invoke_lambda(self, client, func_name): | ||
"""Verify lambda function deployed successfully.""" | ||
self.logger.info('Invoking lambda function: %s', func_name) | ||
resp = client.invoke( | ||
FunctionName=func_name, | ||
InvocationType='RequestResponse' | ||
) | ||
|
||
return resp['StatusCode'] | ||
|
||
def _build(self): | ||
"""Execute and assert initial build. | ||
|
||
Explicitly spawning with a tty here to ensure output | ||
(e.g. from pip) includes color | ||
|
||
""" | ||
with environ({**os.environ, **{'DEPLOY_ENVIRONMENT': 'dev'}}): | ||
with tempfile.TemporaryFile() as pty_output: | ||
def read_pty(fds): | ||
"""Append tty output to file descriptor.""" | ||
data = os.read(fds, 1024) | ||
pty_output.write(data) | ||
return data | ||
|
||
spawn_result = pty.spawn(['runway', 'deploy'], read_pty) | ||
assert spawn_result == 0, 'exit code should be zero' | ||
pty_output.seek(0) | ||
combined_output = pty_output.read().decode() | ||
assert '\x1b[31mERROR: ' not in combined_output, ( | ||
'no red ERROR should be present' | ||
) | ||
|
||
def run(self): | ||
"""Run test.""" | ||
self.copy_fixtures() | ||
self._build() | ||
|
||
client = boto3.client('lambda', region_name=self.region) | ||
|
||
functions = ['dockerizepip-integrationtest', | ||
'nondockerizepip-integrationtest', | ||
'authatedge-integrationtest'] | ||
for func_name in functions: | ||
assert self.invoke_lambda(client, func_name) == 200, \ | ||
f'{self.TEST_NAME}: Execution of lambda {func_name} failed' | ||
|
||
def teardown(self): | ||
"""Teardown test.""" | ||
self.runway_cmd('destroy') | ||
venv_dir = os.path.join(self.fixture_dir, | ||
'lambda_src/dockerize_src/.venv') | ||
if os.path.isdir(venv_dir): | ||
send2trash(venv_dir) | ||
self.cleanup_fixtures() |
113 changes: 61 additions & 52 deletions
113
integration_tests/test_cfngin/tests/fixtures/16_aws_lambda_hook.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,61 @@ | ||
namespace: ${CFNGIN_NAMESPACE} | ||
cfngin_bucket: ${CFNGIN_NAMESPACE}-${region} | ||
|
||
sys_path: ./ | ||
|
||
pre_build: | ||
upload_lambdas: | ||
path: runway.cfngin.hooks.aws_lambda.upload_lambda_functions | ||
required: true | ||
data_key: lambda | ||
args: | ||
functions: | ||
dockerize: | ||
# this won't actually use docker at the moment. | ||
# it will take additional work to get docker running in codebuild for this. | ||
# but, for the time being we are at least testing the use of pipenv. | ||
# note: leaving it set to `non-linux` will allow local testing to use docker even though codebuild testing does not. | ||
dockerize_pip: non-linux | ||
use_pipenv: true | ||
runtime: python3.7 | ||
path: ./fixtures/lambda_src/dockerize_src | ||
include: | ||
- '*.py' | ||
exclude: | ||
- '*.pyc' | ||
nondockerize: | ||
path: ./fixtures/lambda_src/nondockerize_src | ||
include: | ||
- '*.py' | ||
exclude: | ||
- '*.pyc' | ||
|
||
stacks: | ||
test-dockerize: | ||
class_path: fixtures.lambda_function.BlueprintClass | ||
variables: | ||
Code: ${hook_data lambda::dockerize} | ||
Entrypoint: dockerize.handler | ||
AppName: dockerizepip | ||
test-nondockerize: | ||
class_path: fixtures.lambda_function.BlueprintClass | ||
variables: | ||
Code: ${hook_data lambda::nondockerize} | ||
Entrypoint: nondockerize.handler | ||
AppName: nondockerizepip | ||
|
||
post_destroy: | ||
purge_bucket: | ||
path: runway.hooks.cleanup_s3.purge_bucket | ||
required: True | ||
args: | ||
bucket_name: ${CFNGIN_NAMESPACE}-${region} | ||
namespace: ${CFNGIN_NAMESPACE} | ||
cfngin_bucket: ${CFNGIN_NAMESPACE}-${region} | ||
|
||
sys_path: ./ | ||
|
||
pre_build: | ||
upload_lambdas: | ||
path: runway.cfngin.hooks.aws_lambda.upload_lambda_functions | ||
required: true | ||
data_key: lambda | ||
args: | ||
functions: | ||
dockerize: | ||
# this won't actually use docker at the moment. | ||
# it will take additional work to get docker running in codebuild for this. | ||
# but, for the time being we are at least testing the use of pipenv. | ||
# note: leaving it set to `non-linux` will allow local testing to use docker even though codebuild testing does not. | ||
dockerize_pip: non-linux | ||
use_pipenv: true | ||
runtime: python3.7 | ||
path: ./fixtures/lambda_src/dockerize_src | ||
include: | ||
- '*.py' | ||
exclude: | ||
- '*.pyc' | ||
nondockerize: | ||
path: ./fixtures/lambda_src/nondockerize_src | ||
include: | ||
- '*.py' | ||
exclude: | ||
- '*.pyc' | ||
authatedge: | ||
path: ./fixtures/lambda_src/authatedge_src | ||
exclude: | ||
- '*.pyc' | ||
|
||
stacks: | ||
test-dockerize: | ||
class_path: fixtures.lambda_function.BlueprintClass | ||
variables: | ||
Code: ${hook_data lambda::dockerize} | ||
Entrypoint: dockerize.handler | ||
AppName: dockerizepip | ||
test-nondockerize: | ||
class_path: fixtures.lambda_function.BlueprintClass | ||
variables: | ||
Code: ${hook_data lambda::nondockerize} | ||
Entrypoint: nondockerize.handler | ||
AppName: nondockerizepip | ||
test-authatedge: | ||
class_path: fixtures.lambda_function.BlueprintClass | ||
variables: | ||
Code: ${hook_data lambda::authatedge} | ||
AppName: authatedge | ||
|
||
post_destroy: | ||
purge_bucket: | ||
path: runway.hooks.cleanup_s3.purge_bucket | ||
required: True | ||
args: | ||
bucket_name: ${CFNGIN_NAMESPACE}-${region} |
19 changes: 19 additions & 0 deletions
19
integration_tests/test_cfngin/tests/fixtures/lambda_src/authatedge_src/index.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
"""Test handler.""" | ||
import rsa | ||
|
||
|
||
def handler(event, context): | ||
"""Handle lambda.""" | ||
try: | ||
prime = rsa.prime.getprime(4) | ||
if isinstance(prime, int): | ||
return { | ||
'statusCode': 200, | ||
'body': str(prime) | ||
} | ||
raise ValueError | ||
except: | ||
return { | ||
'statusCode': 500, | ||
'body': 'fail' | ||
} |
7 changes: 7 additions & 0 deletions
7
integration_tests/test_cfngin/tests/fixtures/lambda_src/authatedge_src/requirements.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
-i https://pypi.org/simple | ||
ecdsa==0.15 | ||
pyasn1==0.4.8 | ||
pyjwt==1.7.1 | ||
python-jose==3.1.0 | ||
rsa==4.0 | ||
six==1.14.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file is not nearly as changed as the git diff is implying here. The main change is the
_build
method.