Skip to content

Commit 7601a12

Browse files
authored
Use shepherd envs instead on toolsmiths for tests (main) (#2862)
Use shepherd environments instead of toolsmiths to run integration tests. As part of this change, min capi job is disabled since we are still figuring out our versioning policy of how long CLI should support an old version of CAPI.
1 parent 38445c1 commit 7601a12

File tree

2 files changed

+58
-61
lines changed

2 files changed

+58
-61
lines changed

.github/workflows/tests-integration-reusable.yml

Lines changed: 48 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22

33
# secrets.CLIENT_SECRET
44
# secrets.GITHUB_TOKEN
5-
# secrets.TOOLSMITHS_API_TOKEN
6-
# vars.TOOLSMITHS_HOSTNAME
7-
# vars.TOOLSMITHS_POOL_NAME
5+
# secrets.SHEPHERD_SERVICE_ACCOUNT_TOKEN
6+
# vars.SHEPHERD_POOL_NAME
87

98
name: "pvt: run integration tests"
109

@@ -30,7 +29,7 @@ jobs:
3029
run:
3130
shell: bash
3231
runs-on: ${{ inputs.os }}
33-
32+
container: us-west2-docker.pkg.dev/shepherd-268822/shepherd2/concourse-resource:latest
3433
steps:
3534
- uses: LouisBrunner/[email protected]
3635
if: always()
@@ -42,6 +41,7 @@ jobs:
4241
sha: ${{github.event.workflow_run.head_sha}}
4342
output: |
4443
{"title": "${{ inputs.name }}", "summary":"started ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"}
44+
4545
- name: Checkout cli
4646
uses: actions/checkout@v4
4747
with:
@@ -56,6 +56,8 @@ jobs:
5656
- id: read-min-capi
5757
name: Read MIN CAPI
5858
run: |
59+
wget https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -O /usr/bin/yq &&\
60+
chmod +x /usr/bin/yq
5961
version=$(yq '.capi-version-min' build_data.yml)
6062
echo "version=$version" >> $GITHUB_OUTPUT
6163
@@ -80,38 +82,36 @@ jobs:
8082
repository: cloudfoundry/cf-deployment-concourse-tasks
8183
path: cf-deployment-concourse-tasks
8284

83-
- id: claim-toolsmiths-env
84-
name: Claim Toolsmiths Environment
85+
- id: claim-env
86+
name: Claim Environment
8587
env:
86-
api_token: ${{ secrets.TOOLSMITHS_API_TOKEN }}
87-
hostname: ${{ vars.TOOLSMITHS_HOSTNAME }}
88-
notes: "GHA CF CLI Integration Tests ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
89-
pool_name: ${{ vars.TOOLSMITHS_POOL_NAME }}
88+
account_token: ${{ secrets.SHEPHERD_SERVICE_ACCOUNT_TOKEN }}
89+
pool_name: ${{ vars.SHEPHERD_POOL_NAME }}
9090
run: |
91-
while true; do
92-
curl -s --show-error -D headers.txt -H 'Accept: application/json' \
93-
-X POST "https://${hostname}/pooled_gcp_engineering_environments/claim" \
94-
--data-urlencode "api_token=${api_token}" \
95-
--data-urlencode "pool_name=${pool_name}" \
96-
--data-urlencode "notes=${notes}" > metadata.json \
97-
|| echo "Unable to reach server, trying again in 30 seconds..."
98-
99-
cat headers.txt
100-
101-
ERR_500="Sorry, the Toolsmiths Environments app is currently encountering issues. Trying again in 30 seconds..."
102-
ERR_429="Sorry, Toolsmiths are out of environments in your requested pool. New environments are on their way but you can stop by the Toolsmiths slack channel for more help."
103-
ERR_409="Sorry, was not able to claim an environment. Trying again in 30 seconds..."
104-
105-
grep -q -E "HTTP/[[:digit:]\.]{1,3} 401" headers.txt && exit 1
106-
grep -q -E "HTTP/[[:digit:]\.]{1,3} 404" headers.txt && exit 2
107-
grep -q -E "HTTP/[[:digit:]\.]{1,3} 500" headers.txt && echo "$ERR_500"
108-
grep -q -E "HTTP/[[:digit:]\.]{1,3} 200" headers.txt && break
109-
grep -q -E "HTTP/[[:digit:]\.]{1,3} 429" && echo "$ERR_429"
110-
grep -q -E "HTTP/[[:digit:]\.]{1,3} 409" && echo "$ERR_409"
91+
shepherd login service-account ${account_token}
92+
lease_id=$(shepherd create lease --duration 8h --pool ${pool_name} --pool-namespace official --namespace tas-devex --json | jq -r .id)
11193
94+
# Give somtime for the lease to complete. Shepherd may take upto an 3 hours to create an env
95+
# if the pool is empty.
96+
count=0
97+
while [ $count -lt 360 ] ; do
11298
sleep 30
99+
status=$(shepherd get lease ${lease_id} --namespace tas-devex --json | jq -r .status)
100+
if [ $status == "LEASED" ] ; then
101+
shepherd get lease ${lease_id} --namespace tas-devex --json | jq .output > metadata.json
102+
break
103+
elif [ $status == "FAILED" -o $status == "EXPIRED" ] ; then
104+
echo "There was an error obtaining the lease. Lease status is ${status}."
105+
exit 1
106+
else
107+
echo "Waiting for environment to be ready. Lease status is ${status}."
108+
fi
109+
count=$(($count+1))
113110
done
111+
112+
env_name=$(jq -r .name metadata.json)
114113
cat metadata.json | jq -r '.name'
114+
echo "lease-id=$lease_id" >> "${GITHUB_OUTPUT}"
115115
116116
- name: Install Tools
117117
run: |
@@ -141,11 +141,16 @@ jobs:
141141
chmod +x $install_location/credhub
142142
credhub --version
143143
144+
apt-get update
145+
apt-get install -y build-essential
146+
144147
- name: Deploy Isolation Segment and OIDC Provider
145148
if: ${{ inputs.capi-version == 'edge' }}
146149
env:
147150
CF_INT_CLIENT_SECRET: ${{ secrets.CLIENT_SECRET }}
148151
run: |
152+
env_name=$(jq -r .name metadata.json)
153+
jq -r .bosh.jumpbox_private_key metadata.json > /tmp/${env_name}.priv
149154
eval "$(bbl print-env --metadata-file metadata.json)"
150155
151156
# deploy
@@ -182,6 +187,8 @@ jobs:
182187
cp cli-ci/ci/infrastructure/operations/use-latest-ruby-buildpack.yml ops-files/
183188
184189
# Deletes CF-D
190+
env_name=$(jq -r .name metadata.json)
191+
jq -r .bosh.jumpbox_private_key metadata.json > /tmp/${env_name}.priv
185192
eval "$(bbl print-env --metadata-file metadata.json)"
186193
bosh -d cf delete-deployment -n
187194
@@ -225,11 +232,13 @@ jobs:
225232
if: ${{ !inputs.run-with-client-creds }}
226233
run: |
227234
ENV=$(cat metadata.json | jq -r '.name')
235+
jq -r .bosh.jumpbox_private_key metadata.json > /tmp/${ENV}.priv
228236
eval "$(bbl print-env --metadata-file ./metadata.json)"
229237
export CF_INT_PASSWORD="$(credhub get -n /bosh-$ENV/cf/cf_admin_password | bosh interpolate --path /value -)"
230238
export CF_INT_OIDC_USERNAME="admin-oidc"
231239
export CF_INT_OIDC_PASSWORD=$(credhub get -n /bosh-$ENV/cf/uaa_oidc_admin_password | bosh interpolate --path /value -)
232-
export CF_INT_API="https://api.${ENV}.cf-app.com"
240+
API_URL="$(jq -r .cf.api_url metadata.json)"
241+
export CF_INT_API="https://$API_URL"
233242
export CF_DIAL_TIMEOUT=15
234243
export CF_USERNAME=admin
235244
export FLAKE_ATTEMPTS=2
@@ -255,11 +264,13 @@ jobs:
255264
CF_INT_CLIENT_SECRET: ${{ secrets.CLIENT_SECRET }}
256265
run: |
257266
ENV=$(cat metadata.json | jq -r '.name')
267+
jq -r .bosh.jumpbox_private_key metadata.json > /tmp/${ENV}.priv
258268
eval "$(bbl print-env --metadata-file ./metadata.json)"
259269
export CF_INT_PASSWORD="$(credhub get -n /bosh-$ENV/cf/cf_admin_password | bosh interpolate --path /value -)"
260270
export CF_INT_OIDC_USERNAME="admin-oidc"
261271
export CF_INT_OIDC_PASSWORD=$(credhub get -n /bosh-$ENV/cf/uaa_oidc_admin_password | bosh interpolate --path /value -)
262-
export CF_INT_API="https://api.${ENV}.cf-app.com"
272+
API_URL="$(jq -r .cf.api_url metadata.json)"
273+
export CF_INT_API="https://$API_URL"
263274
export CF_DIAL_TIMEOUT=15
264275
export CF_USERNAME=admin
265276
export FLAKE_ATTEMPTS=2
@@ -278,29 +289,15 @@ jobs:
278289
279290
make integration-tests-full-ci
280291
281-
282292
- name: Unclaim environment
283293
if: always()
284294
env:
285-
api_token: ${{ secrets.TOOLSMITHS_API_TOKEN }}
286-
hostname: ${{ vars.TOOLSMITHS_HOSTNAME }}
295+
account_token: ${{ secrets.SHEPHERD_SERVICE_ACCOUNT_TOKEN }}
287296
run: |
288-
ENV=$(cat metadata.json | jq -r '.name')
289-
while true; do
290-
output=$(curl -s --show-error -D headers.txt -H 'Accept: application/json' \
291-
-X POST "https://${hostname}/pooled_gcp_engineering_environments/unclaim" \
292-
--data-urlencode "api_token=${api_token}" \
293-
--data-urlencode "name=${ENV}")
294-
295-
cat headers.txt
296-
297-
ERR_500="Sorry, the Toolsmiths Environments app is currently encountering issues. Trying again in 30 seconds..."
298-
299-
grep -q -E "HTTP/[[:digit:]\.]{1,3} 500" headers.txt && echo "$ERR_500" && sleep 30 && continue
300-
grep -q -E "HTTP/[[:digit:]\.]{1,3} 401" headers.txt && echo $(echo "$output" | jq '.messages | join(", ")') && exit 1
301-
grep -q -E "HTTP/[[:digit:]\.]{1,3} 404" headers.txt && echo $(echo "$output" | jq '.messages | join(", ")') && exit 2
302-
grep -q -E "HTTP/[[:digit:]\.]{1,3} 202" headers.txt && break
303-
done
297+
shepherd login service-account ${account_token}
298+
set -x
299+
shepherd delete lease ${{ steps.claim-env.outputs.lease-id }} --namespace tas-devex
300+
304301
- uses: LouisBrunner/[email protected]
305302
if: always()
306303
with:

.github/workflows/tests-integration.yml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,16 @@ jobs:
3333
name: Integration client creds
3434
secrets: inherit
3535

36-
run-integration-tests-cf-env-with-min-capi:
37-
name: MIN CAPI
38-
if: ${{ github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success' }}
39-
uses: ./.github/workflows/tests-integration-reusable.yml
40-
with:
41-
capi-version: min
42-
run-with-client-creds: false
43-
os: ubuntu-latest
44-
name: Integration MIN CAPI
45-
secrets: inherit
36+
# run-integration-tests-cf-env-with-min-capi:
37+
# name: MIN CAPI
38+
# # if: ${{ github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success' }}
39+
# uses: ./.github/workflows/tests-integration-reusable.yml
40+
# with:
41+
# capi-version: min
42+
# run-with-client-creds: false
43+
# os: ubuntu-latest
44+
# name: Integration MIN CAPI
45+
# secrets: inherit
4646

4747
#run-integration-windows:
4848
# name: Windows

0 commit comments

Comments
 (0)