Skip to content

Commit

Permalink
(MODULES-10670) Add alternate_pe_version parameter
Browse files Browse the repository at this point in the history
This parameter will allow PE users to override the PE version
detection used in the packages source to a different version
than the running PE version.  This could be used to hold back
packages during a PE upgrade cycle until the user is ready
to upgrade the agents.
  • Loading branch information
seanmil committed Oct 10, 2023
1 parent 2920159 commit c1e0210
Show file tree
Hide file tree
Showing 15 changed files with 205 additions and 25 deletions.
9 changes: 8 additions & 1 deletion manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@
# @param skip_if_unavailable
# For yum-based repositories, set the skip_if_unavailable option of the `yumrepo` type.
# @param disable_proxy
# @param alternate_pe_version
# When using a PE-based package source (e.g. "alternate_pe_source", "aix_source")
# this setting allows you to override the PE version number used when constructing the
# package source URL. Normally, this will be the running version of PE but this setting
# can be used to "hold back" the agents during an upgrade of PE if there is a need
# to upgrade the platform and agents on separate schedules.
class puppet_agent (
String $arch = $facts['os']['architecture'],
String $collection = $puppet_agent::params::collection,
Expand Down Expand Up @@ -131,7 +137,8 @@
Optional $wait_for_pxp_agent_exit = undef,
Optional $wait_for_puppet_run = undef,
Array[Puppet_agent::Config] $config = [],
String $version_file_path = $facts['os']['family'] ? { 'windows' => "${facts['env_windows_installdir']}\\VERSION", default => '/opt/puppetlabs/puppet/VERSION' }
String $version_file_path = $facts['os']['family'] ? { 'windows' => "${facts['env_windows_installdir']}\\VERSION", default => '/opt/puppetlabs/puppet/VERSION' },
Optional[String[1]] $alternate_pe_version = undef,
) inherits puppet_agent::params {
# The configure class uses $puppet_agent::config to manage settings in
# puppet.conf, and will always be present. It does not require management of
Expand Down
2 changes: 1 addition & 1 deletion manifests/osfamily/aix.pp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
fail('AIX upgrades are only supported on Puppet Enterprise')
}

$pe_server_version = pe_build_version()
$pe_server_version = $puppet_agent::alternate_pe_version.lest || { pe_build_version() }

