Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support BEAKER_FACTER_* env vars in beaker testing #108

Merged
merged 4 commits into from
Oct 11, 2023
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
10 changes: 10 additions & 0 deletions bin/metadata2gha
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ options = {
beaker_pidfile_workaround: false,
domain: nil,
minimum_major_puppet_version: nil,
beaker_fact: nil,
}

OptionParser.new do |opts|
Expand All @@ -30,6 +31,15 @@ OptionParser.new do |opts|
opts.on('--pidfile-workaround VALUE', 'Generate the systemd PIDFile workaround to work around a docker bug', PidfileWorkaround) { |opt| options[:beaker_pidfile_workaround] = opt }
opts.on('-d', '--domain VALUE', 'the domain for the box, only used when --use-fqdn is set to true') { |opt| options[:domain] = opt }
opts.on('--minimum-major-puppet-version VERSION', "Don't create actions for Puppet versions less than this major version") { |opt| options[:minimum_major_puppet_version] = opt }
opts.on('--beaker-facter FACT:LABEL:VALUES', 'Expand the matrix based on a fact. Separate values using commas') do |opt|
if opt != 'false'
fact, label, values = opt.split(':', 3)
label = fact if !label || label.empty?
raise OptionParser::InvalidArgument unless values

options[:beaker_facter] = [fact, label, values.split(',')]
end
end
end.parse!

filename = ARGV[0]
Expand Down
54 changes: 50 additions & 4 deletions lib/puppet_metadata/github_actions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ def outputs
{
puppet_major_versions: puppet_major_versions,
puppet_unit_test_matrix: puppet_unit_test_matrix,
puppet_beaker_test_matrix: puppet_beaker_test_matrix,
# Deprecated
github_action_test_matrix: github_action_test_matrix,
}
end
Expand Down Expand Up @@ -70,16 +72,49 @@ def beaker_os_releases
end
end

def github_action_test_matrix
def puppet_beaker_test_matrix
matrix_include = []

beaker_os_releases do |os, release, puppet_version|
setfile = PuppetMetadata::Beaker.os_release_to_setfile(
os, release, use_fqdn: options[:beaker_use_fqdn], pidfile_workaround: options[:beaker_pidfile_workaround], domain: options[:domain], puppet_version: puppet_version[:collection]
)
next if puppet_version_below_minimum?(puppet_version[:value])

setfile = os_release_to_beaker_setfile(os, release, puppet_version[:collection])
next unless setfile

name = "#{puppet_version[:name]} - #{setfile[1]}"
env = {
'BEAKER_PUPPET_COLLECTION' => puppet_version[:collection],
'BEAKER_SETFILE' => setfile[0],
}

if options[:beaker_facter]
fact, label, values = options[:beaker_facter]
values.each do |value|
matrix_include << {
name: "#{name} - #{label || fact} #{value}",
env: env.merge("BEAKER_FACTER_#{fact}" => value),
}
end
else
matrix_include << {
name: name,
env: env,
}
end
end

matrix_include
end

def github_action_test_matrix
matrix_include = []

beaker_os_releases do |os, release, puppet_version|
next if puppet_version_below_minimum?(puppet_version[:value])

setfile = os_release_to_beaker_setfile(os, release, puppet_version[:collection])
next unless setfile

