9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [1.7.0] - 2018-09-18

### Summary
Bugfix and compatibility update for Puppet 6

### Features
- Support for changes to Fedora package naming in Puppet 5 and 6
- Refactor OSX upgrades to be like Solaris and Windows, using an external script

## [1.6.2] - 2018-07-26

### Summary
Expand Down
58 changes: 44 additions & 14 deletions manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
assert_private()

$old_packages = (versioncmp("${::clientversion}", '4.0.0') < 0)
$pa_collection = getvar('::puppet_agent::collection')

if ($::operatingsystem == 'SLES' and $::operatingsystemmajrelease == '10') or $::operatingsystem == 'AIX' {
$_install_options = $::operatingsystem ? {
Expand Down Expand Up @@ -54,6 +55,7 @@
$_unzipped_package_name = regsubst($package_file_name, '\.gz$', '')
$adminfile = '/opt/puppetlabs/packages/solaris-noask'
$sourcefile = "/opt/puppetlabs/packages/${_unzipped_package_name}"
$install_script = 'solaris_install.sh.erb'

# Puppet prior to 5.0 would not use a separate process contract when forking from the Puppet
# service. That resulted in service-initiated upgrades failing because trying to remove or
Expand Down Expand Up @@ -89,11 +91,7 @@
file { "${_installsh}":
ensure => file,
mode => '0755',
content => epp('puppet_agent/solaris_install.sh.epp', {
'old_package_names' => $old_package_names,
'adminfile' => $adminfile,
'sourcefile' => $sourcefile,
'install_options' => $install_options})
content => template('puppet_agent/do_install.sh.erb')
}
-> exec { 'solaris_install script':
command => "/usr/bin/ctrun -l none ${_installsh} ${::puppet_agent_pid} 2>&1 > ${_logfile} &",
Expand Down Expand Up @@ -123,15 +121,24 @@
refreshonly => true,
}
} elsif $::operatingsystem == 'Darwin' and $::macosx_productversion_major =~ /^10\.(9|10|11|12|13)/ {
contain puppet_agent::install::remove_packages
if $old_packages or $puppet_agent::aio_upgrade_required {
$install_script = 'osx_install.sh.erb'

# package provider does not provide 'versionable'
package { $::puppet_agent::package_name:
ensure => 'present',
provider => 'pkgdmg',
source => "/opt/puppetlabs/packages/${package_file_name}",
require => Class['puppet_agent::install::remove_packages'],
install_options => $install_options,
contain puppet_agent::install::remove_packages

$_logfile = "${::env_temp_variable}/osx_install.log"
notice("Puppet install log file at ${_logfile}")

$_installsh = "${::env_temp_variable}/osx_install.sh"
file { "${_installsh}":
ensure => file,
mode => '0755',
content => template('puppet_agent/do_install.sh.erb'),
require => Class['Puppet_agent::Install::Remove_packages']
}
-> exec { 'osx_install script':
command => "${_installsh} ${::puppet_agent_pid} 2>&1 > ${_logfile} &",
}
}
} elsif $::osfamily == 'windows' {
# Prevent re-running the batch install
Expand All @@ -157,7 +164,30 @@
} elsif ($::osfamily == 'RedHat') and ($package_version != 'present') {
# Workaround PUP-5802/PUP-5025
if ($::operatingsystem == 'Fedora') {
$dist_tag = "fedoraf${::operatingsystemmajrelease}"
if $pa_collection == 'PC1' or $pa_collection == 'puppet5' {
# 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 {
$dist_tag = "fedoraf${::operatingsystemmajrelease}"
}
} else {
$dist_tag = "fc${::operatingsystemmajrelease}"
}
} elsif ($::platform_tag != undef and $::platform_tag =~ /redhatfips.*/) {
# The undef check here is for unit tests that don't supply this fact.
$dist_tag = 'redhatfips7'
Expand Down
9 changes: 6 additions & 3 deletions metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "puppetlabs-puppet_agent",
"version": "1.6.2",
"version": "1.7.0",
"author": "puppetlabs",
"summary": "Upgrades Puppet 3.7+ and All-In-One Puppet Agents",
"license": "Apache-2.0",
Expand Down Expand Up @@ -76,7 +76,10 @@
"22",
"23",
"24",
"25"
"25",
"26",
"27",
"28"
]
},
{
Expand Down Expand Up @@ -125,7 +128,7 @@
"requirements": [
{
"name": "puppet",
"version_requirement": ">= 3.7.0 < 6.0.0"
"version_requirement": ">= 3.7.0 < 7.0.0"
}
],
"dependencies": [
Expand Down
9 changes: 6 additions & 3 deletions spec/classes/puppet_agent_osfamily_darwin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
:architecture => 'x86_64',
:servername => 'master.example.vm',
:clientcert => 'foo.example.vm',
:env_temp_variable => '/tmp',
:puppet_agent_pid => 42
}

describe 'unsupported environment' do
Expand All @@ -57,17 +59,18 @@
let(:facts) do
facts.merge({
:is_pe => true,
:aio_agent_version => '1.0.4',
:platform_tag => tag,
:macosx_productversion_major => osmajor,
:macosx_productversion_major => osmajor
})
end

it { should compile.with_all_deps }
it { is_expected.to contain_file('/opt/puppetlabs') }
it { is_expected.to contain_file('/opt/puppetlabs/packages') }
it { is_expected.to contain_file("/opt/puppetlabs/packages/puppet-agent-#{package_version}-1.osx#{osmajor}.dmg") }
it { is_expected.to contain_package('puppet-agent').with_ensure('present') }
it { is_expected.to contain_package('puppet-agent').with_source("/opt/puppetlabs/packages/puppet-agent-#{package_version}-1.osx#{osmajor}.dmg") }
it { is_expected.to contain_file('/tmp/osx_install.sh') }
it { is_expected.to contain_exec('osx_install script') }
it { is_expected.to contain_class('puppet_agent::install::remove_packages') }
it { is_expected.to contain_class('puppet_agent::install::remove_packages_osx') }
it { is_expected.to contain_class("puppet_agent::osfamily::darwin") }
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
23 changes: 23 additions & 0 deletions templates/do_install.sh.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

# Mark install process starting
pid_path="$(dirname ${BASH_SOURCE[0]})/puppet_agent_upgrade.pid"

if [[ -f $pid_path ]]; then
rm -f $pid_path
fi
echo $$ > $pid_path

# Wait for Puppet to exit
puppet_pid=$1
while $(kill -0 ${puppet_pid:?}); do
sleep 5
done

# Install the new agent
<%= scope.function_template(["puppet_agent/#{@install_script}"]) %>

# Mark upgrade complete
if [[ -f $pid_path ]]; then
rm -f $pid_path
fi
5 changes: 5 additions & 0 deletions templates/osx_install.sh.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mountpoint="$(mktemp -d)"
package_file_path="<%= scope.lookupvar('puppet_agent::params::local_packages_dir') %>/<%= @package_file_name %>"
/usr/bin/hdiutil attach "${package_file_path}" -nobrowse -readonly -mountpoint "${mountpoint?}"
/usr/sbin/installer -pkg ${mountpoint?}/puppet-agent-*-installer.pkg -target /
/usr/bin/hdiutil detach "${mountpoint?}"
Loading