# in puppet versions later than 4 we began using single agent packages for
# multiple version of AIX. The support sequence is as follows:
Expand Down
2 changes: 1 addition & 1 deletion manifests/osfamily/darwin.pp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
if $puppet_agent::absolute_source {
$source = $puppet_agent::absolute_source
} elsif ($puppet_agent::is_pe and (!$puppet_agent::use_alternate_sources)) {
$pe_server_version = pe_build_version()
$pe_server_version = $puppet_agent::alternate_pe_version.lest || { pe_build_version() }
if $puppet_agent::alternate_pe_source {
$source = "${puppet_agent::alternate_pe_source}/packages/${pe_server_version}/${facts['platform_tag']}/${puppet_agent::package_name}-${puppet_agent::prepare::package_version}-1.osx${$productversion_major}.dmg"
} elsif $puppet_agent::source {
Expand Down
2 changes: 1 addition & 1 deletion manifests/osfamily/debian.pp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
if getvar('::puppet_agent::manage_repo') == true {
include apt
if ($puppet_agent::is_pe and (!$puppet_agent::use_alternate_sources)) {
$pe_server_version = pe_build_version()
$pe_server_version = $puppet_agent::alternate_pe_version.lest || { pe_build_version() }
if $puppet_agent::source {
$source = "${puppet_agent::source}/packages/${pe_server_version}/${facts['platform_tag']}"
} elsif $puppet_agent::alternate_pe_source {
Expand Down
2 changes: 1 addition & 1 deletion manifests/osfamily/redhat.pp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
}
# lint:endignore
if ($puppet_agent::is_pe and (!$puppet_agent::use_alternate_sources)) {
$pe_server_version = pe_build_version()
$pe_server_version = $puppet_agent::alternate_pe_version.lest || { pe_build_version() }
# Treat Amazon Linux just like Enterprise Linux
$pe_repo_dir = ($facts['os']['name'] == 'Amazon') ? {
true => "el-${amz_el_version}-${facts['os']['architecture']}",
Expand Down
2 changes: 1 addition & 1 deletion manifests/osfamily/solaris.pp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
fail('Solaris upgrades are only supported on Puppet Enterprise')
}

$pe_server_version = pe_build_version()
$pe_server_version = $puppet_agent::alternate_pe_version.lest || { pe_build_version() }
if $puppet_agent::absolute_source {
$source_dir = $puppet_agent::absolute_source
} elsif $puppet_agent::alternate_pe_source {
Expand Down
2 changes: 1 addition & 1 deletion manifests/osfamily/suse.pp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
contain puppet_agent::prepare::package
} else {
if ($puppet_agent::is_pe and (!$puppet_agent::use_alternate_sources)) {
$pe_server_version = pe_build_version()
$pe_server_version = $puppet_agent::alternate_pe_version.lest || { pe_build_version() }

# SLES 11 in PE can no longer install agents from pe_repo
if $facts['os']['release']['major'] == '11' {
Expand Down
2 changes: 1 addition & 1 deletion manifests/osfamily/windows.pp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
} elsif $puppet_agent::source {
$source = $puppet_agent::source
} elsif ($puppet_agent::is_pe and (!$puppet_agent::use_alternate_sources)) {
$pe_server_version = pe_build_version()
$pe_server_version = $puppet_agent::alternate_pe_version.lest || { pe_build_version() }
$tag = $puppet_agent::arch ? {
'x64' => $facts['fips_enabled'] ? {
true => 'windowsfips-x86_64',
Expand Down
26 changes: 26 additions & 0 deletions spec/classes/puppet_agent_osfamily_aix_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,32 @@
}
end

context 'with a user defined PE version' do
let(:facts) do
common_facts.merge(
{
architecture: 'PowerPC_POWER8',
platform_tag: 'aix-7.1-power',
}
)
end
let(:params) do
{
package_version: '7.10.100.1',
collection: 'puppet7',
alternate_pe_version: '2222.2.2',
}
end

before(:each) do
Puppet::Parser::Functions.newfunction(:pe_build_version, type: :rvalue) { |_args| '2000.0.0' }
end

it {
is_expected.to contain_file('/opt/puppetlabs/packages/puppet-agent-7.10.100.1-1.aix7.1.ppc.rpm').with_source('puppet:///pe_packages/2222.2.2/aix-7.1-power/puppet-agent-7.10.100.1-1.aix7.1.ppc.rpm')
}
end

context 'with a puppet6 collection' do
context 'with versions up to 6.19.1' do
let(:params) do
Expand Down
20 changes: 20 additions & 0 deletions spec/classes/puppet_agent_osfamily_darwin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,26 @@
it { is_expected.to contain_file('/opt/puppetlabs/packages/puppet-agent-5.10.100.1-1.osx10.13.dmg').with_source('https://fake-pe-master.com/packages/2000.0.0/osx-10.13-x86_64/puppet-agent-5.10.100.1-1.osx10.13.dmg') }
end

describe 'when using a user defined PE version' do
let(:params) do
{
package_version: '5.10.100.1',
collection: 'puppet5',
alternate_pe_version: '2222.2.2',
}
end
let(:facts) do
facts.merge({
is_pe: true,
aio_agent_version: '1.10.99',
platform_tag: 'osx-10.13-x86_64',
macosx_productversion_major: '10.13'
})
end

it { is_expected.to contain_file('/opt/puppetlabs/packages/puppet-agent-5.10.100.1-1.osx10.13.dmg').with_source('puppet:///pe_packages/2222.2.2/osx-10.13-x86_64/puppet-agent-5.10.100.1-1.osx10.13.dmg') }
end

describe 'when using package_version auto' do
let(:params) do
{
Expand Down
22 changes: 22 additions & 0 deletions spec/classes/puppet_agent_osfamily_debian_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,28 @@
}
end

context 'when managing PE apt repo settings and using a user defined PE version' do
let(:params) do
{
manage_repo: true,
package_version: package_version,
alternate_pe_version: '2222.2.2'
}
end

it {
is_expected.to contain_apt__source('pc_repo')
.with({
'location' => 'https://master.example.vm:8140/packages/2222.2.2/debian-7-x86_64',
'repos' => 'PC1',
'key' => {
'id' => 'D6811ED3ADEEB8441AF5AA8F4528B6CD9E61EF26',
'source' => '/etc/pki/deb-gpg/GPG-KEY-puppet-20250406',
},
})
}
end

context 'when not managing PE apt repo settings' do
let(:params) do
{
Expand Down
12 changes: 12 additions & 0 deletions spec/classes/puppet_agent_osfamily_redhat_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,18 @@
it { is_expected.to contain_yumrepo('pc_repo').with_baseurl("http://fake-pe-master.com/packages/2000.0.0/#{repodir}") }
end

context 'when using a user defined PE version' do
let(:params) do
{
package_version: '5.2.0',
manage_repo: true,
alternate_pe_version: '2222.2.2'
}
end

it { is_expected.to contain_yumrepo('pc_repo').with_baseurl("https://master.example.vm:8140/packages/2222.2.2/#{repodir}") }
end

context 'with manage_repo enabled' do
let(:params) do
{
Expand Down
40 changes: 40 additions & 0 deletions spec/classes/puppet_agent_osfamily_solaris_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,26 @@ def install_script(ver, arch)
end
end

context 'when Solaris 11 i386 and a user defined PE version' do
let(:facts) do
override_facts(facts, is_pe: true, os: { release: { major: '11', }, }, platform_tag: 'solaris-11-i386')
end
let(:params) do
{
package_version: package_version,
alternate_pe_version: '2222.2.2'
}
end

it do
is_expected.to contain_file("/opt/puppetlabs/packages/puppet-agent@#{sol11_package_version},5.11-1.i386.p5p")
.with({
'ensure' => 'file',
'source' => "puppet:///pe_packages/2222.2.2/solaris-11-i386/puppet-agent@#{sol11_package_version},5.11-1.i386.p5p",
})
end
end

context 'when Solaris 11 i386' do
let(:facts) do
override_facts(facts, is_pe: true, os: { release: { major: '11', }, }, platform_tag: 'solaris-11-i386')
Expand Down Expand Up @@ -258,6 +278,26 @@ def install_script(ver, arch)
end
end

context 'when Solaris 10 i386 and a user defined PE version' do
let(:facts) do
override_facts(facts, is_pe: true, os: { release: { major: '10', }, }, platform_tag: 'solaris-10-i386')
end
let(:params) do
{
package_version: package_version,
alternate_pe_version: '2222.2.2'
}
end

it do
is_expected.to contain_file("/opt/puppetlabs/packages/puppet-agent-#{package_version}-1.i386.pkg.gz")
.with({
'ensure' => 'file',
'source' => "puppet:///pe_packages/2222.2.2/solaris-10-i386/puppet-agent-#{package_version}-1.i386.pkg.gz",
})
end
end

context 'when Solaris 10 i386' do
let(:facts) do
override_facts(facts, is_pe: true, os: { release: { major: '10', }, }, platform_tag: 'solaris-10-i386')
Expand Down
67 changes: 50 additions & 17 deletions spec/classes/puppet_agent_osfamily_suse_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,26 @@
}
end

context 'with manage_repo enabled and a user defined PE version' do
let(:params) do
{
manage_repo: true,
package_version: package_version,
alternate_pe_version: '2222.2.2',
}
end

it {
is_expected.to contain_ini_setting('zypper pc_repo baseurl')
.with({
'path' => '/etc/zypp/repos.d/pc_repo.repo',
'section' => 'pc_repo',
'setting' => 'baseurl',
'value' => "https://master.example.vm:8140/packages/2222.2.2/sles-#{os_version}-x86_64?ssl_verify=no",
})
}
end

it do
is_expected.to contain_package('puppet-agent')
end
Expand Down Expand Up @@ -369,23 +389,36 @@
end

describe 'package source', if: os_version == '11' do
it { is_expected.to contain_file('/etc/zypp/repos.d/pc_repo.repo').with({ 'ensure' => 'absent' }) }
it {
is_expected.to contain_file('/opt/puppetlabs/packages/puppet-agent-1.10.100-1.sles11.x86_64.rpm')
.with(
source: 'puppet:///pe_packages/2000.0.0/sles-11-x86_64/puppet-agent-1.10.100-1.sles11.x86_64.rpm',
)
}
it {
is_expected.to contain_exec('GPG check the RPM file')
.with(
command: 'rpm -K /opt/puppetlabs/packages/puppet-agent-1.10.100-1.sles11.x86_64.rpm',
path: '/bin:/usr/bin:/sbin:/usr/sbin',
require: 'File[/opt/puppetlabs/packages/puppet-agent-1.10.100-1.sles11.x86_64.rpm]',
logoutput: 'on_failure',
notify: 'Package[puppet-agent]',
)
}
context 'with no source overrides' do
it { is_expected.to contain_file('/etc/zypp/repos.d/pc_repo.repo').with({ 'ensure' => 'absent' }) }
it {
is_expected.to contain_file('/opt/puppetlabs/packages/puppet-agent-1.10.100-1.sles11.x86_64.rpm')
.with(
source: 'puppet:///pe_packages/2000.0.0/sles-11-x86_64/puppet-agent-1.10.100-1.sles11.x86_64.rpm',
)
}
it {
is_expected.to contain_exec('GPG check the RPM file')
.with(
command: 'rpm -K /opt/puppetlabs/packages/puppet-agent-1.10.100-1.sles11.x86_64.rpm',
path: '/bin:/usr/bin:/sbin:/usr/sbin',
require: 'File[/opt/puppetlabs/packages/puppet-agent-1.10.100-1.sles11.x86_64.rpm]',
logoutput: 'on_failure',
notify: 'Package[puppet-agent]',
)
}
end

context 'with a user defined PE version' do
let(:params) { super().merge(alternate_pe_version: '2222.2.2') }

it {
is_expected.to contain_file('/opt/puppetlabs/packages/puppet-agent-1.10.100-1.sles11.x86_64.rpm')
.with(
source: 'puppet:///pe_packages/2222.2.2/sles-11-x86_64/puppet-agent-1.10.100-1.sles11.x86_64.rpm',
)
}
end
end
end
end
Expand Down
20 changes: 20 additions & 0 deletions spec/classes/puppet_agent_osfamily_windows_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,26 @@
'source' => "puppet:///pe_packages/#{pe_version}/windows-#{tag}/puppet-agent-#{arch}.msi",
)
}

context 'when alternate_pe_source is supplied' do
let(:params) { super().merge(alternate_pe_source: 'https://fake-package-source.com') }

it {
is_expected.to contain_file("#{appdata}\\Puppetlabs\\packages\\puppet-agent-#{arch}.msi").with(
'source' => "https://fake-package-source.com/packages/#{pe_version}/windows-#{tag}/puppet-agent-#{arch}.msi",
)
}
end

context 'when alternate_pe_version is supplied' do
let(:params) { super().merge(alternate_pe_version: '2222.2.2') }

it {
is_expected.to contain_file("#{appdata}\\Puppetlabs\\packages\\puppet-agent-#{arch}.msi").with(
'source' => "puppet:///pe_packages/2222.2.2/windows-#{tag}/puppet-agent-#{arch}.msi",
)
}
end
end
end

Expand Down

0 comments on commit c1e0210

Please sign in to comment.