-
Notifications
You must be signed in to change notification settings - Fork 478
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
SNOW-862917: Trigger lambda tests on GHA #1647
Merged
sfc-gh-aalam
merged 13 commits into
main
from
aalam-SNOW-862917-create-shell-scripts-to-run-lambda-tests-on-docker
Jul 19, 2023
Merged
Changes from 11 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
a7e5c91
initial commit
sfc-gh-aalam fe8647c
fix file permission
sfc-gh-aalam 331dcfb
run lambda is docker and call it using curl
sfc-gh-aalam cb270fd
finishing touches
sfc-gh-aalam 81172d2
add test result to job
sfc-gh-aalam 0e903c3
Merge branch 'main' into aalam-SNOW-862917-create-shell-scripts-to-ru…
sfc-gh-aalam 33bcdf8
remove unsupported version
sfc-gh-aalam 50643c6
add support for multiple python runtimes
sfc-gh-aalam cb7b1b8
fix minor bug
sfc-gh-aalam cc2a274
fix python version in app.py
sfc-gh-aalam b16a3c5
fix python version in app.py 2
sfc-gh-aalam 222119a
add python 3.11 tests
sfc-gh-aalam 44ece5c
use PYTHONPATH to fix import issues with CMD
sfc-gh-aalam 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
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
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,11 @@ | ||
FROM public.ecr.aws/lambda/python:3.10-x86_64 | ||
|
||
RUN yum install -y git | ||
|
||
WORKDIR /home/user/snowflake-connector-python | ||
RUN chmod 777 /home/user/snowflake-connector-python | ||
ENV PATH="${PATH}:/opt/python/cp310-cp310/bin/" | ||
|
||
RUN pip3 install -U pip setuptools wheel tox tox-external_wheels | ||
|
||
CMD [ "/home/user/snowflake-connector-python/ci/docker/connector_test_lambda/app.handler" ] |
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,11 @@ | ||
FROM public.ecr.aws/lambda/python:3.8-x86_64 | ||
|
||
RUN yum install -y git | ||
|
||
WORKDIR /home/user/snowflake-connector-python | ||
RUN chmod 777 /home/user/snowflake-connector-python | ||
ENV PATH="${PATH}:/opt/python/cp38-cp38/bin/" | ||
|
||
RUN pip3 install -U pip setuptools wheel tox tox-external_wheels | ||
|
||
CMD [ "/home/user/snowflake-connector-python/ci/docker/connector_test_lambda/app.handler" ] |
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,11 @@ | ||
FROM public.ecr.aws/lambda/python:3.9-x86_64 | ||
|
||
RUN yum install -y git | ||
|
||
WORKDIR /home/user/snowflake-connector-python | ||
RUN chmod 777 /home/user/snowflake-connector-python | ||
ENV PATH="${PATH}:/opt/python/cp39-cp39/bin/" | ||
|
||
RUN pip3 install -U pip setuptools wheel tox tox-external_wheels | ||
|
||
CMD [ "/home/user/snowflake-connector-python/ci/docker/connector_test_lambda/app.handler" ] |
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,81 @@ | ||
import logging | ||
import sys | ||
import xml.etree.ElementTree as ET | ||
from pathlib import Path | ||
from subprocess import PIPE, Popen | ||
|
||
LOGGER = logging.getLogger(__name__) | ||
REPO_PATH = "/home/user/snowflake-connector-python" | ||
PY_SHORT_VER = f"{sys.version_info[0]}{sys.version_info[1]}" | ||
ARCH = "x86" # x86, aarch64 | ||
|
||
|
||
def run_tests(): | ||
"""Run tests using tox""" | ||
LOGGER.info("Running tests..") | ||
test_log, err = Popen( | ||
[ | ||
"python", | ||
"-m", | ||
"tox", | ||
"-e", | ||
f"py{PY_SHORT_VER}{{-lambda}}-ci", | ||
"-c", | ||
f"{REPO_PATH}/tox.ini", | ||
"--workdir", | ||
REPO_PATH, | ||
"--external_wheels", | ||
f"{REPO_PATH}/dist/*.whl", | ||
], | ||
stdout=PIPE, | ||
stderr=PIPE, | ||
).communicate() | ||
LOGGER.info(test_log) | ||
LOGGER.info(err) | ||
return test_log.decode("utf-8") | ||
|
||
|
||
def parse_test_xml_output(): | ||
"""Parse test summary from xml report generated""" | ||
LOGGER.info("Parsing test result output") | ||
test_status = "UNKNOWN" | ||
|
||
default_xml_fp = f"{REPO_PATH}/junit.py{PY_SHORT_VER}-lambda-ci-dev.xml" | ||
files = sorted(Path(REPO_PATH).glob(f"junit.py{PY_SHORT_VER}-lambda-ci-*.xml")) | ||
file_path = files[0].as_posix() if files else default_xml_fp | ||
|
||
try: | ||
root = ET.parse(file_path).getroot() | ||
for child in root: | ||
failure_count = child.attrib.get("failures") | ||
except Exception as ex: | ||
LOGGER.exception(ex) | ||
return test_status | ||
|
||
if int(failure_count) == 0: | ||
test_status = "SUCCESS" | ||
else: | ||
test_status = "FAILURE" | ||
return test_status | ||
|
||
|
||
def handler(events, context): | ||
""" | ||
Lambda handler for testing Python Connector. | ||
""" | ||
test_status = "UNKNOWN" | ||
test_result_log = "N/A" | ||
response = {} | ||
response["statusCode"] = 500 | ||
response["testStatus"] = test_status | ||
|
||
# run tests | ||
test_result_log = run_tests() | ||
|
||
# parse result output | ||
test_status = parse_test_xml_output() | ||
|
||
response["statusCode"] = 200 | ||
response["testStatus"] = test_status | ||
response["testLog"] = test_result_log | ||
return response |
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,56 @@ | ||
#!/bin/bash -x | ||
|
||
THIS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | ||
CONNECTOR_DIR="$( dirname "${THIS_DIR}")" | ||
PYTHON_VERSION="${1:-3.8}" | ||
PYTHON_SHORT_VERSION="$(echo "$PYTHON_VERSION" | tr -d .)" | ||
# In case this is not run locally and not on Jenkins | ||
|
||
if [[ ! -d "$CONNECTOR_DIR/dist/" ]] || [[ $(ls $CONNECTOR_DIR/dist/*cp${PYTHON_SHORT_VERSION}*manylinux2014*.whl) == '' ]]; then | ||
echo "Missing wheel files, going to compile Python connector in Docker..." | ||
$THIS_DIR/build_docker.sh $PYTHON_VERSION | ||
cp $CONNECTOR_DIR/dist/repaired_wheels/*cp${PYTHON_SHORT_VERSION}*manylinux2014*.whl $CONNECTOR_DIR/dist/ | ||
fi | ||
|
||
cd $THIS_DIR/docker/connector_test_lambda | ||
|
||
CONTAINER_NAME="test_lambda_connector${PYTHON_SHORT_VERSION}" | ||
DOCKERFILE="Dockerfile${PYTHON_SHORT_VERSION}" | ||
|
||
echo "[Info] Start building lambda docker image" | ||
docker build -t ${CONTAINER_NAME}:1.0 -f ${DOCKERFILE} . | ||
|
||
user_id=$(id -u $USER) | ||
|
||
docker run --network=host \ | ||
-e LANG=en_US.UTF-8 \ | ||
-e TERM=vt102 \ | ||
-e SF_USE_OPENSSL_ONLY=True \ | ||
-e PIP_DISABLE_PIP_VERSION_CHECK=1 \ | ||
-e LOCAL_USER_ID=$user_id \ | ||
-e CRYPTOGRAPHY_ALLOW_OPENSSL_102=1 \ | ||
-e AWS_ACCESS_KEY_ID \ | ||
-e AWS_SECRET_ACCESS_KEY \ | ||
-e SF_REGRESS_LOGS \ | ||
-e SF_PROJECT_ROOT \ | ||
-e cloud_provider \ | ||
-e PYTEST_ADDOPTS \ | ||
-e GITHUB_ACTIONS \ | ||
--mount type=bind,source="${CONNECTOR_DIR}",target=/home/user/snowflake-connector-python \ | ||
${CONTAINER_NAME}:1.0 & | ||
|
||
# sleep for sometime to make sure docker run is up and running | ||
sleep 5 | ||
|
||
# call the lambda function | ||
lambda_result=$(curl -XPOST "http://localhost:8080/2015-03-31/functions/function/invocations" -d '{}') | ||
echo "Lambda result:$lambda_result" | ||
|
||
# stop all docker processes | ||
docker stop $(docker ps -a -q) | ||
|
||
# reflect status of the test on the job | ||
status=$(echo "$lambda_result" | grep SUCCESS) | ||
if [[ -z "$status" ]]; then | ||
exit 1 | ||
fi |
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.
Do we need 3.11? Similar question on docker files.
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.
aws runtime interface is not yet available for 3.11maybe I'm wrong about this. Last time I checked, it wasn't supported
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.
looks like it was added in the last two months. I'm adding 3.11 support as well