Skip to content

Commit 3a62db4

Browse files
committed
fix: have org-manager-user create space to retain SpaceDeveloper role
Root cause: org-manager-user lost SpaceDeveloper between the deploy step and test execution (~50 min gap). Without it, cf curl POST to create tasks returns an authorization error, failing all acceptance test suites. Previously admin created the space and explicitly granted roles to org-manager-user — but those roles could be lost if anything recreated the space between deploy and test execution. Fix: - Have org-manager-user create the space (creator auto-gets SpaceManager+SpaceDeveloper, which persists with the space) - Admin only needs roles for cleanup operations - Test runner re-ensures SpaceDeveloper as a safety net before task launch - Added diagnostic logging: app state, droplet, and full CF API response on task creation failure (no more silent errors)
1 parent d389cc6 commit 3a62db4

2 files changed

Lines changed: 49 additions & 7 deletions

File tree

.github/workflows/acceptance_tests_reusable.yaml

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,28 @@ jobs:
7979
run: |
8080
make --directory="${AUTOSCALER_DIR}" deploy-cleanup || echo "Cleanup warnings expected if nothing exists"
8181
82-
- name: Grant space roles after space recreation
82+
- name: Create space as org-manager-user (ensures inherent SpaceDeveloper role)
8383
shell: bash
8484
run: |
8585
source "${AUTOSCALER_DIR}/scripts/vars.source.sh"
8686
source "${AUTOSCALER_DIR}/scripts/common.sh"
8787
bbl_login
88+
89+
# Admin ensures org exists and grants OrgManager (needed for space creation)
90+
cf_admin_login
91+
find_or_create_org "${AUTOSCALER_ORG}"
92+
93+
# org-manager-user creates the space — creator auto-gets SpaceManager+SpaceDeveloper
94+
cf api "https://api.${system_domain}" --skip-ssl-validation
95+
cf auth "${AUTOSCALER_ORG_MANAGER_USER}" "${AUTOSCALER_ORG_MANAGER_PASSWORD}"
96+
cf target -o "${AUTOSCALER_ORG}"
97+
cf create-space "${AUTOSCALER_SPACE}" || echo "Space already exists"
98+
cf target -s "${AUTOSCALER_SPACE}"
99+
100+
# Grant admin SpaceDeveloper too (needed for cleanup operations)
88101
cf_admin_login
89-
cf_target "${AUTOSCALER_ORG}" "${AUTOSCALER_SPACE}"
90-
cf set-space-role "${AUTOSCALER_ORG_MANAGER_USER}" "${AUTOSCALER_ORG}" "${AUTOSCALER_SPACE}" SpaceDeveloper
91-
cf set-space-role "${AUTOSCALER_ORG_MANAGER_USER}" "${AUTOSCALER_ORG}" "${AUTOSCALER_SPACE}" SpaceManager
102+
cf set-space-role admin "${AUTOSCALER_ORG}" "${AUTOSCALER_SPACE}" SpaceDeveloper
103+
cf set-space-role admin "${AUTOSCALER_ORG}" "${AUTOSCALER_SPACE}" SpaceManager
92104
93105
- name: Provision DB
94106
shell: bash

scripts/run-mta-acceptance-tests.sh

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,19 @@ validate_app() {
4444
[[ -n "${APP_GUID}" ]] || { echo "ERROR: acceptance-tests app not found. Run: make mta-deploy"; exit 1; }
4545

4646
echo " ✓ App found (GUID: ${APP_GUID:0:8})"
47+
48+
# Diagnostic: check app state and droplet
49+
local app_state
50+
app_state=$(cf curl "/v3/apps/${APP_GUID}" 2>/dev/null | jq -r '.state // "UNKNOWN"')
51+
echo " App state: ${app_state}"
52+
53+
local droplet
54+
droplet=$(cf curl "/v3/apps/${APP_GUID}/droplets/current" 2>/dev/null | jq -r '.guid // empty')
55+
if [[ -n "${droplet}" ]]; then
56+
echo " ✓ Current droplet: ${droplet:0:8}"
57+
else
58+
echo " ✗ WARNING: No current droplet assigned"
59+
fi
4760
}
4861

4962
launch_task() {
@@ -55,13 +68,18 @@ launch_task() {
5568

5669
local guid
5770
local cf_output
58-
cf_output=$(cf curl "/v3/apps/${APP_GUID}/tasks" -X POST -d "$(jq -n --arg n "${task_name}" --arg c "${cmd}" \
59-
'{name:$n,command:$c,memory_in_mb:2048,disk_in_mb:2048}')" 2>&1)
60-
guid=$(echo "$cf_output" | jq -r '.guid // empty')
71+
local payload
72+
payload=$(jq -n --arg n "${task_name}" --arg c "${cmd}" \
73+
'{name:$n,command:$c,memory_in_mb:2048,disk_in_mb:2048}')
74+
cf_output=$(cf curl "/v3/apps/${APP_GUID}/tasks" -X POST -d "${payload}" 2>&1)
75+
guid=$(echo "$cf_output" | jq -r '.guid // empty' 2>/dev/null)
6176
if [[ -n "${guid}" ]]; then
6277
echo "${guid}"
6378
else
6479
echo "ERROR: Failed to launch task for ${suite}" >&2
80+
echo " API response: ${cf_output}" >&2
81+
echo " APP_GUID: ${APP_GUID}" >&2
82+
echo " Payload: ${payload}" >&2
6583
echo "FAILED"
6684
fi
6785
}
@@ -176,6 +194,18 @@ main() {
176194
bbl_login
177195
cf_deployment_login
178196
cf_target "${autoscaler_org}" "${autoscaler_space}"
197+
198+
# On PR branches, ensure org-manager-user has SpaceDeveloper (may have been lost
199+
# between deploy and test execution if another workflow recreated the space).
200+
if [[ "${PR_NUMBER:-main}" != "main" ]]; then
201+
step "Ensuring space roles for ${AUTOSCALER_ORG_MANAGER_USER}"
202+
cf_admin_login
203+
cf set-space-role "${AUTOSCALER_ORG_MANAGER_USER}" "${autoscaler_org}" "${autoscaler_space}" SpaceDeveloper 2>/dev/null || true
204+
# Switch back to org-manager-user for task operations
205+
cf_deployment_login
206+
cf target -o "${autoscaler_org}" -s "${autoscaler_space}"
207+
fi
208+
179209
validate_app
180210

181211
# Launch tasks

0 commit comments

Comments
 (0)