Skip to content

Commit 485b03a

Browse files
authored
chore: optimize zonal tests cloning and fix paths (#16581)
This PR contains changes to optimize zonal tests cloning and fix paths.
1 parent 70dc6bf commit 485b03a

File tree

2 files changed

+42
-5
lines changed

2 files changed

+42
-5
lines changed

packages/google-cloud-storage/cloudbuild/run_zonal_tests.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ echo '--- Installing git and cloning repository on VM ---'
44
sudo apt-get update && sudo apt-get install -y git python3-pip python3-venv
55

66
# Clone the repository and checkout the specific commit from the build trigger.
7-
git clone https://github.com/googleapis/python-storage.git
8-
cd python-storage
7+
git clone --no-checkout --depth 1 --sparse --filter=blob:none https://github.com/googleapis/google-cloud-python.git
8+
cd google-cloud-python
9+
git sparse-checkout set packages/google-cloud-storage
910
git fetch origin "refs/pull/${_PR_NUMBER}/head"
1011
git checkout ${COMMIT_SHA}
12+
cd packages/google-cloud-storage
1113

1214

1315
echo '--- Installing Python and dependencies on VM ---'
@@ -27,4 +29,3 @@ export GCE_METADATA_MTLS_MODE=None
2729
CURRENT_ULIMIT=$(ulimit -n)
2830
echo '--- Running Zonal tests on VM with ulimit set to ---' $CURRENT_ULIMIT
2931
pytest -vv -s --log-format='%(asctime)s %(levelname)s %(message)s' --log-date-format='%H:%M:%S' tests/system/test_zonal.py
30-
pytest -vv -s --log-format='%(asctime)s %(levelname)s %(message)s' --log-date-format='%H:%M:%S' samples/snippets/zonal_buckets/zonal_snippets_test.py

packages/google-cloud-storage/cloudbuild/zb-system-tests-cloudbuild.yaml

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,41 @@ steps:
2323
cat /workspace/.ssh/google_compute_engine.pub > /workspace/gcb_ssh_key.pub
2424
waitFor: ["-"]
2525

26+
- name: "gcr.io/google.com/cloudsdktool/cloud-sdk"
27+
id: "cleanup-old-keys"
28+
entrypoint: "bash"
29+
args:
30+
- "-c"
31+
- |
32+
#!/bin/bash
33+
set -e
34+
35+
echo "Fetching OS Login SSH keys..."
36+
echo "Removing all keys."
37+
echo "---------------------------------------------------------------------"
38+
39+
FINGERPRINTS_TO_DELETE=$$(gcloud compute os-login ssh-keys list \
40+
--format="value(fingerprint)")
41+
42+
echo "Keys to delete: $$FINGERPRINTS_TO_DELETE"
43+
44+
if [ -z "$$FINGERPRINTS_TO_DELETE" ]; then
45+
echo "No keys found to delete. Nothing to do."
46+
exit 0
47+
fi
48+
49+
while IFS= read -r FINGERPRINT; do
50+
if [ -n "$$FINGERPRINT" ]; then
51+
echo "Deleting key with fingerprint: $$FINGERPRINT"
52+
gcloud compute os-login ssh-keys remove \
53+
--key="$$FINGERPRINT" \
54+
--quiet || true
55+
fi
56+
done <<< "$$FINGERPRINTS_TO_DELETE"
57+
58+
echo "---------------------------------------------------------------------"
59+
echo "Cleanup complete."
60+
2661
# Step 1 Create a GCE VM to run the tests.
2762
# The VM is created in the same zone as the buckets to test rapid storage features.
2863
# It's given the 'cloud-platform' scope to allow it to access GCS and other services.
@@ -63,12 +98,12 @@ steps:
6398
sleep 15
6499
done
65100
# copy the script to the VM
66-
gcloud compute scp cloudbuild/run_zonal_tests.sh ${_VM_NAME}:~ --zone=${_ZONE} --internal-ip --ssh-key-file=/workspace/.ssh/google_compute_engine
101+
gcloud compute scp packages/google-cloud-storage/cloudbuild/run_zonal_tests.sh ${_VM_NAME}:~ --zone=${_ZONE} --internal-ip --ssh-key-file=/workspace/.ssh/google_compute_engine
67102
68103
# Execute the script on the VM via SSH.
69104
# Capture the exit code to ensure cleanup happens before the build fails.
70105
set +e
71-
gcloud compute ssh ${_VM_NAME} --zone=${_ZONE} --internal-ip --ssh-key-file=/workspace/.ssh/google_compute_engine --command="ulimit -n {_ULIMIT}; COMMIT_SHA=${COMMIT_SHA} _ZONAL_BUCKET=${_ZONAL_BUCKET} CROSS_REGION_BUCKET=${_CROSS_REGION_BUCKET} _PR_NUMBER=${_PR_NUMBER} bash run_zonal_tests.sh"
106+
gcloud compute ssh ${_VM_NAME} --zone=${_ZONE} --internal-ip --ssh-key-file=/workspace/.ssh/google_compute_engine --command="ulimit -n ${_ULIMIT}; COMMIT_SHA=${COMMIT_SHA} _ZONAL_BUCKET=${_ZONAL_BUCKET} CROSS_REGION_BUCKET=${_CROSS_REGION_BUCKET} _PR_NUMBER=${_PR_NUMBER} bash run_zonal_tests.sh"
72107
EXIT_CODE=$?
73108
set -e
74109
@@ -80,6 +115,7 @@ steps:
80115
waitFor:
81116
- "create-vm"
82117
- "generate-ssh-key"
118+
- "cleanup-old-keys"
83119

84120
- name: "gcr.io/google.com/cloudsdktool/cloud-sdk"
85121
id: "cleanup-ssh-key"

0 commit comments

Comments
 (0)