matrix_include << {
name: "#{puppet_version[:name]} - #{setfile[1]}",
setfile: {
Expand All @@ -98,5 +133,16 @@ def puppet_version_below_minimum?(version)

Gem::Version.new(version) < Gem::Version.new(options[:minimum_major_puppet_version])
end

def os_release_to_beaker_setfile(os, release, puppet_collection)
PuppetMetadata::Beaker.os_release_to_setfile(
os,
release,
use_fqdn: options[:beaker_use_fqdn],
pidfile_workaround: options[:beaker_pidfile_workaround],
domain: options[:domain],
puppet_version: puppet_collection,
)
end
end
end
43 changes: 42 additions & 1 deletion spec/github_actions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
let(:beaker_use_fqdn) { false }

it { is_expected.to be_an_instance_of(Hash) }
it { expect(subject.keys).to contain_exactly(:puppet_major_versions, :puppet_unit_test_matrix, :github_action_test_matrix) }
it { expect(subject.keys).to contain_exactly(:puppet_major_versions, :puppet_unit_test_matrix, :puppet_beaker_test_matrix, :github_action_test_matrix) }

describe 'puppet_major_versions' do
subject { super()[:puppet_major_versions] }
Expand Down Expand Up @@ -111,6 +111,47 @@
end
end

describe 'puppet_beaker_test_matrix' do
subject { super()[:puppet_beaker_test_matrix] }

it { is_expected.to be_an_instance_of(Array) }

it 'is expected to contain supported os / puppet version combinations' do
expect(subject).to contain_exactly(
{ name: 'Distro Puppet - Archlinux rolling', env: { 'BEAKER_PUPPET_COLLECTION' => 'none', 'BEAKER_SETFILE' => 'archlinuxrolling-64' } },
{ name: 'Puppet 5 - CentOS 7', env: { 'BEAKER_PUPPET_COLLECTION' => 'puppet5', 'BEAKER_SETFILE' => 'centos7-64' } },
{ name: 'Puppet 6 - CentOS 7', env: { 'BEAKER_PUPPET_COLLECTION' => 'puppet6', 'BEAKER_SETFILE' => 'centos7-64' } },
{ name: 'Puppet 7 - CentOS 7', env: { 'BEAKER_PUPPET_COLLECTION' => 'puppet7', 'BEAKER_SETFILE' => 'centos7-64' } },
{ name: 'Puppet 8 - CentOS 7', env: { 'BEAKER_PUPPET_COLLECTION' => 'puppet8', 'BEAKER_SETFILE' => 'centos7-64' } },
{ name: 'Puppet 5 - CentOS 8', env: { 'BEAKER_PUPPET_COLLECTION' => 'puppet5', 'BEAKER_SETFILE' => 'centos8-64' } },
{ name: 'Puppet 6 - CentOS 8', env: { 'BEAKER_PUPPET_COLLECTION' => 'puppet6', 'BEAKER_SETFILE' => 'centos8-64' } },
{ name: 'Puppet 7 - CentOS 8', env: { 'BEAKER_PUPPET_COLLECTION' => 'puppet7', 'BEAKER_SETFILE' => 'centos8-64' } },
{ name: 'Puppet 8 - CentOS 8', env: { 'BEAKER_PUPPET_COLLECTION' => 'puppet8', 'BEAKER_SETFILE' => 'centos8-64' } },
{ name: 'Puppet 6 - CentOS 9', env: { 'BEAKER_PUPPET_COLLECTION' => 'puppet6', 'BEAKER_SETFILE' => 'centos9-64' } },
{ name: 'Puppet 7 - CentOS 9', env: { 'BEAKER_PUPPET_COLLECTION' => 'puppet7', 'BEAKER_SETFILE' => 'centos9-64' } },
{ name: 'Puppet 8 - CentOS 9', env: { 'BEAKER_PUPPET_COLLECTION' => 'puppet8', 'BEAKER_SETFILE' => 'centos9-64' } },
{ name: 'Puppet 5 - Debian 9', env: { 'BEAKER_PUPPET_COLLECTION' => 'puppet5', 'BEAKER_SETFILE' => 'debian9-64' } },
{ name: 'Puppet 6 - Debian 9', env: { 'BEAKER_PUPPET_COLLECTION' => 'puppet6', 'BEAKER_SETFILE' => 'debian9-64' } },
{ name: 'Puppet 7 - Debian 9', env: { 'BEAKER_PUPPET_COLLECTION' => 'puppet7', 'BEAKER_SETFILE' => 'debian9-64' } },
{ name: 'Puppet 5 - Debian 10', env: { 'BEAKER_PUPPET_COLLECTION' => 'puppet5', 'BEAKER_SETFILE' => 'debian10-64' } },
{ name: 'Puppet 6 - Debian 10', env: { 'BEAKER_PUPPET_COLLECTION' => 'puppet6', 'BEAKER_SETFILE' => 'debian10-64' } },
{ name: 'Puppet 7 - Debian 10', env: { 'BEAKER_PUPPET_COLLECTION' => 'puppet7', 'BEAKER_SETFILE' => 'debian10-64' } },
{ name: 'Puppet 8 - Debian 10', env: { 'BEAKER_PUPPET_COLLECTION' => 'puppet8', 'BEAKER_SETFILE' => 'debian10-64' } },
)
end

context 'with beaker_facter option' do
let(:options) { super().merge(beaker_facter: ['pulpcore_version', 'Pulp', %w[2 3]]) }

it 'is expected to contain supported os / puppet version / fact combinations' do
expect(subject).to include(
{ name: 'Distro Puppet - Archlinux rolling - Pulp 2', env: { 'BEAKER_PUPPET_COLLECTION' => 'none', 'BEAKER_SETFILE' => 'archlinuxrolling-64', 'BEAKER_FACTER_pulpcore_version' => '2' } },
{ name: 'Distro Puppet - Archlinux rolling - Pulp 3', env: { 'BEAKER_PUPPET_COLLECTION' => 'none', 'BEAKER_SETFILE' => 'archlinuxrolling-64', 'BEAKER_FACTER_pulpcore_version' => '3' } },
)
end
end
end

describe 'github_action_test_matrix' do
subject { super()[:github_action_test_matrix] }

Expand Down