Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions .github/workflows/pr_testing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ env:
# Environment variables needed when running the task install scripts
# manually.
PT__installdir: ${{ github.workspace }}
PT_apt_source: "https://apt.voxpupuli.org"
PT_yum_source: "https://yum.voxpupuli.org"

jobs:
shellcheck:
Expand Down Expand Up @@ -46,8 +44,7 @@ jobs:
- name: Run openvox-agent install task
run: bolt task run openvox_bootstrap::install --targets localhost --run-as root
- name: Verify openvox-agent is installed
run: |-
[[ "$(/opt/puppetlabs/bin/puppet --version)" =~ [0-9]+\.[0-9]+\.[0-9]+ ]]
run: bolt task run openvox_bootstrap::check --targets localhost --run-as root
- name: Verify idempotency
run: bolt task run openvox_bootstrap::install --targets localhost --run-as root

Expand Down Expand Up @@ -80,7 +77,10 @@ jobs:
PT_collection: openvox8
run: ./openvox_bootstrap/tasks/install_linux.sh
- name: Verify openvox-agent is installed
run: /opt/puppetlabs/bin/puppet --version | grep -E '8\.[0-9]+'
env:
PT_version: '8'
PT_test: 'gt'
run: ./openvox_bootstrap/tasks/check_linux.sh
- name: Verify idempotency
env:
PT_collection: openvox8
Expand Down Expand Up @@ -110,7 +110,9 @@ jobs:
PT_version: "8.14.0"
run: ./openvox_bootstrap/tasks/install_linux.sh
- name: Verify openvox-agent is installed
run: /opt/puppetlabs/bin/puppet --version | grep '8.14.0'
env:
PT_version: "8.14.0"
run: ./openvox_bootstrap/tasks/check_linux.sh
- name: Verify idempotency
env:
PT_version: "8.14.0"
Expand Down
9 changes: 5 additions & 4 deletions .github/workflows/pr_testing_install_build_artifact.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ jobs:
- name: Run openvox-agent install task
run: bolt task run openvox_bootstrap::install_build_artifact version=8.15.0 --targets localhost --run-as root
- name: Verify openvox-agent is installed
run: |-
[[ "$(/opt/puppetlabs/bin/puppet --version)" = "8.15.0" ]]
run: bolt task run openvox_bootstrap::check version=8.15.0 --targets localhost --run-as root
- name: Verify idempotency
run: bolt task run openvox_bootstrap::install_build_artifact version=8.15.0 --targets localhost --run-as root

Expand Down Expand Up @@ -64,8 +63,10 @@ jobs:
run: ./openvox_bootstrap/tasks/install_build_artifact_linux.sh
- name: Verify openvox-agent is installed
shell: bash
run: |-
[[ "$(/opt/puppetlabs/bin/puppet --version)" = "8.15.0" ]]
env:
PT__installdir: ${{ github.workspace }}
PT_version: "8.15.0"
run: ./openvox_bootstrap/tasks/check_linux.sh
- name: Verify idempotency
env:
PT__installdir: ${{ github.workspace }}
Expand Down
66 changes: 66 additions & 0 deletions .github/workflows/pr_testing_with_nested_vms.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
---
name: 'PR Testing with Nested VMs'

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
test-install-task:
strategy:
matrix:
os:
- [almalinux, '8']
- [almalinux, '9']
- [debian, '10']
- [debian, '11']
- [debian, '12']
- [debian, '13', 'amd64', 'daily-latest']
- [rocky, '8']
- [rocky, '9']
- [ubuntu, '18.04']
- [ubuntu, '20.04']
- [ubuntu, '22.04']
- [ubuntu, '24.04']
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- id: install-bolt
uses: ./.github/actions/bolt
with:
os-codename: jammy
- id: vm-cluster
uses: jpartlow/nested_vms@v1
with:
os: ${{ matrix.os[0] }}
os-version: ${{ matrix.os[1] }}
os-arch: ${{ matrix.os[2] || 'x86_64' }}
image_version: ${{ matrix.os[3] }}
host-root-access: true
ruby-version: '3.3'
install-openvox: false
# Note: the cpu_mode is set to host-model for the sake of
# el-9 which expects at least x86_64-2 arch. This depends on
# the runner's architecture being sufficient, and there is
# probably a better way to get this set on the libvirt
# domain instead.
vms: |-
[
{
"role": "agent",
"count": 1,
"cpus": 2,
"mem_mb": 4096,
"cpu_mode": "host-model"
}
]
- name: Run openvox_bootstrap::install task on nested vm
run: |-
bolt task run openvox_bootstrap::install --inventory kvm_automation_tooling/terraform/instances/inventory.test.yaml --targets test-agent-1
- name: Verify openvox-agent is installed
run: |-
bolt task run openvox_bootstrap::check version=8 test=gt --inventory kvm_automation_tooling/terraform/instances/inventory.test.yaml --targets test-agent-1
21 changes: 21 additions & 0 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,32 @@

### Tasks

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

## Tasks

### <a name="check"></a>`check`

Check whether a Puppet(tm) implementation is installed. Optionally checks the version.

**Supports noop?** false

#### Parameters

##### `version`

Data type: `Optional[String]`

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

##### `test`

Data type: `Enum['eq', 'lt', 'le', 'gt', 'ge']`

Version comparison operator.

### <a name="install"></a>`install`

Installs an openvox package. By default, this will be the latest openvox-agent from the latest collection.
Expand Down
7 changes: 3 additions & 4 deletions files/common.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#! /usr/bin/env bash

