Skip to content

Commit ab6e9cf

Browse files
authored
Merge pull request #21 from voxpupuli/gh-20-curl-versions-predate-fail-with-body
(gh-20) Download with curl --fail instead of --fail-with-body
2 parents 9c75d24 + 11e6d7c commit ab6e9cf

File tree

12 files changed

+411
-38
lines changed

12 files changed

+411
-38
lines changed

.github/workflows/pr_testing.yaml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ env:
1313
# Environment variables needed when running the task install scripts
1414
# manually.
1515
PT__installdir: ${{ github.workspace }}
16-
PT_apt_source: "https://apt.voxpupuli.org"
17-
PT_yum_source: "https://yum.voxpupuli.org"
1816

1917
jobs:
2018
shellcheck:
@@ -46,8 +44,7 @@ jobs:
4644
- name: Run openvox-agent install task
4745
run: bolt task run openvox_bootstrap::install --targets localhost --run-as root
4846
- name: Verify openvox-agent is installed
49-
run: |-
50-
[[ "$(/opt/puppetlabs/bin/puppet --version)" =~ [0-9]+\.[0-9]+\.[0-9]+ ]]
47+
run: bolt task run openvox_bootstrap::check --targets localhost --run-as root
5148
- name: Verify idempotency
5249
run: bolt task run openvox_bootstrap::install --targets localhost --run-as root
5350

@@ -80,7 +77,10 @@ jobs:
8077
PT_collection: openvox8
8178
run: ./openvox_bootstrap/tasks/install_linux.sh
8279
- name: Verify openvox-agent is installed
83-
run: /opt/puppetlabs/bin/puppet --version | grep -E '8\.[0-9]+'
80+
env:
81+
PT_version: '8'
82+
PT_test: 'gt'
83+
run: ./openvox_bootstrap/tasks/check_linux.sh
8484
- name: Verify idempotency
8585
env:
8686
PT_collection: openvox8
@@ -110,7 +110,9 @@ jobs:
110110
PT_version: "8.14.0"
111111
run: ./openvox_bootstrap/tasks/install_linux.sh
112112
- name: Verify openvox-agent is installed
113-
run: /opt/puppetlabs/bin/puppet --version | grep '8.14.0'
113+
env:
114+
PT_version: "8.14.0"
115+
run: ./openvox_bootstrap/tasks/check_linux.sh
114116
- name: Verify idempotency
115117
env:
116118
PT_version: "8.14.0"

.github/workflows/pr_testing_install_build_artifact.yaml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ jobs:
2929
- name: Run openvox-agent install task
3030
run: bolt task run openvox_bootstrap::install_build_artifact version=8.15.0 --targets localhost --run-as root
3131
- name: Verify openvox-agent is installed
32-
run: |-
33-
[[ "$(/opt/puppetlabs/bin/puppet --version)" = "8.15.0" ]]
32+
run: bolt task run openvox_bootstrap::check version=8.15.0 --targets localhost --run-as root
3433
- name: Verify idempotency
3534
run: bolt task run openvox_bootstrap::install_build_artifact version=8.15.0 --targets localhost --run-as root
3635

@@ -64,8 +63,10 @@ jobs:
6463
run: ./openvox_bootstrap/tasks/install_build_artifact_linux.sh
6564
- name: Verify openvox-agent is installed
6665
shell: bash
67-
run: |-
68-
[[ "$(/opt/puppetlabs/bin/puppet --version)" = "8.15.0" ]]
66+
env:
67+
PT__installdir: ${{ github.workspace }}
68+
PT_version: "8.15.0"
69+
run: ./openvox_bootstrap/tasks/check_linux.sh
6970
- name: Verify idempotency
7071
env:
7172
PT__installdir: ${{ github.workspace }}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
---
2+
name: 'PR Testing with Nested VMs'
3+
4+
on:
5+
push:
6+
branches:
7+
- main
8+
pull_request:
9+
branches:
10+
- main
11+
12+
jobs:
13+
test-install-task:
14+
strategy:
15+
matrix:
16+
os:
17+
- [almalinux, '8']
18+
- [almalinux, '9']
19+
- [debian, '10']
20+
- [debian, '11']
21+
- [debian, '12']
22+
- [debian, '13', 'amd64', 'daily-latest']
23+
- [rocky, '8']
24+
- [rocky, '9']
25+
- [ubuntu, '18.04']
26+
- [ubuntu, '20.04']
27+
- [ubuntu, '22.04']
28+
- [ubuntu, '24.04']
29+
runs-on: ubuntu-22.04
30+
steps:
31+
- uses: actions/checkout@v4
32+
- id: install-bolt
33+
uses: ./.github/actions/bolt
34+
with:
35+
os-codename: jammy
36+
- id: vm-cluster
37+
uses: jpartlow/nested_vms@v1
38+
with:
39+
os: ${{ matrix.os[0] }}
40+
os-version: ${{ matrix.os[1] }}
41+
os-arch: ${{ matrix.os[2] || 'x86_64' }}
42+
image_version: ${{ matrix.os[3] }}
43+
host-root-access: true
44+
ruby-version: '3.3'
45+
install-openvox: false
46+
# Note: the cpu_mode is set to host-model for the sake of
47+
# el-9 which expects at least x86_64-2 arch. This depends on
48+
# the runner's architecture being sufficient, and there is
49+
# probably a better way to get this set on the libvirt
50+
# domain instead.
51+
vms: |-
52+
[
53+
{
54+
"role": "agent",
55+
"count": 1,
56+
"cpus": 2,
57+
"mem_mb": 4096,
58+
"cpu_mode": "host-model"
59+
}
60+
]
61+
- name: Run openvox_bootstrap::install task on nested vm
62+
run: |-
63+
bolt task run openvox_bootstrap::install --inventory kvm_automation_tooling/terraform/instances/inventory.test.yaml --targets test-agent-1
64+
- name: Verify openvox-agent is installed
65+
run: |-
66+
bolt task run openvox_bootstrap::check version=8 test=gt --inventory kvm_automation_tooling/terraform/instances/inventory.test.yaml --targets test-agent-1

