Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions cloudbuild/zb-system-tests-cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@ substitutions:
_SHORT_BUILD_ID: ${BUILD_ID:0:8}

steps:
# Step 0: Generate a persistent SSH key for this build run.
# This prevents gcloud from adding a new key to the OS Login profile on every ssh/scp command.
- name: "gcr.io/google.com/cloudsdktool/cloud-sdk"
id: "generate-ssh-key"
entrypoint: "bash"
args:
- "-c"
- |
mkdir -p /workspace/.ssh
# Generate the SSH key
ssh-keygen -t rsa -f /workspace/.ssh/google_compute_engine -N '' -C gcb
# Save the public key content to a file for the cleanup step
cat /workspace/.ssh/google_compute_engine.pub > /workspace/gcb_ssh_key.pub
waitFor: ["-"]

# 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.
Expand Down Expand Up @@ -38,19 +52,19 @@ steps:
set -e
# Wait for the VM to be fully initialized and SSH to be ready.
for i in {1..10}; do
if gcloud compute ssh gcsfs-test-vm-${_SHORT_BUILD_ID} --zone=${_ZONE} --internal-ip --command="echo VM is ready"; then
if gcloud compute ssh gcsfs-test-vm-${_SHORT_BUILD_ID} --zone=${_ZONE} --internal-ip --ssh-key-file=/workspace/.ssh/google_compute_engine --command="echo VM is ready"; then
break
fi
echo "Waiting for VM to become available... (attempt $i/10)"
sleep 15
done
# copy the script to the VM
gcloud compute scp cloudbuild/run_zonal_tests.sh gcsfs-test-vm-${_SHORT_BUILD_ID}:~ --zone=${_ZONE} --internal-ip
gcloud compute scp cloudbuild/run_zonal_tests.sh gcsfs-test-vm-${_SHORT_BUILD_ID}:~ --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 gcsfs-test-vm-${_SHORT_BUILD_ID} --zone=${_ZONE} --internal-ip --command="COMMIT_SHA=${COMMIT_SHA} _ZONAL_BUCKET=${_ZONAL_BUCKET} bash run_zonal_tests.sh"
gcloud compute ssh gcsfs-test-vm-${_SHORT_BUILD_ID} --zone=${_ZONE} --internal-ip --ssh-key-file=/workspace/.ssh/google_compute_engine --command="COMMIT_SHA=${COMMIT_SHA} _ZONAL_BUCKET=${_ZONAL_BUCKET} bash run_zonal_tests.sh"
EXIT_CODE=$?
set -e

Expand All @@ -62,6 +76,18 @@ steps:
waitFor:
- "create-vm"

- name: "gcr.io/google.com/cloudsdktool/cloud-sdk"
id: "cleanup-ssh-key"
entrypoint: "bash"
args:
- "-c"
- |
echo "--- Removing SSH key from OS Login profile to prevent accumulation ---"
gcloud compute os-login ssh-keys remove \
--key-file=/workspace/gcb_ssh_key.pub || true
waitFor:
- "run-tests-and-delete-vm"

timeout: "3600s" # 60 minutes

options:
Expand Down