Skip to content

Commit 4596a6c

Browse files
authored
(PE-39307) Legacy compilers support smoke tests (#505)
* feat(workflow): add GitHub Actions workflow for converting compilers to legacy - Trigger on pull requests affecting specific paths and on manual dispatch - Provision and set up a test cluster using Bolt and Rake - Install Puppet Enterprise on the test cluster - Convert one compiler to legacy and verify the conversion - Tear down the test cluster after the workflow completes * feat(workflow): add GitHub Actions workflow for upgrading PE with legacy compilers - Trigger on pull requests affecting specific paths and on manual dispatch - Provision and set up a test cluster using Bolt and Rake - Install Puppet Enterprise with legacy compilers on the test cluster - Verify the configuration of legacy compilers - Upgrade Puppet Enterprise and verify the configuration post-upgrade - Tear down the test cluster after the workflow completes * refactor(peadm_spec): improve error handling in add_inventory_hostnames plan - Replace parallelize with map for better readability - Add error handling for hostname command execution - Add error handling for inventory file update command * fix(workflow): correct legacy compiler selection in test-legacy-upgrade.yaml - Replace `head -n 2` with `sed -n 2p` for accurate selection of the second compiler * chore(workflows): remove push trigger from legacy workflows The push trigger has been removed from the test-legacy-compilers and test-legacy-upgrade workflows. This change ensures that these workflows are only triggered manually via workflow_dispatch. fix(workflow): correct conditional syntax in test-legacy-upgrade.yaml - Replace incorrect `AND` with `&&` for accurate conditional checks
1 parent 39d5f7d commit 4596a6c

File tree

3 files changed

+375
-5
lines changed

3 files changed

+375
-5
lines changed
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
---
2+
name: Convert compiler to legacy
3+
on:
4+
pull_request:
5+
paths:
6+
- .github/workflows/**/*
7+
- spec/**/*
8+
- lib/**/*
9+
- tasks/**/*
10+
- functions/**/*
11+
- types/**/*
12+
- plans/**/*
13+
- hiera/**/*
14+
- manifests/**/*
15+
- templates/**/*
16+
- files/**/*
17+
- metadata.json
18+
- Rakefile
19+
- Gemfile
20+
- provision.yaml
21+
- .rspec
22+
- .rubocop.yml
23+
- .puppet-lint.rc
24+
- .fixtures.yml
25+
branches: [main]
26+
workflow_dispatch:
27+
inputs:
28+
ssh-debugging:
29+
description: Boolean; whether or not to pause for ssh debugging
30+
required: true
31+
default: 'false'
32+
jobs:
33+
convert_compiler:
34+
name: Convert compilers to legacy
35+
runs-on: ubuntu-20.04
36+
env:
37+
BOLT_GEM: true
38+
BOLT_DISABLE_ANALYTICS: true
39+
LANG: en_US.UTF-8
40+
steps:
41+
- name: Start SSH session
42+
if: ${{ github.event.inputs.ssh-debugging == 'true' }}
43+
uses: luchihoratiu/debug-via-ssh@main
44+
with:
45+
NGROK_AUTH_TOKEN: ${{ secrets.NGROK_AUTH_TOKEN }}
46+
SSH_PASS: ${{ secrets.SSH_PASS }}
47+
- name: Checkout Source
48+
uses: actions/checkout@v2
49+
- name: Activate Ruby 2.7
50+
uses: ruby/setup-ruby@v1
51+
with:
52+
ruby-version: '2.7'
53+
bundler-cache: true
54+
- name: Print bundle environment
55+
if: ${{ github.repository_owner == 'puppetlabs' }}
56+
run: |
57+
echo ::group::info:bundler
58+
bundle env
59+
echo ::endgroup::
60+
- name: Provision test cluster
61+
timeout-minutes: 15
62+
run: |
63+
echo ::group::prepare
64+
mkdir -p $HOME/.ssh
65+
echo 'Host *' > $HOME/.ssh/config
66+
echo ' ServerAliveInterval 150' >> $HOME/.ssh/config
67+
echo ' ServerAliveCountMax 2' >> $HOME/.ssh/config
68+
bundle exec rake spec_prep
69+
echo ::endgroup::
70+
echo ::group::provision
71+
bundle exec bolt plan run peadm_spec::provision_test_cluster \
72+
--modulepath spec/fixtures/modules \
73+
provider=provision_service \
74+
image=almalinux-cloud/almalinux-8 \
75+
architecture=large-with-dr
76+
echo ::endgroup::
77+
echo ::group::certnames
78+
bundle exec bolt plan run peadm_spec::add_inventory_hostnames \
79+
--inventory spec/fixtures/litmus_inventory.yaml \
80+
--modulepath spec/fixtures/modules \
81+
--no-host-key-check \
82+
inventory_file=spec/fixtures/litmus_inventory.yaml
83+
echo ::endgroup::
84+
echo ::group::info:request
85+
cat request.json || true; echo
86+
echo ::endgroup::
87+
echo ::group::info:inventory
88+
sed -e 's/password: .*/password: "[redacted]"/' < spec/fixtures/litmus_inventory.yaml || true
89+
echo ::endgroup::
90+
- name: Set up yq
91+
uses: frenck/action-setup-yq@v1
92+
with:
93+
version: v4.30.5
94+
- name: Install PE on test cluster
95+
timeout-minutes: 120
96+
run: |
97+
bundle exec bolt plan run peadm_spec::install_test_cluster \
98+
--inventoryfile spec/fixtures/litmus_inventory.yaml \
99+
--modulepath spec/fixtures/modules \
100+
architecture=large-with-dr \
101+
console_password=${{ secrets.CONSOLE_PASSWORD }} \
102+
version=2023.7.0
103+
- name: Wait as long as the file ${HOME}/pause file is present
104+
if: ${{ always() && github.event.inputs.ssh-debugging == 'true' }}
105+
run: |
106+
while [ -f "${HOME}/pause" ] ; do
107+
echo "${HOME}/pause present, sleeping for 60 seconds..."
108+
sleep 60
109+
done
110+
echo "${HOME}/pause absent, continuing workflow."
111+
- name: Convert one compiler to legacy
112+
timeout-minutes: 120
113+
run: |
114+
primary=$(yq '.groups[].targets[] | select(.vars.role == "primary") | .name' spec/fixtures/litmus_inventory.yaml)
115+
compiler=$(yq '.groups[].targets[] | select(.vars.role == "compiler") | .name' spec/fixtures/litmus_inventory.yaml | head -n 1)
116+
echo "primary: $primary"
117+
echo "compiler: $compiler"
118+
echo ::group::convert_compiler_to_legacy
119+
bundle exec bolt plan run peadm::convert_compiler_to_legacy \
120+
--inventoryfile spec/fixtures/litmus_inventory.yaml \
121+
--modulepath spec/fixtures/modules \
122+
--no-host-key-check \
123+
primary_host=$primary \
124+
legacy_hosts=$compiler
125+
echo ::endgroup::
126+
- name: Check if compiler is converted
127+
timeout-minutes: 120
128+
run: |
129+
echo ::group::inventory
130+
sed -e 's/password: .*/password: "[redacted]"/' < spec/fixtures/litmus_inventory.yaml || true
131+
echo ::endgroup::
132+
echo ::group::get_peadm_config
133+
primary=$(yq '.groups[].targets[] | select(.vars.role == "primary") | .name' spec/fixtures/litmus_inventory.yaml)
134+
compiler=$(yq '.groups[].targets[] | select(.vars.role == "compiler") | .name' spec/fixtures/litmus_inventory.yaml | head -n 1)
135+
bundle exec bolt task run peadm::get_peadm_config \
136+
--targets $primary \
137+
--inventoryfile spec/fixtures/litmus_inventory.yaml \
138+
--modulepath spec/fixtures/modules \
139+
--no-host-key-check \
140+
--format json > peadm_config.json
141+
cat peadm_config.json
142+
echo ::endgroup::
143+
echo ::group::smoke_test
144+
legacy_compiler=$(yq '.items[0].value.params.legacy_compilers[0]' peadm_config.json)
145+
if [ "$compiler" != "$legacy_compiler" ]; then
146+
echo "Compiler conversion failed, expected $compiler, got $legacy_compiler"
147+
exit 1
148+
fi
149+
echo ::endgroup::
150+
- name: Tear down test cluster
151+
if: ${{ always() }}
152+
continue-on-error: true
153+
run: |-
154+
if [ -f spec/fixtures/litmus_inventory.yaml ]; then
155+
echo ::group::tear_down
156+
bundle exec rake 'litmus:tear_down'
157+
echo ::endgroup::
158+
echo ::group::info:request
159+
cat request.json || true; echo
160+
echo ::endgroup::
161+
fi
Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
---
2+
name: Upgrade PE with legacy compilers
3+
on:
4+
pull_request:
5+
paths:
6+
- .github/workflows/**/*
7+
- spec/**/*
8+
- lib/**/*
9+
- tasks/**/*
10+
- functions/**/*
11+
- types/**/*
12+
- plans/**/*
13+
- hiera/**/*
14+
- manifests/**/*
15+
- templates/**/*
16+
- files/**/*
17+
- metadata.json
18+
- Rakefile
19+
- Gemfile
20+
- provision.yaml
21+
- .rspec
22+
- .rubocop.yml
23+
- .puppet-lint.rc
24+
- .fixtures.yml
25+
branches: [main]
26+
workflow_dispatch:
27+
inputs:
28+
ssh-debugging:
29+
description: Boolean; whether or not to pause for ssh debugging
30+
required: true
31+
default: 'false'
32+
jobs:
33+
upgrade_with_legacy_compilers:
34+
name: Upgrade PE with legacy compilers
35+
runs-on: ubuntu-20.04
36+
env:
37+
BOLT_GEM: true
38+
BOLT_DISABLE_ANALYTICS: true
39+
LANG: en_US.UTF-8
40+
steps:
41+
- name: Start SSH session
42+
if: ${{ github.event.inputs.ssh-debugging == 'true' }}
43+
uses: luchihoratiu/debug-via-ssh@main
44+
with:
45+
NGROK_AUTH_TOKEN: ${{ secrets.NGROK_AUTH_TOKEN }}
46+
SSH_PASS: ${{ secrets.SSH_PASS }}
47+
- name: Checkout Source
48+
uses: actions/checkout@v2
49+
- name: Activate Ruby 2.7
50+
uses: ruby/setup-ruby@v1
51+
with:
52+
ruby-version: '2.7'
53+
bundler-cache: true
54+
- name: Print bundle environment
55+
if: ${{ github.repository_owner == 'puppetlabs' }}
56+
run: |
57+
echo ::group::info:bundler
58+
bundle env
59+
echo ::endgroup::
60+
- name: Provision test cluster
61+
timeout-minutes: 15
62+
run: |
63+
echo ::group::prepare
64+
mkdir -p $HOME/.ssh
65+
echo 'Host *' > $HOME/.ssh/config
66+
echo ' ServerAliveInterval 150' >> $HOME/.ssh/config
67+
echo ' ServerAliveCountMax 2' >> $HOME/.ssh/config
68+
bundle exec rake spec_prep
69+
echo ::endgroup::
70+
echo ::group::provision
71+
bundle exec bolt plan run peadm_spec::provision_test_cluster \
72+
--modulepath spec/fixtures/modules \
73+
provider=provision_service \
74+
image=almalinux-cloud/almalinux-8 \
75+
architecture=large-with-dr
76+
echo ::endgroup::
77+
echo ::group::certnames
78+
bundle exec bolt plan run peadm_spec::add_inventory_hostnames \
79+
--inventory spec/fixtures/litmus_inventory.yaml \
80+
--modulepath spec/fixtures/modules \
81+
--no-host-key-check \
82+
inventory_file=spec/fixtures/litmus_inventory.yaml
83+
echo ::endgroup::
84+
echo ::group::info:request
85+
cat request.json || true; echo
86+
echo ::endgroup::
87+
echo ::group::info:inventory
88+
sed -e 's/password: .*/password: "[redacted]"/' < spec/fixtures/litmus_inventory.yaml || true
89+
echo ::endgroup::
90+
- name: Set up yq
91+
uses: frenck/action-setup-yq@v1
92+
with:
93+
version: v4.30.5
94+
- name: Create the params.json file
95+
run: |
96+
primary=$(yq '.groups[].targets[] | select(.vars.role == "primary") | .name' spec/fixtures/litmus_inventory.yaml)
97+
compiler=$(yq '.groups[].targets[] | select(.vars.role == "compiler") | .name' spec/fixtures/litmus_inventory.yaml | head -n 1)
98+
legacy_compiler=$(yq '.groups[].targets[] | select(.vars.role == "compiler") | .name' spec/fixtures/litmus_inventory.yaml | sed -n 2p)
99+
replica=$(yq '.groups[].targets[] | select(.vars.role == "replica") | .name' spec/fixtures/litmus_inventory.yaml)
100+
echo -n '{ "download_mode": "direct", "primary_host": "'$primary'", "replica_host": "'$replica'", "legacy_compilers": ["'$legacy_compiler'"], "compiler_hosts": ["'$compiler'"], "version": "2023.7.0", "console_password": "'${{ secrets.CONSOLE_PASSWORD }}'" }' > params.json
101+
- name: Install PE with legacy compilers
102+
timeout-minutes: 120
103+
run: |
104+
echo ::group::params.json
105+
jq '.console_password = "[redacted]"' params.json || true
106+
echo ::endgroup::
107+
echo ::group::install
108+
bundle exec bolt plan run peadm::install \
109+
--inventoryfile spec/fixtures/litmus_inventory.yaml \
110+
--modulepath spec/fixtures/modules \
111+
--no-host-key-check \
112+
--params @params.json
113+
echo ::endgroup::
114+
- name: Wait as long as the file ${HOME}/pause file is present
115+
if: ${{ always() && github.event.inputs.ssh-debugging == 'true' }}
116+
run: |
117+
while [ -f "${HOME}/pause" ] ; do
118+
echo "${HOME}/pause present, sleeping for 60 seconds..."
119+
sleep 60
120+
done
121+
echo "${HOME}/pause absent, continuing workflow."
122+
- name: Check if compilers are configured
123+
timeout-minutes: 120
124+
run: |
125+
echo ::group::inventory
126+
sed -e 's/password: .*/password: "[redacted]"/' < spec/fixtures/litmus_inventory.yaml || true
127+
echo ::endgroup::
128+
echo ::group::get_peadm_config
129+
primary=$(yq '.groups[].targets[] | select(.vars.role == "primary") | .name' spec/fixtures/litmus_inventory.yaml)
130+
compiler=$(yq '.groups[].targets[] | select(.vars.role == "compiler") | .name' spec/fixtures/litmus_inventory.yaml | head -n 1)
131+
legacy_compiler=$(yq '.groups[].targets[] | select(.vars.role == "compiler") | .name' spec/fixtures/litmus_inventory.yaml | sed -n 2p)
132+
bundle exec bolt task run peadm::get_peadm_config \
133+
--targets $primary \
134+
--inventoryfile spec/fixtures/litmus_inventory.yaml \
135+
--modulepath spec/fixtures/modules \
136+
--no-host-key-check \
137+
--format json > peadm_config.json
138+
cat peadm_config.json
139+
echo ::endgroup::
140+
echo ::group::smoke_test
141+
configured_legacy_compiler=$(yq '.items[0].value.params.legacy_compilers[0]' peadm_config.json)
142+
configured_compiler=$(yq '.items[0].value.params.compiler_hosts[0]' peadm_config.json)
143+
if [ "$configured_legacy_compiler" != "$legacy_compiler" ] && [ "$configured_compiler" != "$compiler" ]; then
144+
echo "Compilers are not configured, expected $legacy_compiler and $compiler, got $configured_legacy_compiler and $configured_compiler"
145+
exit 1
146+
fi
147+
echo ::endgroup::
148+
- name: Create the upgrade params.json file
149+
run: |
150+
primary=$(yq '.groups[].targets[] | select(.vars.role == "primary") | .name' spec/fixtures/litmus_inventory.yaml)
151+
compiler=$(yq '.groups[].targets[] | select(.vars.role == "compiler") | .name' spec/fixtures/litmus_inventory.yaml | head -n 1)
152+
legacy_compiler=$(yq '.groups[].targets[] | select(.vars.role == "compiler") | .name' spec/fixtures/litmus_inventory.yaml | sed -n 2p)
153+
replica=$(yq '.groups[].targets[] | select(.vars.role == "replica") | .name' spec/fixtures/litmus_inventory.yaml)
154+
echo -n '{ "primary_host": "'$primary'", "replica_host": "'$replica'", "compiler_hosts": ["'$compiler'", "'$legacy_compiler'"], "version": "2023.8.0"}' > upgrade_params.json
155+
- name: Upgrade PE with legacy compilers
156+
run: |
157+
echo ::group::upgrade_params.json
158+
cat upgrade_params.json
159+
echo ::endgroup::
160+
echo ::group::upgrade
161+
bundle exec bolt plan run peadm::upgrade \
162+
--inventoryfile spec/fixtures/litmus_inventory.yaml \
163+
--modulepath spec/fixtures/modules \
164+
--no-host-key-check \
165+
--params @upgrade_params.json
166+
echo ::endgroup::
167+
- name: Check if we still have legacy compilers configured
168+
timeout-minutes: 120
169+
run: |
170+
echo ::group::inventory
171+
sed -e 's/password: .*/password: "[redacted]"/' < spec/fixtures/litmus_inventory.yaml || true
172+
echo ::endgroup::
173+
echo ::group::get_peadm_config
174+
primary=$(yq '.groups[].targets[] | select(.vars.role == "primary") | .name' spec/fixtures/litmus_inventory.yaml)
175+
compiler=$(yq '.groups[].targets[] | select(.vars.role == "compiler") | .name' spec/fixtures/litmus_inventory.yaml | head -n 1)
176+
legacy_compiler=$(yq '.groups[].targets[] | select(.vars.role == "compiler") | .name' spec/fixtures/litmus_inventory.yaml | sed -n 2p)
177+
bundle exec bolt task run peadm::get_peadm_config \
178+
--targets $primary \
179+
--inventoryfile spec/fixtures/litmus_inventory.yaml \
180+
--modulepath spec/fixtures/modules \
181+
--no-host-key-check \
182+
--format json > peadm_config.json
183+
cat peadm_config.json
184+
echo ::endgroup::
185+
echo ::group::smoke_test
186+
configured_legacy_compiler=$(yq '.items[0].value.params.legacy_compilers[0]' peadm_config.json)
187+
configured_compiler=$(yq '.items[0].value.params.compiler_hosts[0]' peadm_config.json)
188+
if [ "$configured_legacy_compiler" != "$legacy_compiler" ] && [ "$configured_compiler" != "$compiler" ]; then
189+
echo "Compilers are not configured, expected $legacy_compiler and $compiler, got $configured_legacy_compiler and $configured_compiler"
190+
exit 1
191+
fi
192+
echo ::endgroup::
193+
- name: Tear down test cluster
194+
if: ${{ always() }}
195+
continue-on-error: true
196+
run: |-
197+
if [ -f spec/fixtures/litmus_inventory.yaml ]; then
198+
echo ::group::tear_down
199+
bundle exec rake 'litmus:tear_down'
200+
echo ::endgroup::
201+
echo ::group::info:request
202+
cat request.json || true; echo
203+
echo ::endgroup::
204+
fi

spec/acceptance/peadm_spec/plans/add_inventory_hostnames.pp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,15 @@
44
$t = get_targets('*')
55
wait_until_available($t)
66

7-
parallelize($t) |$target| {
8-
$fqdn = run_command('hostname -f', $target)
9-
$target.set_var('certname', $fqdn.first['stdout'].chomp)
10-
$command = "yq eval '(.groups[].targets[] | select(.uri == \"${target.uri}\").name) = \"${target.vars['certname']}\"' -i ${inventory_file}"
11-
run_command($command, 'localhost')
7+
$t.map |$target| {
8+
$fqdn = run_command('hostname -f', $target).first
9+
if $fqdn['exit_code'] != 0 {
10+
fail("Failed to get FQDN for target ${target.name}: ${fqdn['stderr']}")
11+
}
12+
$command = "yq eval '(.groups[].targets[] | select(.uri == \"${target.uri}\").name) = \"${fqdn['stdout'].chomp}\"' -i ${inventory_file}"
13+
$result = run_command($command, 'localhost').first
14+
if $result['exit_code'] != 0 {
15+
fail("Failed to update inventory file for target ${uri}: ${result['stderr']}")
16+
}
1217
}
1318
}

0 commit comments

Comments
 (0)