Skip to content

Commit dcee867

Browse files
committed
patch
1 parent f8a0ad8 commit dcee867

File tree

1 file changed

+47
-22
lines changed

1 file changed

+47
-22
lines changed

.github/workflows/integration_test.yml

Lines changed: 47 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ jobs:
115115
- name: Classify PE Master with pe_repo::platform (via RBAC token)
116116
env:
117117
BOLT_GEM: "1"
118-
# Optional: override if your plan uses a different admin password
118+
# If your install plan sets a different admin password, override here:
119119
PE_ADMIN_PASSWORD: "Puppetlabs123!"
120120
shell: bash
121121
run: |
@@ -124,44 +124,69 @@ jobs:
124124
if [[ -z "$MASTER" ]]; then echo "Empty master target"; exit 1; fi
125125
126126
# Map matrix platform -> PE platform tag -> class suffix
127-
INPUT="${{ matrix.platform }}" # ubuntu-2204-lts
127+
INPUT="${{ matrix.platform }}" # e.g. ubuntu-2204-lts
128128
OS="${INPUT%%-*}" # ubuntu
129129
VER="${INPUT#*-}" ; VER="${VER%-lts}" # 2204
130130
TAG="${OS}-${VER:0:2}.${VER:2:2}-amd64" # ubuntu-22.04-amd64
131131
SUFFIX="${TAG//-/_}" ; SUFFIX="${SUFFIX//./}" # ubuntu_2204_amd64
132132
CLASS="pe_repo::platform::${SUFFIX}"
133-
echo "Classifying master with: ${CLASS} for tag ${TAG}"
133+
echo "Classifying master with: ${CLASS} (platform tag: ${TAG})"
134134
135+
# Run remotely under Bash so we can use pipefail and here-strings
135136
bundle exec bolt command run "/bin/bash -lc '
136137
set -euo pipefail
137138
export PATH=/opt/puppetlabs/bin:/opt/puppetlabs/puppet/bin:\$PATH
139+
CACERT=\$(/opt/puppetlabs/bin/puppet config print localcacert)
138140
139-
# Obtain/refresh an RBAC token (retry a few times while services settle)
141+
# Acquire RBAC token via API (retry while services come up)
142+
LOGIN_PAYLOAD=\$(ruby -e \"puts({login: \\\"admin\\\", password: \\\"${PE_ADMIN_PASSWORD}\\\", lifetime: \\\"30m\\\"}.to_json)\")
140143
for i in {1..10}; do
141-
if /opt/puppetlabs/bin/puppet-access show >/dev/null 2>&1; then
142-
break
143-
fi
144-
/opt/puppetlabs/bin/puppet-access login \
145-
--lifetime 30m \
146-
-u admin -p \"${PE_ADMIN_PASSWORD}\" && break || sleep 6
144+
RESP=\$(curl -sS --fail-with-body --cacert \"\$CACERT\" \
145+
-H \"Content-Type: application/json\" \
146+
-d \"\$LOGIN_PAYLOAD\" \
147+
https://localhost:4433/rbac-api/v1/auth/token) || true
148+
TOKEN=\$(ruby -rjson -e \"j=STDIN.read; puts(JSON.parse(j)[\\\"token\\\"] rescue '')\" <<< \"\$RESP\")
149+
[[ -n \"\$TOKEN\" ]] && break
150+
echo \"Waiting for RBAC to issue token... (\$i/10)\" >&2
151+
sleep 6
147152
done
148-
TOKEN=\$(/opt/puppetlabs/bin/puppet-access show || true)
149153
if [[ -z \"\$TOKEN\" ]]; then
150-
echo \"Failed to obtain RBAC token\" >&2
154+
echo \"Failed to obtain RBAC token; last response:\" >&2
155+
echo \"\$RESP\" >&2
151156
exit 1
152157
fi
153-
154-
# Fetch PE Master group id
155-
GROUPS=\$(curl -sS -k -H \"X-Authentication: \$TOKEN\" https://localhost:4433/classifier-api/v1/groups)
156-
ID=\$(ruby -rjson -e \"g=JSON.parse(STDIN.read); pe=g.find{|x| x['name']=='PE Master'} or abort('PE Master group not found'); puts pe['id']\" <<< \"\$GROUPS\")
157-
158-
# Merge class into group
159-
CURR=\$(curl -sS -k -H \"X-Authentication: \$TOKEN\" https://localhost:4433/classifier-api/v1/groups/\$ID)
160-
UPDATED=\$(CLASS=\"${CLASS}\" ruby -rjson -e \"g=JSON.parse(STDIN.read); g['classes']||={}; g['classes'][ENV['CLASS']]||={}; puts({'id'=>g['id'],'classes'=>g['classes']}.to_json)\" <<< \"\$CURR\")
161-
curl -sS -k -X POST -H \"X-Authentication: \$TOKEN\" -H 'Content-Type: application/json' \
162-
-d \"\$UPDATED\" https://localhost:4433/classifier-api/v1/groups/\$ID >/dev/null
158+
echo \"RBAC token acquired\"
159+
160+
# Find the PE Master group id
161+
GROUPS=\$(curl -sS --fail-with-body --cacert \"\$CACERT\" \
162+
-H \"X-Authentication: \$TOKEN\" \
163+
https://localhost:4433/classifier-api/v1/groups)
164+
ID=\$(
165+
ruby -rjson -e \"g=JSON.parse(STDIN.read); pe=g.find{|x| x['name']=='PE Master'} or abort('PE Master group not found'); puts pe['id']\" \
166+
<<< \"\$GROUPS\"
167+
)
168+
echo \"PE Master group id: \$ID\"
169+
170+
# Merge the platform class into the group's classes
171+
CURR=\$(curl -sS --fail-with-body --cacert \"\$CACERT\" \
172+
-H \"X-Authentication: \$TOKEN\" \
173+
https://localhost:4433/classifier-api/v1/groups/\$ID)
174+
UPDATED=\$(
175+
CLASS=\"${CLASS}\" ruby -rjson -e \"g=JSON.parse(STDIN.read); g['classes']||={}; g['classes'][ENV['CLASS']]||={}; print({id: g['id'], classes: g['classes']}.to_json)\" \
176+
<<< \"\$CURR\"
177+
)
178+
179+
# POST the partial update (merge) back to the group
180+
curl -sS --fail-with-body --cacert \"\$CACERT\" \
181+
-H \"X-Authentication: \$TOKEN\" \
182+
-H \"Content-Type: application/json\" \
183+
-X POST -d \"\$UPDATED\" \
184+
https://localhost:4433/classifier-api/v1/groups/\$ID >/dev/null
185+
186+
echo \"Class ${CLASS} merged into PE Master group\"
163187
'" -i spec/fixtures/litmus_inventory.yaml --targets "$MASTER"
164188
189+
165190
# 3) Converge master again so pe_repo materializes platform content
166191
- name: Converge PE master (stabilize services & pe_repo)
167192
env:

0 commit comments

Comments
 (0)