# PT_* variables are set by Bolt.
# shellcheck disable=SC2154
installdir=$PT__installdir
declare PT__installdir

tempdir=$(mktemp -d)
trap 'rm -rf $tempdir' EXIT
Expand Down Expand Up @@ -143,7 +142,7 @@ download() {
if exists 'wget'; then
exec_and_capture wget -O "${_file}" "${_url}"
elif exists 'curl'; then
exec_and_capture curl --fail-with-body -sSL -o "${_file}" "${_url}"
exec_and_capture curl --fail -sSL -o "${_file}" "${_url}"
else
fail "Unable to download ${_url}. Neither wget nor curl are installed."
fi
Expand Down Expand Up @@ -210,7 +209,7 @@ set_os_family() {
# $os_major_version
# $os_family
set_platform_globals() {
local facts="${installdir}/facts/tasks/bash.sh"
local facts="${PT__installdir}/facts/tasks/bash.sh"
if [ -e "${facts}" ]; then
platform=$(bash "${facts}" platform)
os_full_version=$(bash "${facts}" release)
Expand Down
174 changes: 174 additions & 0 deletions spec/tasks/check_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
# frozen_string_literal: true

require 'spec_helper'
require_relative '../../tasks/check'

describe 'openvox_bootstrap::check' do
before do
allow(OpenvoxBootstrap::Check).to receive(:puppet_version).and_return('8.0.0')
end

describe '.run' do
let(:input) do
{
version: nil
}
end
let(:expected_output) do
{
puppet_version: '8.0.0',
valid: true
}
end

def validate_task_run(input:, expected: {}, code: 0)
old_stdin = $stdin
$stdin = StringIO.new(input.to_json)
old_stdout = $stdout
$stdout = StringIO.new

begin
OpenvoxBootstrap::Check.run
rescue SystemExit => e
expect(e.status).to eq(code)
end

output = JSON.parse($stdout.string, symbolize_names: true)
expect(output).to eq(expected)
ensure
$stdin = old_stdin
$stdout = old_stdout
end

it 'raises for empty input' do
expect do
validate_task_run(input: nil)
end.to raise_error(ArgumentError)
end

it 'returns version without test if given no args' do
validate_task_run(input: input, expected: expected_output)
end

context 'testing valid version' do
it 'returns successfully' do
input[:version] = '8.0.0'

expected_output[:test] = 'eq'
expected_output[:test_version] = '8.0.0'

validate_task_run(input: input, expected: expected_output)
end
end

context 'testing invalid version' do
it 'returns non-zero' do
input[:version] = '8.1.0'
input[:test] = 'gt'

expected_output[:valid] = false
expected_output[:test] = 'gt'
expected_output[:test_version] = '8.1.0'

validate_task_run(input: input, expected: expected_output, code: 1)
end
end
end

describe '#task' do
let(:check) { OpenvoxBootstrap::Check.new }

context 'eq' do
it 'returns true for equal versions' do
expect(check.task(version: '8.0.0')).to(
eq(
{
puppet_version: '8.0.0',
valid: true,
test: 'eq',
test_version: '8.0.0'
}
)
)
end

it 'returns false for unequal versions' do
expect(check.task(version: '8.0.1')).to(
eq(
{
puppet_version: '8.0.0',
valid: false,
test: 'eq',
test_version: '8.0.1'
}
)
)
end
end

context 'ge' do
it 'returns true for greater than versions' do
expect(check.task(version: '7.0.0', test: 'ge')).to(
eq(
{
puppet_version: '8.0.0',
valid: true,
test: 'ge',
test_version: '7.0.0'
}
)
)
end

it 'returns true for equal versions' do
expect(check.task(version: '8.0.0', test: 'ge')).to(include(valid: true))
end

it 'returns false for less than versions' do
expect(check.task(version: '9.0.0', test: 'ge')).to(
eq(
{
puppet_version: '8.0.0',
valid: false,
test: 'ge',
test_version: '9.0.0'
}
)
)
end
end

context 'gt' do
it 'is valid for greater than versions' do
expect(check.task(version: '7.0.0', test: 'gt')).to(include(valid: true))
end

it 'is invalid for equal versions or less than versions' do
expect(check.task(version: '8.0.0', test: 'gt')).to(include(valid: false))
expect(check.task(version: '8.0.1', test: 'gt')).to(include(valid: false))
end
end

context 'lt' do
it 'is valid for less than versions' do
expect(check.task(version: '8.0.1', test: 'lt')).to(include(valid: true))
end

it 'is invalid for equal versions or greater than versions' do
expect(check.task(version: '8.0.0', test: 'lt')).to(include(valid: false))
expect(check.task(version: '7.0.0', test: 'lt')).to(include(valid: false))
end
end

context 'le' do
it 'is valid for less than or equal versions' do
expect(check.task(version: '9.0.0', test: 'le')).to(include(valid: true))
expect(check.task(version: '8.0.0', test: 'le')).to(include(valid: true))
end

it 'is invalid for greater than versions' do
expect(check.task(version: '7.0.0', test: 'le')).to(include(valid: false))
end
end
end
end
3 changes: 1 addition & 2 deletions spec/unit/bash/common_sh_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,7 @@
expect(status.success?).to be(false)
expect(output).to include('Executing: curl ')
expect(output).to include('The requested URL returned error: 404')
file = File.read("#{tmpdir}/file")
expect(file).to include('404 Not Found')
expect(File.exist?("#{tmpdir}/file")).to be(false)
end
end
end
Expand Down
Loading