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

Add support for OpenVox beaker jobs #165

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
4 changes: 4 additions & 0 deletions lib/puppet_metadata/aio.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ class AIO
8 => '3.2',
}.freeze

OPENVOX_RUBY_VERSIONS = {
8 => '3.2',
}.freeze

class << self
def find_base_os(os)
COMPATIBLE.fetch(os, os)
Expand Down
36 changes: 30 additions & 6 deletions lib/puppet_metadata/github_actions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
def outputs(at = nil)
{
puppet_unit_test_matrix: puppet_unit_test_matrix,
puppet_beaker_test_matrix: puppet_beaker_test_matrix(at),
puppet_beaker_test_matrix: puppet_beaker_test_matrix(at) + openvox_beaker_test_matrix(at),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like keeping a single method. puppet_beaker_test_matrix is also the output key, so let's change the methods so they return the correct result.

Suggested change
puppet_beaker_test_matrix: puppet_beaker_test_matrix(at) + openvox_beaker_test_matrix(at),
puppet_beaker_test_matrix: puppet_beaker_test_matrix(at),

You can argue it would be better to use ${gem}_${target}_$test_matrix to decouple from Puppet specifically. Then it'd be puppet_metadata_unit_test_matrix instead.

}
end

Expand All @@ -35,6 +35,18 @@
end.compact
end

def openvox_major_versions
metadata.openvox_major_versions.sort.reverse.map do |version|
next if puppet_version_below_minimum?(version)

{
name: "Puppet #{version}",
value: version,
collection: "openvox#{version}",
}
end.compact
end

def puppet_unit_test_matrix
metadata.puppet_major_versions.sort.reverse.map do |puppet|
ruby = PuppetMetadata::AIO::PUPPET_RUBY_VERSIONS[puppet]
Expand All @@ -48,15 +60,19 @@
end.compact
end

def beaker_os_releases(at = nil)
majors = puppet_major_versions
def beaker_os_releases(at = nil, collection)

Check failure on line 63 in lib/puppet_metadata/github_actions.rb

View workflow job for this annotation

GitHub Actions / rubocop_and_matrix

Style/OptionalArguments: Optional arguments should appear at the end of the argument list. (https://rubystyle.guide#optional-arguments)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name collection isn't something I entirely agree with. Previously we have Puppet PC1 as a collection, later puppet5, puppet6, etc. So IMHO collection isn't quite accurate.

Question is, what is accurate. In metadata.json it's listed under requirements so I'd play with something like for_requirement because I don't know a good word for the thing that satisfies the requirement.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking more about it now: requirement_name could work as well

majors = case collection
when 'puppet'
puppet_major_versions
when 'openvox'
openvox_major_versions
end

distro_puppet_version = {
name: 'Distro Puppet',
value: nil, # We don't know the version and since it's rolling, it can be anything
collection: 'none',
}

metadata.operatingsystems.each do |os, releases|
case os
when 'Archlinux', 'Gentoo'
Expand Down Expand Up @@ -89,17 +105,25 @@
end

def puppet_beaker_test_matrix(at)
beaker_test_matrix(at, 'puppet')
end

def openvox_beaker_test_matrix(at)
beaker_test_matrix(at, 'openvox')
Comment on lines +108 to +112
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And following up on the above discussion:

Suggested change
beaker_test_matrix(at, 'puppet')
end
def openvox_beaker_test_matrix(at)
beaker_test_matrix(at, 'openvox')
beaker_test_matrix(at, 'puppet') + beaker_test_matrix(at, 'openvox')

You can even keep them alphabetically:

Suggested change
beaker_test_matrix(at, 'puppet')
end
def openvox_beaker_test_matrix(at)
beaker_test_matrix(at, 'openvox')
beaker_test_matrix(at, 'openvox') + beaker_test_matrix(at, 'puppet')

end

def beaker_test_matrix(at, collection)
matrix_include = []

beaker_os_releases(at) do |os, release, puppet_version|
beaker_os_releases(at, collection) 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

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

Expand Down
20 changes: 14 additions & 6 deletions lib/puppet_metadata/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,20 +137,28 @@ def satisfies_requirement?(name, version)
matches?(requirements[name], version)
end

def puppet_major_versions
major_versions('puppet')
end

def openvox_major_versions
major_versions('openvox')
end

# @return [Array[Integer]] Supported major Puppet versions
# @see #requirements
def puppet_major_versions
requirement = requirements['puppet']
raise Exception, 'No Puppet requirement found' unless requirement
def major_versions(collection)
requirement = requirements[collection]
# don't raise an exception
# raise Exception, "No #{collection} requirement found" unless requirement
return [] unless requirement

# Current latest major is 7. It is highly recommended that modules
# actually specify exact bounds, but this prevents an infinite loop.
end_major = (requirement.end == SemanticPuppet::Version::MAX) ? 7 : requirement.end.major
Comment on lines 156 to 158
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks out of date, which is a problem with hardcoding magic numbers ...


(requirement.begin.major..end_major).select do |major|
requirement.include?(SemanticPuppet::Version.new(major, 0,
0)) || requirement.include?(SemanticPuppet::Version.new(major,
99, 99))
requirement.include?(SemanticPuppet::Version.new(major, 0, 0)) || requirement.include?(SemanticPuppet::Version.new(major, 99, 99))
end
end

Expand Down
3 changes: 2 additions & 1 deletion spec/metadata_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
its(:operatingsystems) { is_expected.to eq({}) }
it { expect(subject.os_release_supported?('any', 'version')).to be(true) }
it { expect(subject.eol_operatingsystems).to eq({}) }
it { expect { subject.puppet_major_versions }.to raise_error(/No Puppet requirement found/) }
# TODO: check that we have at least one thing listed as requirement
# it { expect { subject.puppet_major_versions }.to raise_error(/No puppet requirement found/) }
end

context 'full metadata' do
Expand Down
Loading