forked from puppetlabs/cat-github-actions
-
Notifications
You must be signed in to change notification settings - Fork 0
427 lines (373 loc) · 17.3 KB
/
module_acceptance_prep.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
# This is a generic workflow for Puppet module acceptance operations.
name: "Module Acceptance Prep"
on:
workflow_call:
inputs:
runs_on:
description: "The operating system used for the runner."
required: false
default: "ubuntu-latest"
type: "string"
flags:
description: "Additional flags to pass to matrix_from_metadata_v2."
required: false
default: ''
type: "string"
kernel_modules:
description: "Volume map host kernel /lib/modules into docker container"
default: true
type: boolean
disable_apparmor:
description: "Disable and stop apparmor"
default: false
type: boolean
continuewithownsetupsteps:
description: "Running Extra Setup Steps module_acceptance"
required: false
default: true
type: boolean
continueintooriginalsteps:
description: "Continue the run into the Steps from the original module_acceptance"
required: false
default: false
type: boolean
# Proposed Steps
continueintoproposedsteps:
description: "Continue the run into the Steps from the proposed module_acceptance"
required: false
default: false
type: boolean
provision_environment__task:
description: "Rake Task to Provision the Environment"
required: false
default: ''
type: "string"
install_agent__task:
description: "Rake Task to install the Agent"
required: false
default: ''
type: "string"
install_module__task:
description: "Rake Task to install the Modules"
required: false
default: ''
type: "string"
acceptance__task:
description: "Rake Task to Run the Acceptance Tests"
required: false
default: ''
type: "string"
tear_down__task:
description: "Rake Task to Run the Tear Down the test environments"
required: false
default: ''
type: "string"
matrix_from_metadata:
description: 'Commands to run to get the test matrix'
default: 'matrix_from_metadata_v2'
type: "string"
# Start of the Debugging Parameters
prepcommand1:
description: "Additional PrepCommand to run as a preparation Part 1"
required: false
default: 'echo'
type: "string"
prepcommand2:
description: "Additional PrepCommand to run as a preparation Part 2"
required: false
default: 'echo'
type: "string"
command:
description: "Additional Command to run as a preparation/test"
required: false
default: 'echo'
type: "string"
postcommand:
description: "Additional Command to run as cleanup"
required: false
default: 'echo'
type: "string"
preinstallpecommands:
description: "Additional Commands to install or config PE, running before the installation"
required: false
default: 'echo Before Install PE ;'
type: "string"
installpecommands:
description: "Additional Commands to install or config PE, running after the installation"
required: false
default: 'echo Install PE done ;'
type: "string"
deploy_petargetinv:
description: "Path to Inventory to use to run deploy_pe for PE installation. It must contain the target deploy_petarget."
required: false
default: 'inventory.yaml'
type: "string"
deploy_petarget:
description: "Target to run run deploy_pe for PE installation"
required: false
default: 'localhost'
type: "string"
deploy_peversion:
description: "P.E. version to install for deploy_pe"
required: false
default: '-'
type: "string"
peadm_peversion:
description: "P.E. version to install for peadm"
required: false
default: '-'
type: "string"
opensourcepuppetversion:
description: "Open Source Puppet version to install, Default as empty to install Puppet Enterprise instead, and set 'L' for latest "
required: false
default: ''
type: "string"
jobs:
setup_matrix:
name: "Setup Test Matrix"
runs-on: ${{ inputs.runs_on }}
outputs:
acceptance_matrix: ${{ steps.get-matrix.outputs.spec_matrix }}
acceptance__matrix: ${{ steps.get-matrix.outputs.matrix }}
ruby_version: ${{ steps.get-puppet_ruby_version.outputs.ruby_version }}
puppet_version: ${{ steps.get-puppet_ruby_version.outputs.puppet_version }}
env:
BUNDLE_WITHOUT: release_prep
steps:
- name: "Checkout"
uses: "actions/checkout@v4"
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: "Setup ruby"
uses: "ruby/setup-ruby@v1"
with:
ruby-version: "2.7"
bundler-cache: true
- name: "Bundle environment"
run: |
echo ::group::bundler environment
bundle env
echo ::endgroup::
- name: Setup Test Matrix
id: get-matrix
run: |
bundle exec ${{ inputs.matrix_from_metadata }} ${{ inputs.flags }}
- name: Setup Ruby Version and Setup Puppet Version
id: get-puppet_ruby_version
run: |
echo ${{ toJSON(steps.get-matrix.outputs.spec_matrix ) }} | jq -r '.include | .[0] | to_entries[] | "\(.key)=\(.value)"' >> $GITHUB_OUTPUT
acceptance:
name: "Acceptance tests (${{matrix.platforms.label}}, ${{matrix.collection}}) - ruby: ${{needs.setup_matrix.outputs.ruby_version}} puppet: ${{needs.setup_matrix.outputs.puppet_version}} "
needs: "setup_matrix"
runs-on: ${{ inputs.runs_on }}
timeout-minutes: 180
strategy:
fail-fast: false
matrix: ${{ fromJson( needs.setup_matrix.outputs.acceptance__matrix ) }}
# matrix: ${{ fromJson( needs.setup_matrix.outputs.acceptance_matrix ) }}
# spec_matrix: ${{ fromJson( needs.setup_matrix.outputs.acceptance__matrix ) }}
env:
BUNDLE_WITHOUT: release_prep
PUPPET_GEM_VERSION: ${{needs.setup_matrix.outputs.puppet_version}}
FACTER_GEM_VERSION: 'https://github.com/puppetlabs/facter#main' # why is this set?
steps:
- name: "Checkout"
uses: "actions/checkout@v4"
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: "Disable Apparmor"
if: ${{ inputs.disable_apparmor }}
run: |
if command -v apparmor_parser >/dev/null ; then
sudo find /etc/apparmor.d/ -maxdepth 1 -type f -exec ln -sf {} /etc/apparmor.d/disable/ \;
sudo apparmor_parser -R /etc/apparmor.d/disable/* || true
sudo systemctl disable apparmor
sudo systemctl stop apparmor
fi
- name: "Setup ruby"
uses: "ruby/setup-ruby@v1"
with:
ruby-version: ${{needs.setup_matrix.outputs.ruby_version}}
bundler-cache: true
- name: "Bundle environment"
run: |
echo ::group::bundler environment
bundle env
echo ::endgroup::
- name: modify sudo settings
if: ${{ inputs.continuewithownsetupsteps }}
run: |
sudo sed -i 's/Defaults env_reset//' /etc/sudoers
- name: Create the fixtures directory
if: ${{ inputs.continuewithownsetupsteps }}
run: |
bundle exec rake spec_prep
- name: install actual bolt
if: ${{ inputs.continuewithownsetupsteps }}
run: |
wget https://apt.puppet.com/puppet-tools-release-jammy.deb
sudo -E dpkg -i puppet-tools-release-jammy.deb
sudo -E apt-get update
sudo -E apt-get -y install puppet-bolt
sudo -E apt-get -y install curl || sudo -E yum install -y curl || apt-get -y install curl || yum install -y curl
sudo -E apt-get -y install cron
sudo -E /usr/local/bin/bolt --modulepath spec/fixtures/modules plan show
- name: install bolt modules
if: ${{ inputs.continuewithownsetupsteps }}
run: |
sudo -E mkdir -p spec/fixtures/modules
sudo -E echo ln -s spec/fixtures/modules .modules
sudo -E /usr/local/bin/bolt project init my_project --modules jarretlavallee-deploy_pe,puppetlabs-peadm,aursu-puppet
sudo -E /usr/local/bin/bolt --modulepath spec/fixtures/modules module add jarretlavallee-deploy_pe
sudo -E /usr/local/bin/bolt --modulepath spec/fixtures/modules module add puppetlabs-peadm
sudo -E chmod a+rw ./inventory.yaml
- name: "Run Commands to Check or Cover Pre- PE Installation aka preinstallpecommands"
if: ${{ inputs.continuewithownsetupsteps }}
run: |
${{ inputs.preinstallpecommands }}
- name: install pe or opensource puppet
if: ${{ inputs.continuewithownsetupsteps && ( inputs.deploy_peversion != '-' || inputs.opensourcepuppetversion != '' ) }}
run: |
echo "==deploy_peversion=${{ inputs.deploy_peversion }}" ;
echo "==opensourcepuppetversion=${{ inputs.opensourcepuppetversion }}" ;
if [ -z "${{ inputs.opensourcepuppetversion }}" ] ; then
if [ ! "${{ inputs.deploy_petargetinv }}" = "inventory.yaml" -a -e "${{ inputs.deploy_petargetinv }}" ] ; then
cat "${{ inputs.deploy_petargetinv }}" > inventory.yaml || echo "Same files cannot update." ;
elif [ -z "`grep -v '^[ ]*$' ${{ inputs.deploy_petargetinv }}`" ] ; then
echo -e 'groups:\n - name: pe\n targets:\n - uri: localhost\n vars:\n roles:\n - pe' > inventory.yaml ;
fi ;
[ ! -e ./spec/fixtures/litmus_inventory.yaml ] || grep -H -n -v -E 'AALINEAANUMBER' ./spec/fixtures/litmus_inventory.yaml ;
sudo -E /usr/local/bin/bolt --modulepath spec/fixtures/modules plan show
sudo -E /usr/local/bin/bolt --modulepath spec/fixtures/modules plan run facts targets=${{ inputs.deploy_petarget }}
[ "-" = "${{ inputs.deploy_peversion }}" ] || sudo -E /usr/local/bin/bolt --modulepath spec/fixtures/modules plan run deploy_pe::provision_master targets=${{ inputs.deploy_petarget }} version=${{ inputs.deploy_peversion }} || echo "==Install PE deploy_pe failed==" ;
else
curl -q "https://raw.githubusercontent.com/sooyean-hoo/pe_curl_requests/feature/SYInstallerEnhance/installer/download_pe_tarball.sh" > /tmp/download_pe_tarball.sh ;
export opensourcepuppetversion="${{ inputs.opensourcepuppetversion }}" ;
source /tmp/download_pe_tarball.sh > /tmp/ops.log || echo ;
tail -10 /tmp/ops.log | grep -H -n -v -E 'AALINEAANUMBER' ;
pkg2installOSpuppet=$( cat /tmp/ops.log | grep '====OPENSOURCEPUPPET=pkgurl=' | sed -E 's/====OPENSOURCEPUPPET=pkgurl=//' ) ;
echo "Installing..... ${pkg2installOSpuppet} " ;
installPkg ${pkg2installOSpuppet} || echo ;
upgradePkg || echo ;
for p in puppetserver puppet-agent ; do
installPkg $p || installPkg $p --nobest --skip-broken || echo ;
done ;
puppet --help > /dev/null 2> /dev/null || {
tarfile=`ls -1 ./puppet*tar.gz | head -n 1` ;
tar -zxvf $tarfile ;
cd ${tarfile/.tar.gz/} ;
onepkg=`find -iname 'puppet-agent*' | grep -E 'rpm|deb'| head -1 ` ;
cd `dirname ${onepkg}` ;
ext=${onepkg/*./}
sudocmd=`which sudo` || echo a ;
if [ "$ext" = "rpm" ] ; then
${sudocmd} rpm -i ./pe-puppetserver-* ./puppet-agent-* ./pe-puppet-enterprise-release-* ./pe-java*.rpm ./pe-bouncy-castle-jars-* ;
else
installPkg net-tools ;
${sudocmd} dpkg -i ./pe-puppetserver* ./puppet-agent* ./pe-puppet-enterprise-release* ./pe-java* ./pe-bouncy-castle-jars* ;
installPkg puppet-agent puppetmaster ;
fi;
} || echo "Minimum Puppet Installation using Tar Failed" ;
fi ;
- name: "Run Commands to Check or Cover Post PE Installation aka installpecommands"
if: ${{ inputs.continuewithownsetupsteps }}
run: |
${{ inputs.installpecommands }}
- name: "Run prepCommand Part 1 aka prepcommand1"
if: ${{ inputs.continuewithownsetupsteps }}
run: |
${{ inputs.prepcommand1 }}
- name: "Run prepCommand Part 2 aka prepcommand2"
if: ${{ inputs.continuewithownsetupsteps }}
run: |
${{ inputs.prepcommand2 }}
- name: "Run Command aka command"
if: ${{ inputs.continuewithownsetupsteps }}
run: |
${{ inputs.command }}
- name: "Run Commands after the command aka postcommand"
if: ${{ inputs.continuewithownsetupsteps }}
run: |
${{ inputs.postcommand }}
# Proposed Steps from the module_acceptance
- name: "Provision environment"
if: ${{ inputs.continueintoproposedsteps }}
run: |
if [ "${{ inputs.provision_environment__task }}" = "litmus:provision" ] ; then
if [[ "${{ inputs.kernel_modules }}" == "true" ]] && [[ "${{matrix.platforms.provider}}" =~ docker* ]] ; then
DOCKER_RUN_OPTS="docker_run_opts: {'--volume': '/lib/modules/$(uname -r):/lib/modules/$(uname -r)'}"
else
DOCKER_RUN_OPTS=''
fi
bundle exec rake "litmus:provision[${{matrix.platforms.provider}},${{ matrix.platforms.image }},$DOCKER_RUN_OPTS]"
# Redact password
FILE='spec/fixtures/litmus_inventory.yaml'
sed -e 's/password: .*/password: "[redacted]"/' < $FILE || true
else
if [[ "${{ inputs.kernel_modules }}" == "true" ]] && [[ "${{matrix.platforms.provider}}" =~ docker* ]] ; then
DOCKER_RUN_OPTS="docker_run_opts: {'--volume': '/lib/modules/$(uname -r):/lib/modules/$(uname -r)'}"
else
DOCKER_RUN_OPTS=''
fi
if [ ! -z "${{ inputs.provision_environment__task }}" ] ; then
echo ===cat ${GITHUB_OUTPUT} ; ls -l ${GITHUB_OUTPUT} ; cat ${GITHUB_OUTPUT} || echo "No file ${GITHUB_OUTPUT}";
source ${GITHUB_OUTPUT} ; echo "from file: ${matrix}" ; echo "inGitHub: ${{matrix}}" ;
echo "spec_matrix: ${{ needs.setup_matrix.outputs.acceptance_matrix }}" ;
echo "matrix: ${{ needs.setup_matrix.outputs.acceptance__matrix }}" ;
echo "============================";
platformsprovider="${{matrix.platforms.provider}}"
platformsimage="${{ matrix.platforms.image }}"
bundle exec rake "${{ inputs.provision_environment__task }}[${platformsprovider:-},${platformsimage:-},$DOCKER_RUN_OPTS]" ;
fi
fi;
- name: "Install Puppet agent"
if: ${{ inputs.continueintoproposedsteps }}
run: |
[ -z "${{ inputs.install_agent__task }}" ] || bundle exec rake '${{ inputs.install_agent__task }}[${{ matrix.collection }}]'
- name: "Install module"
if: ${{ inputs.continueintoproposedsteps }}
run: |
[ -z "${{ inputs.install_module__task }}" ] || bundle exec rake '${{ inputs.install_module__task }}'
- name: "Run acceptance tests"
if: ${{ inputs.continueintoproposedsteps }}
run: |
[ -z "${{ inputs.acceptance__task }}" ] || bundle exec rake '${{ inputs.acceptance__task }}'
- name: "Remove test environment"
if: ${{ inputs.continueintoproposedsteps }}
continue-on-error: true
run: |
if [[ -f spec/fixtures/litmus_inventory.yaml ]]; then
[ -z "${{ inputs.tear_down__task }}" ] || bundle exec rake '${{ inputs.tear_down__task }}'
fi
# Same Steps from the module_acceptance
- name: "Provision environment"
if: ${{ inputs.continueintooriginalsteps }}
run: |
if [[ "${{ inputs.kernel_modules }}" == "true" ]] && [[ "${{matrix.platforms.provider}}" =~ docker* ]] ; then
DOCKER_RUN_OPTS="docker_run_opts: {'--volume': '/lib/modules/$(uname -r):/lib/modules/$(uname -r)'}"
else
DOCKER_RUN_OPTS=''
fi
bundle exec rake "litmus:provision[${{matrix.platforms.provider}},${{ matrix.platforms.image }},$DOCKER_RUN_OPTS]"
# Redact password
FILE='spec/fixtures/litmus_inventory.yaml'
sed -e 's/password: .*/password: "[redacted]"/' < $FILE || true
- name: "Install Puppet agent"
if: ${{ inputs.continueintooriginalsteps }}
run: |
bundle exec rake 'litmus:install_agent[${{ matrix.collection }}]'
- name: "Install module"
if: ${{ inputs.continueintooriginalsteps }}
run: |
bundle exec rake 'litmus:install_module'
- name: "Run acceptance tests"
if: ${{ inputs.continueintooriginalsteps }}
run: |
bundle exec rake 'litmus:acceptance:parallel'
- name: "Remove test environment"
if: ${{ inputs.continueintooriginalsteps }}
continue-on-error: true
run: |
if [[ -f spec/fixtures/litmus_inventory.yaml ]]; then
bundle exec rake 'litmus:tear_down'
fi