@@ -7,8 +7,10 @@ run_tests:
77 stage : test
88 resource_group : ssh-helper-tests
99 script :
10- - export AWS_REGION=eu-west-1
11- - export AWS_DEFAULT_REGION=eu-west-1
10+ - cat /etc/hosts
11+ # Creating venv
12+ - python -m venv ./venv
13+ - source ./venv/bin/activate
1214 # Install the package
1315 - pip freeze --all | tee pip_freeze_before.txt
1416 - pip install '.'
@@ -22,14 +24,22 @@ run_tests:
2224 # Scanning sources
2325 - bandit -r ./sagemaker_ssh_helper/ ./tests/ *.py --skip B603,B404,B101 2>&1 | tee bandit.txt
2426 - flake8 --extend-ignore E501,F401,F541,E402 ./sagemaker_ssh_helper/ ./tests/ *.py | tee flake8.txt
27+ # Configure local env
28+ - id
29+ - apt-get update
30+ - apt-get install -y sudo
31+ - sm-local-configure
32+ - source tests/generate_sagemaker_config.sh
2533 # Update IAM/SSM policies
2634 - curl -fsSL https://deb.nodesource.com/setup_lts.x | bash -
35+ - export DEBIAN_FRONTEND=noninteractive
2736 - apt-get install -y nodejs
2837 - npm install -g aws-cdk
2938 - cdk --version
30- - REGION=$AWS_REGION
39+ - REGION=eu-west-1
3140 - USER_ROLE=$GITLAB_ROLE_ARN
3241 - APP="python -m sagemaker_ssh_helper.cdk.app"
42+ # Bootstrapping requires Administrator privileges:
3343 # cdk bootstrap aws://"$ACCOUNT_ID"/"$REGION" --require-approval never
3444 - AWS_REGION=$REGION cdk -a "$APP" deploy SSH-IAM-SSM-Stack-Tests
3545 --require-approval never -c sagemaker_role=$SAGEMAKER_ROLE -c user_role=$USER_ROLE
@@ -41,30 +51,38 @@ run_tests:
4151 # cdk bootstrap aws://"$ACCOUNT_ID"/"$REGION" --require-approval never
4252 - AWS_REGION=$REGION cdk -a "$APP" deploy SSM-Advanced-Tier-Stack
4353 --require-approval never -c sagemaker_role=$SAGEMAKER_ROLE -c user_role=$USER_ROLE
44- # Configure local env
45- - sm-local-configure
46- - source tests/generate_sagemaker_config.sh
54+ - unset REGION
55+ - unset USER_ROLE
56+ - unset APP
57+ # Set bucket versioning to detect model repacking / dependencies overrides
58+ - aws s3api put-bucket-versioning
59+ --bucket $(AWS_DEFAULT_REGION=eu-west-1 bash tests/get_sagemaker_bucket.sh)
60+ --versioning-configuration Status=Enabled
61+ - aws s3api put-bucket-versioning
62+ --bucket $(AWS_DEFAULT_REGION=eu-west-2 bash tests/get_sagemaker_bucket.sh)
63+ --versioning-configuration Status=Enabled
64+ # Set default region for tests - need both to avoid confusion because one can override another
65+ - export AWS_REGION=eu-west-1
66+ - export AWS_DEFAULT_REGION=eu-west-1
67+ - aws configure list
4768 # Assume CI/CD role
48- - sts=( $(
49- aws sts assume-role
50- --role-arn "$GITLAB_ROLE_ARN"
51- --role-session-name "gitlab-ci"
52- --duration-seconds 18000
53- --query 'Credentials.[AccessKeyId,SecretAccessKey,SessionToken]'
54- --output text
55- ) )
69+ - sts=( $(source tests/assume-sagemaker-role.sh) )
5670 - export AWS_ACCESS_KEY_ID=${sts[0]}
5771 - export AWS_SECRET_ACCESS_KEY=${sts[1]}
5872 - export AWS_SESSION_TOKEN=${sts[2]}
59- # Build BYOC docker image for tests
60- - sm-docker build . --file tests/byoc/Dockerfile --repo byoc-ssh:latest
6173 # Run tests
6274 - echo "Extra args for pytest - $PYTEST_EXTRA_ARGS"
6375 - cd tests
64- - coverage run -m pytest --html=pytest_report.html --self-contained-html --junitxml=pytest_report.xml -m 'not manual' -o sagemaker_role=$SAGEMAKER_ROLE -o kernel_gateway_name=$KERNEL_GATEWAY_NAME $PYTEST_EXTRA_ARGS
76+ - coverage run -m pytest
77+ --html=pytest_report.html --self-contained-html --junitxml=pytest_report.xml
78+ -m 'not manual'
79+ -o sagemaker_studio_domain=$SAGEMAKER_STUDIO_DOMAIN
80+ $PYTEST_EXTRA_ARGS || EXIT_CODE=$?
6581 - coverage report
6682 - coverage xml
83+ - coverage html --show-contexts
6784 - cd -
85+ - exit $EXIT_CODE
6886 coverage : ' /(?i)total.*? (100(?:\.0+)?\%|[1-9]?\d(?:\.\d+)?\%)$/'
6987 artifacts :
7088 when : always
@@ -81,6 +99,40 @@ run_tests:
8199 - pip_freeze_diff_test.txt
82100 - tests/pytest_report.xml
83101 - tests/pytest_report.html
102+ - tests/htmlcov/
84103 - tests/coverage.xml
104+ - tests/.coverage
85105 - bandit.txt
86- - flake8.txt
106+ - flake8.txt
107+
108+ profile_tests :
109+ stage : test
110+ resource_group : ssh-helper-tests
111+ script :
112+ - python -m venv ./venv
113+ - source ./venv/bin/activate
114+ - pip install '.[test]'
115+ - id
116+ - apt-get update
117+ - apt-get install -y sudo
118+ - sm-local-configure
119+ - source tests/generate_sagemaker_config.sh
120+ - export DEBIAN_FRONTEND=noninteractive
121+ - apt-get install -y graphviz
122+ - export AWS_REGION=eu-west-1
123+ - export AWS_DEFAULT_REGION=eu-west-1
124+ - sts=( $(source tests/assume-sagemaker-role.sh) )
125+ - export AWS_ACCESS_KEY_ID=${sts[0]}
126+ - export AWS_SECRET_ACCESS_KEY=${sts[1]}
127+ - export AWS_SESSION_TOKEN=${sts[2]}
128+ - cd tests
129+ - pytest
130+ -m 'not manual'
131+ -o sagemaker_studio_domain=$SAGEMAKER_STUDIO_DOMAIN
132+ --profile --profile-svg
133+ $PYTEST_EXTRA_ARGS
134+ - cd -
135+ artifacts :
136+ when : always
137+ paths :
138+ - tests/prof/
0 commit comments