diff --git a/packages/google-cloud-storage/cloudbuild/run_zonal_tests.sh b/packages/google-cloud-storage/cloudbuild/run_zonal_tests.sh index 2d42ce6d5f68..7baabf888753 100644 --- a/packages/google-cloud-storage/cloudbuild/run_zonal_tests.sh +++ b/packages/google-cloud-storage/cloudbuild/run_zonal_tests.sh @@ -4,10 +4,12 @@ echo '--- Installing git and cloning repository on VM ---' sudo apt-get update && sudo apt-get install -y git python3-pip python3-venv # Clone the repository and checkout the specific commit from the build trigger. -git clone https://github.com/googleapis/python-storage.git -cd python-storage +git clone --no-checkout --depth 1 --sparse --filter=blob:none https://github.com/googleapis/google-cloud-python.git +cd google-cloud-python +git sparse-checkout set packages/google-cloud-storage git fetch origin "refs/pull/${_PR_NUMBER}/head" git checkout ${COMMIT_SHA} +cd packages/google-cloud-storage echo '--- Installing Python and dependencies on VM ---' @@ -27,4 +29,3 @@ export GCE_METADATA_MTLS_MODE=None CURRENT_ULIMIT=$(ulimit -n) echo '--- Running Zonal tests on VM with ulimit set to ---' $CURRENT_ULIMIT pytest -vv -s --log-format='%(asctime)s %(levelname)s %(message)s' --log-date-format='%H:%M:%S' tests/system/test_zonal.py -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 diff --git a/packages/google-cloud-storage/cloudbuild/zb-system-tests-cloudbuild.yaml b/packages/google-cloud-storage/cloudbuild/zb-system-tests-cloudbuild.yaml index 26daa8ae92d9..868d13958474 100644 --- a/packages/google-cloud-storage/cloudbuild/zb-system-tests-cloudbuild.yaml +++ b/packages/google-cloud-storage/cloudbuild/zb-system-tests-cloudbuild.yaml @@ -23,6 +23,41 @@ steps: cat /workspace/.ssh/google_compute_engine.pub > /workspace/gcb_ssh_key.pub waitFor: ["-"] + - name: "gcr.io/google.com/cloudsdktool/cloud-sdk" + id: "cleanup-old-keys" + entrypoint: "bash" + args: + - "-c" + - | + #!/bin/bash + set -e + + echo "Fetching OS Login SSH keys..." + echo "Removing all keys." + echo "---------------------------------------------------------------------" + + FINGERPRINTS_TO_DELETE=$$(gcloud compute os-login ssh-keys list \ + --format="value(fingerprint)") + + echo "Keys to delete: $$FINGERPRINTS_TO_DELETE" + + if [ -z "$$FINGERPRINTS_TO_DELETE" ]; then + echo "No keys found to delete. Nothing to do." + exit 0 + fi + + while IFS= read -r FINGERPRINT; do + if [ -n "$$FINGERPRINT" ]; then + echo "Deleting key with fingerprint: $$FINGERPRINT" + gcloud compute os-login ssh-keys remove \ + --key="$$FINGERPRINT" \ + --quiet || true + fi + done <<< "$$FINGERPRINTS_TO_DELETE" + + echo "---------------------------------------------------------------------" + echo "Cleanup complete." + # Step 1 Create a GCE VM to run the tests. # The VM is created in the same zone as the buckets to test rapid storage features. # It's given the 'cloud-platform' scope to allow it to access GCS and other services. @@ -63,12 +98,12 @@ steps: sleep 15 done # copy the script to the VM - gcloud compute scp cloudbuild/run_zonal_tests.sh ${_VM_NAME}:~ --zone=${_ZONE} --internal-ip --ssh-key-file=/workspace/.ssh/google_compute_engine + 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 # Execute the script on the VM via SSH. # Capture the exit code to ensure cleanup happens before the build fails. set +e - 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" + 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" EXIT_CODE=$? set -e @@ -80,6 +115,7 @@ steps: waitFor: - "create-vm" - "generate-ssh-key" + - "cleanup-old-keys" - name: "gcr.io/google.com/cloudsdktool/cloud-sdk" id: "cleanup-ssh-key"