Skip to content

Commit 0e31627

Browse files
committed
patch 2
1 parent 15b5bc1 commit 0e31627

File tree

1 file changed

+57
-37
lines changed

1 file changed

+57
-37
lines changed

.github/workflows/integration_test.yml

Lines changed: 57 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ jobs:
5050
runs-on: ubuntu-24.04
5151
strategy:
5252
fail-fast: false
53-
matrix: ${{fromJson(needs.setup_matrix.outputs.matrix)}}
53+
matrix: ${{ fromJson(needs.setup_matrix.outputs.matrix) }}
5454

5555
steps:
5656

@@ -96,74 +96,94 @@ jobs:
9696
puts "master_uri=#{t["uri"]}"
9797
' >> $GITHUB_OUTPUT
9898
99-
# === FIXED STEP: run classifier API via Bash on the master ===
100-
- name: Classify PE Master with pe_repo::platform (via classifier API)
99+
# 1) Warm up services BEFORE classification (2 quick runs)
100+
- name: Warm up PE master (first convergence)
101101
env:
102102
BOLT_GEM: "1"
103103
shell: bash
104+
run: |
105+
MASTER='${{ steps.pe-master.outputs.master_uri }}'
106+
MASTER=${MASTER//\"/}; MASTER=${MASTER//\'/}
107+
for i in 1 2; do
108+
echo "puppet agent -t (warm-up run $i) on $MASTER"
109+
bundle exec bolt command run "/opt/puppetlabs/bin/puppet agent -t || true" \
110+
-i spec/fixtures/litmus_inventory.yaml --targets "$MASTER"
111+
sleep 10
112+
done
113+
114+
# 2) Classify master with the pe_repo platform using RBAC token
115+
- name: Classify PE Master with pe_repo::platform (via RBAC token)
116+
env:
117+
BOLT_GEM: "1"
118+
# Optional: override if your plan uses a different admin password
119+
PE_ADMIN_PASSWORD: "Puppetlabs123!"
120+
shell: bash
104121
run: |
105122
MASTER='${{ steps.pe-master.outputs.master_uri }}'
106123
MASTER=${MASTER//\"/}; MASTER=${MASTER//\'/}
107124
if [[ -z "$MASTER" ]]; then echo "Empty master target"; exit 1; fi
108125
109-
# Map matrix platform (e.g. ubuntu-2204-lts) -> ubuntu-22.04-amd64 -> ubuntu_2204_amd64
126+
# Map matrix platform -> PE platform tag -> class suffix
110127
INPUT="${{ matrix.platform }}" # ubuntu-2204-lts
111128
OS="${INPUT%%-*}" # ubuntu
112129
VER="${INPUT#*-}" ; VER="${VER%-lts}" # 2204
113130
TAG="${OS}-${VER:0:2}.${VER:2:2}-amd64" # ubuntu-22.04-amd64
114131
SUFFIX="${TAG//-/_}" ; SUFFIX="${SUFFIX//./}" # ubuntu_2204_amd64
115132
CLASS="pe_repo::platform::${SUFFIX}"
116-
echo "Classifying master with: ${CLASS}"
133+
echo "Classifying master with: ${CLASS} for tag ${TAG}"
117134
118-
# Run the remote script with /bin/bash -lc so 'pipefail' and '<<<' work
119-
bundle exec bolt command run "CLASS=${CLASS} /bin/bash -lc '
135+
bundle exec bolt command run "/bin/bash -lc '
120136
set -euo pipefail
121-
CERT=\$(/opt/puppetlabs/bin/puppet config print hostcert)
122-
KEY=\$(/opt/puppetlabs/bin/puppet config print hostprivkey)
123-
CACERT=/etc/puppetlabs/puppet/ssl/certs/ca.pem
124-
# 1) Find PE Master group id
125-
GROUPS=\$(curl -s --cert \"\$CERT\" --key \"\$KEY\" --cacert \"\$CACERT\" https://localhost:4433/classifier-api/v1/groups)
126-
ID=\$(/opt/puppetlabs/puppet/bin/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\")
127-
echo \"PE Master group id: \$ID\"
128-
129-
# 2) Merge the class into the group classes and POST
130-
CURR=\$(curl -s --cert \"\$CERT\" --key \"\$KEY\" --cacert \"\$CACERT\" https://localhost:4433/classifier-api/v1/groups/\$ID)
131-
UPDATED=\$(/opt/puppetlabs/puppet/bin/ruby -rjson -e \"g=JSON.parse(STDIN.read); g[\\\"classes\\\"] ||= {}; g[\\\"classes\\\"][ENV[\\\"CLASS\\\"]] ||= {}; puts({\\\"id\\\"=>g[\\\"id\\\"],\\\"classes\\\"=>g[\\\"classes\\\"]}.to_json)\" <<< \"\$CURR\")
132-
133-
curl -s -X POST --cert \"\$CERT\" --key \"\$KEY\" --cacert \"\$CACERT\" \
134-
-H \"Content-Type: application/json\" \
135-
-d \"\$UPDATED\" \
136-
https://localhost:4433/classifier-api/v1/groups/\$ID >/dev/null
137+
export PATH=/opt/puppetlabs/bin:/opt/puppetlabs/puppet/bin:\$PATH
138+
139+
# Obtain/refresh an RBAC token (retry a few times while services settle)
140+
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
147+
done
148+
TOKEN=\$(/opt/puppetlabs/bin/puppet-access show || true)
149+
if [[ -z \"\$TOKEN\" ]]; then
150+
echo \"Failed to obtain RBAC token\" >&2
151+
exit 1
152+
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
137163
'" -i spec/fixtures/litmus_inventory.yaml --targets "$MASTER"
138164
165+
# 3) Converge master again so pe_repo materializes platform content
139166
- name: Converge PE master (stabilize services & pe_repo)
140167
env:
141168
BOLT_GEM: "1"
142169
shell: bash
143170
run: |
144171
MASTER='${{ steps.pe-master.outputs.master_uri }}'
145172
MASTER=${MASTER//\"/}; MASTER=${MASTER//\'/}
146-
if [[ -z "$MASTER" ]]; then echo "Empty master target"; exit 1; fi
147-
148-
for i in 1 2; do
149-
echo "Puppet agent run $i on master..."
150-
bundle exec bolt command run "puppet agent -t || true" \
151-
-i spec/fixtures/litmus_inventory.yaml \
152-
--targets "$MASTER"
153-
sleep 10
154-
done
173+
echo "puppet agent -t (post-classification) on $MASTER"
174+
bundle exec bolt command run "/opt/puppetlabs/bin/puppet agent -t || true" \
175+
-i spec/fixtures/litmus_inventory.yaml --targets "$MASTER"
155176
177+
# Verify the agent packages folder exists for your platform
156178
INPUT="${{ matrix.platform }}" # ubuntu-2204-lts
157179
OS="${INPUT%%-*}" # ubuntu
158180
VER="${INPUT#*-}" ; VER="${VER%-lts}" # 2204
159181
TAG="${OS}-${VER:0:2}.${VER:2:2}-amd64" # ubuntu-22.04-amd64
160-
161182
bundle exec bolt command run \
162-
"PEV=\$(facter -p pe_server_version 2>/dev/null || echo '2023.8.5'); \
183+
"/bin/bash -lc 'PEV=\$(facter -p pe_server_version 2>/dev/null || echo 2023.8.5); \
163184
test -d /opt/puppetlabs/server/data/packages/public/\$PEV/${TAG} || \
164-
(echo 'Missing pe_repo packages for ${TAG}'; ls -ld /opt/puppetlabs/server/data/packages/public/*; exit 1)" \
165-
-i spec/fixtures/litmus_inventory.yaml \
166-
--targets "$MASTER"
185+
(echo Missing pe_repo packages for ${TAG}; ls -ld /opt/puppetlabs/server/data/packages/public/*; exit 1)'" \
186+
-i spec/fixtures/litmus_inventory.yaml --targets "$MASTER"
167187
168188
- name: Install Agents
169189
env:

0 commit comments

Comments
 (0)