REFERENCE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,32 @@
66

77
### Tasks
88

9+
* [`check`](#check): Check whether a Puppet(tm) implementation is installed. Optionally checks the version.
910
* [`install`](#install): Installs an openvox package. By default, this will be the latest openvox-agent from the latest collection.
1011
* [`install_build_artifact`](#install_build_artifact): Downloads and installs a package directly from the openvox build artifact server.
1112

1213
## Tasks
1314

15+
### <a name="check"></a>`check`
16+
17+
Check whether a Puppet(tm) implementation is installed. Optionally checks the version.
18+
19+
**Supports noop?** false
20+
21+
#### Parameters
22+
23+
##### `version`
24+
25+
Data type: `Optional[String]`
26+
27+
The version of the implementation to check. To check if version meets a minimum, set test to 'ge' and version to x, x.y or x.y.z
28+
29+
##### `test`
30+
31+
Data type: `Enum['eq', 'lt', 'le', 'gt', 'ge']`
32+
33+
Version comparison operator.
34+
1435
### <a name="install"></a>`install`
1536

1637
Installs an openvox package. By default, this will be the latest openvox-agent from the latest collection.

files/common.sh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#! /usr/bin/env bash
22

33
# PT_* variables are set by Bolt.
4-
# shellcheck disable=SC2154
5-
installdir=$PT__installdir
4+
declare PT__installdir
65

76
tempdir=$(mktemp -d)
87
trap 'rm -rf $tempdir' EXIT
@@ -143,7 +142,7 @@ download() {
143142
if exists 'wget'; then
144143
exec_and_capture wget -O "${_file}" "${_url}"
145144
elif exists 'curl'; then
146-
exec_and_capture curl --fail-with-body -sSL -o "${_file}" "${_url}"
145+
exec_and_capture curl --fail -sSL -o "${_file}" "${_url}"
147146
else
148147
fail "Unable to download ${_url}. Neither wget nor curl are installed."
149148
fi
@@ -210,7 +209,7 @@ set_os_family() {
210209
# $os_major_version
211210
# $os_family
212211
set_platform_globals() {
213-
local facts="${installdir}/facts/tasks/bash.sh"
212+
local facts="${PT__installdir}/facts/tasks/bash.sh"
214213
if [ -e "${facts}" ]; then
215214
platform=$(bash "${facts}" platform)
216215
os_full_version=$(bash "${facts}" release)

spec/tasks/check_spec.rb

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper'
4+
require_relative '../../tasks/check'
5+
6+
describe 'openvox_bootstrap::check' do
7+
before do
8+
allow(OpenvoxBootstrap::Check).to receive(:puppet_version).and_return('8.0.0')
9+
end
10+
11+
describe '.run' do
12+
let(:input) do
13+
{
14+
version: nil
15+
}
16+
end
17+
let(:expected_output) do
18+
{
19+
puppet_version: '8.0.0',
20+
valid: true
21+
}
22+
end
23+
24+
def validate_task_run(input:, expected: {}, code: 0)
25+
old_stdin = $stdin
26+
$stdin = StringIO.new(input.to_json)
27+
old_stdout = $stdout
28+
$stdout = StringIO.new
29+
30+
begin
31+
OpenvoxBootstrap::Check.run
32+
rescue SystemExit => e
33+
expect(e.status).to eq(code)
34+
end
35+
36+
output = JSON.parse($stdout.string, symbolize_names: true)
37+
expect(output).to eq(expected)
38+
ensure
39+
$stdin = old_stdin
40+
$stdout = old_stdout
41+
end
42+
43+
it 'raises for empty input' do
44+
expect do
45+
validate_task_run(input: nil)
46+
end.to raise_error(ArgumentError)
47+
end
48+
49+
it 'returns version without test if given no args' do
50+
validate_task_run(input: input, expected: expected_output)
51+
end
52+
53+
context 'testing valid version' do
54+
it 'returns successfully' do
55+
input[:version] = '8.0.0'
56+
57+
expected_output[:test] = 'eq'
58+
expected_output[:test_version] = '8.0.0'
59+
60+
validate_task_run(input: input, expected: expected_output)
61+
end
62+
end
63+
64+
context 'testing invalid version' do
65+
it 'returns non-zero' do
66+
input[:version] = '8.1.0'
67+
input[:test] = 'gt'
68+
69+
expected_output[:valid] = false
70+
expected_output[:test] = 'gt'
71+
expected_output[:test_version] = '8.1.0'
72+
73+
validate_task_run(input: input, expected: expected_output, code: 1)
74+
end
75+
end
76+
end
77+
78+
describe '#task' do
79+
let(:check) { OpenvoxBootstrap::Check.new }
80+
81+
context 'eq' do
82+
it 'returns true for equal versions' do
83+
expect(check.task(version: '8.0.0')).to(
84+
eq(
85+
{
86+
puppet_version: '8.0.0',
87+
valid: true,
88+
test: 'eq',
89+
test_version: '8.0.0'
90+
}
91+
)
92+
)
93+
end
94+
95+
it 'returns false for unequal versions' do
96+
expect(check.task(version: '8.0.1')).to(
97+
eq(
98+
{
99+
puppet_version: '8.0.0',
100+
valid: false,
101+
test: 'eq',
102+
test_version: '8.0.1'
103+
}
104+
)
105+
)
106+
end
107+
end
108+
109+
context 'ge' do
110+
it 'returns true for greater than versions' do
111+
expect(check.task(version: '7.0.0', test: 'ge')).to(
112+
eq(
113+
{
114+
puppet_version: '8.0.0',
115+
valid: true,
116+
test: 'ge',
117+
test_version: '7.0.0'
118+
}
119+
)
120+
)
121+
end
122+
123+
it 'returns true for equal versions' do
124+
expect(check.task(version: '8.0.0', test: 'ge')).to(include(valid: true))
125+
end
126+
127+
it 'returns false for less than versions' do
128+
expect(check.task(version: '9.0.0', test: 'ge')).to(
129+
eq(
130+
{
131+
puppet_version: '8.0.0',
132+
valid: false,
133+
test: 'ge',
134+
test_version: '9.0.0'
135+
}
136+
)
137+
)
138+
end
139+
end
140+
141+
context 'gt' do
142+
it 'is valid for greater than versions' do
143+
expect(check.task(version: '7.0.0', test: 'gt')).to(include(valid: true))
144+
end
145+
146+
it 'is invalid for equal versions or less than versions' do
147+
expect(check.task(version: '8.0.0', test: 'gt')).to(include(valid: false))
148+
expect(check.task(version: '8.0.1', test: 'gt')).to(include(valid: false))
149+
end
150+
end
151+
152+
context 'lt' do
153+
it 'is valid for less than versions' do
154+
expect(check.task(version: '8.0.1', test: 'lt')).to(include(valid: true))
155+
end
156+
157+
it 'is invalid for equal versions or greater than versions' do
158+
expect(check.task(version: '8.0.0', test: 'lt')).to(include(valid: false))
159+
expect(check.task(version: '7.0.0', test: 'lt')).to(include(valid: false))
160+
end
161+
end
162+
163+
context 'le' do
164+
it 'is valid for less than or equal versions' do
165+
expect(check.task(version: '9.0.0', test: 'le')).to(include(valid: true))
166+
expect(check.task(version: '8.0.0', test: 'le')).to(include(valid: true))
167+
end
168+
169+
it 'is invalid for greater than versions' do
170+
expect(check.task(version: '7.0.0', test: 'le')).to(include(valid: false))
171+
end
172+
end
173+
end
174+
end

spec/unit/bash/common_sh_spec.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,7 @@
247247
expect(status.success?).to be(false)
248248
expect(output).to include('Executing: curl ')
249249
expect(output).to include('The requested URL returned error: 404')
250-
file = File.read("#{tmpdir}/file")
251-
expect(file).to include('404 Not Found')
250+
expect(File.exist?("#{tmpdir}/file")).to be(false)
252251
end
253252
end
254253
end

0 commit comments

Comments
 (0)