Skip to content

Commit 868e63d

Browse files
authored
ci: improve patching and fix erroneous script paths for samcli-vm (runfinch#341)
This PR adds more patching for assisting with teardown issues in image deletion in SAMcli tests. These were new issues that arose after the previous merge. It also fixes the paths to scripts that were added for improved error handling. Signed-off-by: ayush-panta <[email protected]>
1 parent 147be1b commit 868e63d

12 files changed

+52
-15
lines changed

.github/workflows/samcli-direct.yaml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ name: samcli-direct
22

33
on:
44
pull_request:
5+
branches:
6+
- main
57
types:
68
- closed
79
schedule:
@@ -58,8 +60,13 @@ jobs:
5860
with:
5961
python-version: '3.11'
6062

61-
- name: Checkout finch-daemon repo
62-
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
63+
- name: Checkout finch-daemon
64+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
65+
with:
66+
ref: ${{ github.head_ref }}
67+
fetch-depth: 0
68+
persist-credentials: false
69+
submodules: recursive
6370

6471
- name: Stop pre-existing services
6572
run: |

.github/workflows/samcli-vm.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ jobs:
159159

160160
- name: Patch SAM CLI for Docker image cleanup
161161
run: |
162-
# Apply git patch to handle ImageNotFound exceptions for all Docker tests
163-
su ec2-user -c 'cd /Users/ec2-user/aws-sam-cli && git apply ${{ github.workspace }}/finch-daemon-pr/scripts/samcli-vm/invoke-teardown.patch'
162+
# Apply patch to handle ImageNotFound exceptions for all Docker tests
163+
su ec2-user -c 'cd /Users/ec2-user/aws-sam-cli && patch -p1 tests/integration/local/invoke/test_integrations_cli.py < ${{ github.workspace }}/finch-daemon-pr/scripts/samcli-vm/invoke-teardown.patch'
164164
shell: bash
165165

166166
- name: Run invoke tests

scripts/samcli-direct/run-invoke-tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ test_building_new_rapid_image_removes_old_rapid_images
1919
EOF
2020

2121
# Validate test results
22-
$(dirname "$0")/../validate-test-results.sh invoke_output.txt expected_invoke_failures.txt "Invoke tests"
22+
$GITHUB_WORKSPACE/scripts/validate-test-results.sh invoke_output.txt expected_invoke_failures.txt "Invoke tests"

scripts/samcli-direct/run-package-tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ test_package_with_loadable_image_archive_0_template_image_load_yaml
1616
EOF
1717

1818
# Validate test results
19-
$(dirname "$0")/../validate-test-results.sh package_output.txt expected_package_failures.txt "Package tests"
19+
$GITHUB_WORKSPACE/scripts/validate-test-results.sh package_output.txt expected_package_failures.txt "Package tests"

scripts/samcli-direct/run-start-api-tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ test_can_invoke_lambda_layer_successfully
1313
EOF
1414

1515
# Validate test results
16-
$(dirname "$0")/../validate-test-results.sh start_api_output.txt expected_start_api_failures.txt "Start-API tests"
16+
$GITHUB_WORKSPACE/scripts/validate-test-results.sh start_api_output.txt expected_start_api_failures.txt "Start-API tests"

scripts/samcli-direct/run-start-lambda-tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ python -m pytest tests/integration/local/start_lambda -k 'not Terraform' -v --tb
99
touch expected_start_lambda_failures.txt
1010

1111
# Validate test results
12-
$(dirname "$0")/../validate-test-results.sh start_lambda_output.txt expected_start_lambda_failures.txt "Start-Lambda tests"
12+
$GITHUB_WORKSPACE/scripts/validate-test-results.sh start_lambda_output.txt expected_start_lambda_failures.txt "Start-Lambda tests"

scripts/samcli-vm/invoke-teardown.patch

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
--- a/tests/integration/local/invoke/test_integrations_cli.py
22
+++ b/tests/integration/local/invoke/test_integrations_cli.py
3-
@@ -754,6 +754,11 @@
3+
@@ -755,7 +755,12 @@
44
docker_client = docker.from_env()
55
samcli_images = docker_client.images.list(name="samcli/lambda")
66
for image in samcli_images:
@@ -13,4 +13,31 @@
1313
+ print(f"An error occurred while trying to remove image {image.id}: {str(e)}")
1414

1515
shutil.rmtree(str(self.layer_cache), ignore_errors=True)
16-
+
16+
17+
@@ -772,7 +777,12 @@
18+
docker_client = docker.from_env()
19+
samcli_images = docker_client.images.list(name="samcli/lambda")
20+
for image in samcli_images:
21+
- docker_client.images.remove(image.id)
22+
+ try:
23+
+ docker_client.images.remove(image.id, force=True)
24+
+ except docker.errors.ImageNotFound:
25+
+ print(f"Image {image.id} was not found. It may have been removed already.")
26+
+ except Exception as e:
27+
+ print(f"An error occurred while trying to remove image {image.id}: {str(e)}")
28+
integ_layer_cache_dir = Path().home().joinpath("integ_layer_cache")
29+
if integ_layer_cache_dir.exists():
30+
shutil.rmtree(str(integ_layer_cache_dir))
31+
@@ -1012,7 +1022,12 @@
32+
docker_client = docker.from_env()
33+
samcli_images = docker_client.images.list(name="samcli/lambda")
34+
for image in samcli_images:
35+
- docker_client.images.remove(image.id)
36+
+ try:
37+
+ docker_client.images.remove(image.id, force=True)
38+
+ except docker.errors.ImageNotFound:
39+
+ print(f"Image {image.id} was not found. It may have been removed already.")
40+
+ except Exception as e:
41+
+ print(f"An error occurred while trying to remove image {image.id}: {str(e)}")
42+
43+
def test_layer_does_not_exist(self):

scripts/samcli-vm/run-invoke-tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@ test_successful_invoke
3636
EOF
3737

3838
# Validate test results
39-
$(dirname "$0")/../validate-test-results.sh /tmp/invoke_test_output.txt expected_invoke_failures.txt "Invoke tests"
39+
$GITHUB_WORKSPACE/finch-daemon-pr/scripts/validate-test-results.sh /tmp/invoke_test_output.txt expected_invoke_failures.txt "Invoke tests"

scripts/samcli-vm/run-package-tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ test_package_with_loadable_image_archive_0_template_image_load_yaml
2727
EOF
2828

2929
# Validate test results
30-
$(dirname "$0")/../validate-test-results.sh /tmp/package_test_output.txt expected_package_failures.txt "Package tests"
30+
$GITHUB_WORKSPACE/finch-daemon-pr/scripts/validate-test-results.sh /tmp/package_test_output.txt expected_package_failures.txt "Package tests"

scripts/samcli-vm/run-start-api-tests.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,12 @@ echo "=== START-API TESTS - Finished at $(date) ==="
3535

3636
# test_can_invoke_lambda_layer_successfully: Uses random port, fails occasionally.
3737
# Only 1 test of 386 total, acceptable failure rate.
38+
# test_changed_code_got_observed_and_loaded: Fails due to race conditions with containers.
39+
# Fails infrequently, but is of note.
3840
cat > expected_start_api_failures.txt << 'EOF'
3941
test_can_invoke_lambda_layer_successfully
42+
test_changed_code_got_observed_and_loaded
4043
EOF
4144

4245
# Validate test results
43-
$(dirname "$0")/../validate-test-results.sh /tmp/start_api_test_output.txt expected_start_api_failures.txt "Start-API tests"
46+
$GITHUB_WORKSPACE/finch-daemon-pr/scripts/validate-test-results.sh /tmp/start_api_test_output.txt expected_start_api_failures.txt "Start-API tests"

0 commit comments

Comments
 (0)