11name : " Integration Testing"
22
3- on :
3+ on :
44 pull_request :
55 branches :
66 - " main"
@@ -15,32 +15,32 @@ jobs:
1515 matrix : ${{ steps.get-matrix.outputs.matrix }}
1616
1717 steps :
18- - name : Checkout Source
19- uses : actions/checkout@v3
20- if : ${{ github.repository_owner == 'puppetlabs' }}
21-
22- - name : Activate Ruby 3.2
23- uses : ruby/setup-ruby@v1
24- if : ${{ github.repository_owner == 'puppetlabs' }}
25- with :
26- ruby-version : " 3.2"
27- bundler-cache : true
28-
29- - name : Print bundle environment
30- if : ${{ github.repository_owner == 'puppetlabs' }}
31- run : |
32- echo ::group::bundler environment
33- bundle env
34- echo ::endgroup::
35-
36- - name : Setup Integration Test Matrix
37- id : get-matrix
38- run : |
39- if [ '${{ github.repository_owner }}' == 'puppetlabs' ]; then
40- echo "matrix={'platform':['ubuntu-2204-lts'],'collection':['puppetcore8-nightly']}" >> $GITHUB_OUTPUT
41- else
42- echo "matrix={}" >> $GITHUB_OUTPUT
43- fi
18+ - name : Checkout Source
19+ if : ${{ github.repository_owner == 'puppetlabs' }}
20+ uses : actions/checkout@v3
21+
22+ - name : Activate Ruby 3.2
23+ if : ${{ github.repository_owner == 'puppetlabs' }}
24+ uses : ruby/setup-ruby@v1
25+ with :
26+ ruby-version : " 3.2"
27+ bundler-cache : true
28+
29+ - name : Print bundle environment
30+ if : ${{ github.repository_owner == 'puppetlabs' }}
31+ run : |
32+ echo ::group::bundler environment
33+ bundle env
34+ echo ::endgroup::
35+
36+ - name : Setup Integration Test Matrix
37+ id : get-matrix
38+ run : |
39+ if [ '${{ github.repository_owner }}' == 'puppetlabs' ]; then
40+ echo "matrix={'platform':['ubuntu-2204-lts'],'collection':['puppetcore8-nightly']}" >> $GITHUB_OUTPUT
41+ else
42+ echo "matrix={}" >> $GITHUB_OUTPUT
43+ fi
4444
4545 Integration :
4646 needs :
@@ -50,58 +50,247 @@ jobs:
5050 runs-on : ubuntu-24.04
5151 strategy :
5252 fail-fast : false
53- matrix : ${{fromJson(needs.setup_matrix.outputs.matrix)}}
54-
55- # env:
56- # PUPPET_GEM_VERSION: '~> 7.24'
57- # FACTER_GEM_VERSION: 'https://github.com/puppetlabs/facter#main' # why is this set?
53+ matrix : ${{ fromJson(needs.setup_matrix.outputs.matrix) }}
5854
5955 steps :
56+ - name : Checkout Source
57+ uses : actions/checkout@v3
58+
59+ - name : Activate Ruby 3.2
60+ uses : ruby/setup-ruby@v1
61+ with :
62+ ruby-version : " 3.2"
63+ bundler-cache : true
64+
65+ - name : Print bundle environment
66+ run : |
67+ echo ::group::bundler environment
68+ bundle env
69+ echo ::endgroup::
70+
71+ - name : Create the fixtures directory
72+ run : |
73+ bundle exec rake spec_prep
74+
75+ - name : Provision test environment
76+ env : { BOLT_GEM: "1" }
77+ run : |
78+ bundle exec bolt --modulepath spec/fixtures/modules plan run ntp::acceptance::provision_integration image=${{ matrix.platform }}
79+
80+ # --- Resolve the master target early (we’ll need it for waits and agent installs)
81+ - name : Resolve PE master target
82+ id : pe-master
83+ run : |
84+ ruby -ryaml -e '
85+ inv = YAML.load_file("spec/fixtures/litmus_inventory.yaml")
86+ targets = inv["groups"].flat_map{|g| g["targets"] rescue []}.compact
87+ t = targets.find{|x| x.dig("vars","role")=="ntpserver"}
88+ abort "No ntpserver target found in inventory" unless t
89+ puts "master_uri=#{t["uri"]}"
90+ ' >> $GITHUB_OUTPUT
91+
92+ - name : Wait for SSH on PE master
93+ env : { BOLT_GEM: "1" }
94+ shell : bash
95+ run : |
96+ MASTER='${{ steps.pe-master.outputs.master_uri }}'
97+ MASTER=${MASTER//\"/}; MASTER=${MASTER//\'/}
98+ echo "Waiting for SSH on $MASTER ..."
99+ for i in {1..48}; do
100+ if bundle exec bolt command run "echo online" \
101+ -i spec/fixtures/litmus_inventory.yaml \
102+ --targets "$MASTER" \
103+ --connect-timeout 20 >/dev/null 2>&1; then
104+ echo "SSH is up on $MASTER"
105+ exit 0
106+ fi
107+ sleep 10
108+ done
109+ echo "Timed out waiting for SSH on $MASTER" >&2
110+ bundle exec bolt command run "echo online" \
111+ -i spec/fixtures/litmus_inventory.yaml \
112+ --targets "$MASTER" \
113+ --connect-timeout 20 || true
114+ exit 1
115+
116+ - name : Install PE
117+ env : { BOLT_GEM: "1" }
118+ run : |
119+ bundle exec bolt --modulepath spec/fixtures/modules \
120+ -i ./spec/fixtures/litmus_inventory.yaml \
121+ plan run ntp::acceptance::pe_server
122+
123+ # --- Warm up master services (twice is usually enough)
124+ - name : Warm up PE master (first convergence)
125+ env : { BOLT_GEM: "1" }
126+ shell : bash
127+ run : |
128+ MASTER='${{ steps.pe-master.outputs.master_uri }}'
129+ MASTER=${MASTER//\"/}; MASTER=${MASTER//\'/}
130+ for i in 1 2; do
131+ echo "puppet agent -t (warm-up run $i) on $MASTER"
132+ bundle exec bolt command run "/opt/puppetlabs/bin/puppet agent -t || true" \
133+ -i spec/fixtures/litmus_inventory.yaml --targets "$MASTER"
134+ sleep 10
135+ done
136+
137+ # --- Install agents from the primary’s /packages/current install script
138+ - name : Install Agents (official install.bash)
139+ env : { BOLT_GEM: "1" }
140+ shell : bash
141+ run : |
142+ MASTER='${{ steps.pe-master.outputs.master_uri }}'
143+ MASTER=${MASTER//\"/}; MASTER=${MASTER//\'/}
144+ AGENTS=$(ruby -ryaml -e '
145+ inv = YAML.load_file("spec/fixtures/litmus_inventory.yaml")
146+ puts inv.fetch("groups",[]).flat_map{|g| g.fetch("targets",[])}.
147+ select{|t| t.dig("vars","role")=="ntpclient"}.
148+ map{|t| t["uri"]}.join(",")
149+ ')
150+ if [[ -z "$AGENTS" ]]; then echo "No ntpclient targets found"; exit 1; fi
151+ echo "Agent targets: $AGENTS"
152+
153+ bundle exec bolt command run \
154+ "/bin/bash -lc 'curl -ks https://${MASTER}:8140/packages/current/install.bash | bash'" \
155+ -i spec/fixtures/litmus_inventory.yaml \
156+ --targets "$AGENTS" \
157+ --run-as root
158+
159+ - name : Sign agent certificates & converge agents
160+ env : { BOLT_GEM: "1" }
161+ shell : bash
162+ run : |
163+ MASTER='${{ steps.pe-master.outputs.master_uri }}'
164+ MASTER=${MASTER//\"/}; MASTER=${MASTER//\'/}
165+ # Sign pending CSRs on primary
166+ bundle exec bolt command run \
167+ "/bin/bash -lc '/opt/puppetlabs/bin/puppetserver ca list --all || true; /opt/puppetlabs/bin/puppetserver ca sign --all || true'" \
168+ -i spec/fixtures/litmus_inventory.yaml \
169+ --targets "$MASTER"
170+
171+ # Run one agent converge on all clients
172+ AGENTS=$(ruby -ryaml -e '
173+ inv = YAML.load_file("spec/fixtures/litmus_inventory.yaml")
174+ puts inv.fetch("groups",[]).flat_map{|g| g.fetch("targets",[])}.
175+ select{|t| t.dig("vars","role")=="ntpclient"}.
176+ map{|t| t["uri"]}.join(",")
177+ ')
178+ bundle exec bolt command run "/opt/puppetlabs/bin/puppet agent -t || true" \
179+ -i spec/fixtures/litmus_inventory.yaml \
180+ --targets "$AGENTS"
181+
182+ # --- Build the module (without rake), upload & install via absolute /opt/puppetlabs/bin/puppet
183+ - name : Build, upload & install module on all targets
184+ env : { BOLT_GEM: "1" }
185+ shell : bash
186+ run : |
187+ set -Eeuo pipefail
188+ set -o pipefail
189+
190+ # --- Determine module version (fallback to 0.0.0)
191+ VER="$(ruby -rjson -e 'puts JSON.parse(File.read("metadata.json"))["version"]' 2>/dev/null || true)"
192+ [[ -n "${VER:-}" ]] || VER="0.0.0"
193+
194+ # --- Build module tarball
195+ mkdir -p pkg stage && rm -rf stage/puppetlabs-ntp
196+ mkdir -p stage/puppetlabs-ntp
197+
198+ shopt -s dotglob
199+ for item in *; do
200+ case "$item" in
201+ pkg|stage|.git|.github|vendor|.bundle|spec/fixtures) continue ;;
202+ *) cp -a "$item" stage/puppetlabs-ntp/ ;;
203+ esac
204+ done
205+ shopt -u dotglob
206+
207+ TAR="pkg/puppetlabs-ntp-${VER}.tar.gz"
208+ tar -C stage -czf "${TAR}" puppetlabs-ntp
209+ echo "Built module archive: ${TAR}"
210+
211+ # --- Collect all target URIs (master + clients) from inventory
212+ ALL="$(ruby -ryaml -e '
213+ inv = YAML.load_file("spec/fixtures/litmus_inventory.yaml")
214+ puts inv.fetch("groups",[]).flat_map{|g| g.fetch("targets",[]) }.map{|t| t["uri"]}.join(",")
215+ ')"
216+ [[ -n "$ALL" ]] || { echo "No targets found in inventory"; exit 3; }
217+
218+ # --- Resolve and sanitize master URI for package installs
219+ MASTER='${{ steps.pe-master.outputs.master_uri }}'
220+ MASTER=${MASTER//\"/}; MASTER=${MASTER//\'/}
221+
222+ echo "Ensuring puppet CLI present (best-effort) on: $ALL"
223+ bundle exec bolt command run "/bin/bash -lc '
224+ set -Eeuo pipefail; set -o pipefail
225+ if ! command -v puppet >/dev/null 2>&1 && [ ! -x /opt/puppetlabs/bin/puppet ]; then
226+ echo \"Installing puppet-agent from https://${MASTER}:8140...\" >&2
227+ success=0
228+ for i in 1 2 3; do
229+ if curl -fsSLk https://${MASTER}:8140/packages/current/install.bash | bash; then
230+ success=1; break
231+ fi
232+ echo \"Install attempt $i failed; retrying...\" >&2
233+ sleep $((i*5))
234+ done
235+ if [ $success -eq 0 ]; then
236+ echo \"WARN: puppet-agent install failed; will continue with tarball fallback.\" >&2
237+ fi
238+ fi
239+ # convenience symlinks if CLI exists
240+ if [ -x /opt/puppetlabs/bin/puppet ]; then
241+ ln -sf /opt/puppetlabs/bin/puppet /usr/bin/puppet || true
242+ ln -sf /opt/puppetlabs/bin/puppet /usr/local/bin/puppet || true
243+ fi
244+ exit 0
245+ '" \
246+ -i spec/fixtures/litmus_inventory.yaml \
247+ --targets "$ALL" \
248+ --run-as root
249+
250+ echo "Uploading module archive to targets..."
251+ bundle exec bolt file upload "${TAR}" /root/ntp.tgz \
252+ -i spec/fixtures/litmus_inventory.yaml \
253+ --targets "$ALL"
254+
255+ echo "Installing module on targets (uses puppet if present, falls back to unpack)..."
256+ bundle exec bolt command run "/bin/bash -lc '
257+ set -Eeuo pipefail; set -o pipefail
258+ puppet_bin=\$(command -v puppet || echo /opt/puppetlabs/bin/puppet)
259+ if [ -x \"\$puppet_bin\" ]; then
260+ \"\$puppet_bin\" module install /root/ntp.tgz --force --ignore-dependencies
261+ else
262+ echo \"WARN: puppet CLI not found; unpacking module into codedir\" >&2
263+ mkdir -p /etc/puppetlabs/code/environments/production/modules
264+ tar -xzf /root/ntp.tgz -C /etc/puppetlabs/code/environments/production/modules
265+ fi
266+ '" \
267+ -i spec/fixtures/litmus_inventory.yaml \
268+ --targets "$ALL" \
269+ --run-as root
270+
271+ echo "Verifying module presence..."
272+ bundle exec bolt command run "/bin/bash -lc '
273+ set -Eeuo pipefail; set -o pipefail
274+ if command -v puppet >/dev/null 2>&1 || [ -x /opt/puppetlabs/bin/puppet ]; then
275+ puppet_bin=\$(command -v puppet || echo /opt/puppetlabs/bin/puppet)
276+ \"\$puppet_bin\" module list --tree | egrep -i \"(^| )ntp( |$)\" || true
277+ else
278+ if test -d /etc/puppetlabs/code/environments/production/modules/puppetlabs-ntp; then
279+ echo \"puppetlabs-ntp present (unpacked)\"
280+ else
281+ echo \"WARN: ntp module not found\"
282+ fi
283+ fi
284+ '" \
285+ -i spec/fixtures/litmus_inventory.yaml \
286+ --targets "$ALL" \
287+ --run-as root || true
288+
289+ - name : Run integration tests
290+ run : |
291+ bundle exec rake ntp:integration
60292
61- - name : Checkout Source
62- uses : actions/checkout@v3
63-
64- - name : Activate Ruby 3.2
65- uses : ruby/setup-ruby@v1
66- with :
67- ruby-version : " 3.2"
68- bundler-cache : true
69-
70- - name : Print bundle environment
71- run : |
72- echo ::group::bundler environment
73- bundle env
74- echo ::endgroup::
75-
76- - name : Create the fixtures directory
77- run : |
78- bundle exec rake spec_prep
79-
80- - name : Provision test environment
81- run : |
82- bundle exec bolt --modulepath spec/fixtures/modules plan run ntp::acceptance::provision_integration image=${{ matrix.platform }}
83- # Redact password
84- FILE='spec/fixtures/litmus_inventory.yaml'
85- sed -e 's/password: .*/password: "[redacted]"/' < $FILE || true
86-
87- - name : Install PE
88- run : |
89- bundle exec bolt --modulepath spec/fixtures/modules -i ./spec/fixtures/litmus_inventory.yaml plan run ntp::acceptance::pe_server
90-
91- - name : Install Agents
92- run : |
93- bundle exec bolt --modulepath spec/fixtures/modules -i ./spec/fixtures/litmus_inventory.yaml plan run ntp::acceptance::pe_agent
94-
95- - name : Install module
96- run : |
97- bundle exec rake 'litmus:install_module'
98-
99- - name : Run integration tests
100- run : |
101- bundle exec rake ntp:integration
102-
103- - name : Remove test environment
104- if : ${{ always() }}
105- continue-on-error : true
106- run : |
107- bundle exec rake 'litmus:tear_down'
293+ - name : Remove test environment
294+ if : ${{ always() }}
295+ continue-on-error : true
296+ run : |
0 commit comments