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

(MODULES-7758) Properly handle distro tag for Fedora platforms #321

Merged
merged 1 commit into from
Sep 11, 2018
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
21 changes: 20 additions & 1 deletion manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,26 @@
# Workaround PUP-5802/PUP-5025
if ($::operatingsystem == 'Fedora') {
if $pa_collection == 'PC1' or $pa_collection == 'puppet5' {
$dist_tag = "fedoraf${::operatingsystemmajrelease}"
# There's three cases here due to some mistakes with how we
# set-up our distro tags for Fedora platforms:
# * For newer Fedora platforms (e.g. Fedora 28), we want
# to use the fc<major> tag
#
# * For older Fedora platforms (e.g. Fedora 26 and 27), we
# have two separate cases:
# * If the package version's > 5.5.3, then we use the fedora<major>
# tag, b/c in those versions we removed the 'f' prefix.
#
# * If the package version's <= 5.5.3, then we use the fedoraf<major>
# tag b/c the 'f' prefix is still there.
#
if (versioncmp("${::operatingsystemmajrelease}", '27') > 0) {
$dist_tag = "fc${::operatingsystemmajrelease}"
} elsif (versioncmp("${package_version}", '5.5.3') > 0) {
$dist_tag = "fedora${::operatingsystemmajrelease}"
} else {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note that the PC1 collection will always hit the else branch since the agent version's older than 5.5.3, which is what we want.

$dist_tag = "fedoraf${::operatingsystemmajrelease}"
}
} else {
$dist_tag = "fc${::operatingsystemmajrelease}"
}
Expand Down
127 changes: 105 additions & 22 deletions spec/classes/puppet_agent_osfamily_redhat_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,27 @@

describe 'puppet_agent' do
# All FOSS and all Puppet 4+ upgrades require the package_version
package_version = '1.2.5'
package_version = '5.5.4'
let(:params) {
{
:package_version => package_version
}
}

[['Fedora', 'fedora/f$releasever', 7], ['CentOS', 'el/$releasever', 7], ['Amazon', 'el/6', 6]].each do |os, urlbit, osmajor|
let(:facts) do
{
:osfamily => 'RedHat',
:architecture => 'x64',
:servername => 'master.example.vm',
:clientcert => 'foo.example.vm',
}
end

[['Fedora', 'fedora/f$releasever', 27], ['CentOS', 'el/$releasever', 7], ['Amazon', 'el/6', 6]].each do |os, urlbit, osmajor|
context "with #{os} and #{urlbit}" do
let(:facts) {{
:osfamily => 'RedHat',
:operatingsystem => os,
:architecture => 'x64',
:servername => 'master.example.vm',
:clientcert => 'foo.example.vm',
:operatingsystemmajrelease => osmajor,
}}
let(:facts) do
super().merge(:operatingsystem => os, :operatingsystemmajrelease => osmajor)
end

it { is_expected.to contain_exec('import-GPG-KEY-puppetlabs').with({
'path' => '/bin:/usr/bin:/sbin:/usr/sbin',
Expand Down Expand Up @@ -116,6 +120,87 @@
end
end

# There are a lot of special cases here, so it is best to have a separate
# unit test context for them.
context 'distro tag on Fedora platforms' do
def sets_distro_tag_to(expected_distro_tag)
is_expected.to contain_package('puppet-agent').with_ensure(
"#{params[:package_version]}-1.#{expected_distro_tag}"
)
end

let(:facts) do
super().merge(:operatingsystem => 'Fedora')
end

context 'when the collection is PC1' do
let(:params) do
# Older agents use the PC1 collection, so set the package_version
# to 1.10.9 to simulate this.
super().merge(:collection => 'PC1', :package_version => '1.10.9')
end

let(:facts) do
# Older agents do not support anything past Fedora 27
super().merge(:operatingsystemmajrelease => 27)
end

it { sets_distro_tag_to('fedoraf27') }
end

context 'when the collection is puppet5' do
let(:params) do
super().merge(:collection => 'puppet5')
end

context 'on newer Fedora versions' do
let(:facts) do
super().merge(:operatingsystemmajrelease => 28)
end

it { sets_distro_tag_to('fc28') }
end

context 'on older Fedora versions' do
let(:facts) do
super().merge(:operatingsystemmajrelease => 27)
end

shared_examples 'a package version' do |package_version, distro_tag|
let(:params) do
super().merge(:package_version => package_version)
end

it { sets_distro_tag_to(distro_tag) }
end

context 'when package_version > 5.5.3' do
include_examples 'a package version', '5.5.4', 'fedora27'
end

context 'when package_version == 5.5.3' do
include_examples 'a package version', '5.5.3', 'fedoraf27'
end

context 'when package_version < 5.5.3' do
include_examples 'a package version', '5.5.1', 'fedoraf27'
end
end
end

context 'when the collection is newer than PC1 and puppet5' do
let(:params) do
super().merge(:collection => 'puppet6', :package_version => '6.0.0')
end

let(:facts) do
super().merge(:operatingsystemmajrelease => 27)
end

it { sets_distro_tag_to('fc27') }
end
end

[['RedHat', 'el-7-x86_64', 'el-7-x86_64', 7], ['Amazon', '', 'el-6-x64', 6]].each do |os, tag, repodir, osmajor|
context "when PE on #{os}" do
before(:each) do
Expand All @@ -126,20 +211,18 @@
end

Puppet::Parser::Functions.newfunction(:pe_compiling_server_aio_build, :type => :rvalue) do |args|
'1.2.5'
'5.5.4'
end
end

let(:facts) {{
:osfamily => 'RedHat',
:operatingsystem => os,
:architecture => 'x64',
:servername => 'master.example.vm',
:clientcert => 'foo.example.vm',
:is_pe => true,
:platform_tag => tag,
:operatingsystemmajrelease => osmajor,
}}
let(:facts) do
super().merge(
:operatingsystem => os,
:operatingsystemmajrelease => osmajor,
:platform_tag => tag,
is_pe: true
)
end

context 'with manage_repo enabled' do
let(:params) {
Expand Down Expand Up @@ -207,7 +290,7 @@
:package_version => package_version
}
}
it { is_expected.to contain_package('puppet-agent').with_ensure("1.2.5-1.el#{osmajor}") }
it { is_expected.to contain_package('puppet-agent').with_ensure("#{params[:package_version]}-1.el#{osmajor}") }

end

Expand Down