Skip to content

Commit

Permalink
(maint) Fix handling dev versions on Solaris 11
Browse files Browse the repository at this point in the history
Version numbers for development packages on Solaris 11 need to be
munged, which happened for the file name. However Solaris 11
puppet-agent upgrades use the version number, which was not correctly
munged. Fix that, and add testing for development version numbers.
  • Loading branch information
Michael Smith committed Apr 14, 2016
1 parent a037448 commit 50ec7f9
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 19 deletions.
16 changes: 12 additions & 4 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,11 @@
$_package_file_name = "${puppet_agent::package_name}-${package_version}-1.${pkg_arch}.pkg.gz"
} elsif $::operatingsystemmajrelease == '11' {
# Strip letters from development builds. Unique to Solaris 11 packaging.
$_version_without_letters = regsubst($package_version, /[a-zA-Z]/, '', 'G')
$_solaris_version = regsubst($_version_without_letters, /(^-|-$)/, '', 'G')
# Need to pass the regex as strings for Puppet 3 compatibility.
$_version_without_letters = regsubst($package_version, '[a-zA-Z]', '', 'G')
$_package_version = regsubst($_version_without_letters, '(^-|-$)', '', 'G')

$_package_file_name = "${puppet_agent::package_name}@${_solaris_version},5.11-1.${pkg_arch}.p5p"
$_package_file_name = "${puppet_agent::package_name}@${_package_version},5.11-1.${pkg_arch}.p5p"
}
} elsif $::operatingsystem == 'Darwin' and $::macosx_productversion_major =~ /10\.[9,10,11]/ {
$_package_file_name = "${puppet_agent::package_name}-${package_version}-1.osx${$::macosx_productversion_major}.dmg"
Expand All @@ -90,13 +91,20 @@
$_package_file_name = undef
}

# Allow for normalizing package_version for the package provider via _package_version.
# This only needs to be passed through to install, as elsewhere we want to
# use the full version string for comparisons.
if $_package_version == undef {
$_package_version = $package_version
}

class { '::puppet_agent::prepare':
package_file_name => $_package_file_name,
package_version => $package_version,
} ->
class { '::puppet_agent::install':
package_file_name => $_package_file_name,
package_version => $package_version,
package_version => $_package_version,
}

contain '::puppet_agent::prepare'
Expand Down
42 changes: 27 additions & 15 deletions spec/classes/puppet_agent_osfamily_solaris_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
:clientcert => 'foo.example.vm',
}

package_version = '1.2.5'
package_version = '1.2.5.90.g93a35da'
# Strips out strings in the version string on Solaris 11,
# because pkg doesn't accept strings in version numbers. This
# is how developer builds are labelled.
sol11_package_version = '1.2.5.90.9335'
pe_version = '2000.0.0'
if Puppet.version >= "4.0.0"
let(:params) do
Expand Down Expand Up @@ -50,6 +54,10 @@
Puppet::Parser::Functions.newfunction(:pe_compiling_server_aio_build, :type => :rvalue) do |args|
package_version
end

# Ensure we get a versionable package provider
pkg = Puppet::Type.type(:package)
pkg.stubs(:defaultprovider).returns(pkg.provider(:pkg))
end

context "when Solaris 11 i386" do
Expand All @@ -65,17 +73,17 @@
it { is_expected.to contain_file('/opt/puppetlabs') }
it { is_expected.to contain_file('/opt/puppetlabs/packages') }
it do
is_expected.to contain_file("/opt/puppetlabs/packages/puppet-agent@#{package_version},5.11-1.i386.p5p").with_ensure('present')
is_expected.to contain_file("/opt/puppetlabs/packages/puppet-agent@#{package_version},5.11-1.i386.p5p").with({
'source' => "puppet:///pe_packages/#{pe_version}/solaris-11-i386/puppet-agent@#{package_version},5.11-1.i386.p5p",
is_expected.to contain_file("/opt/puppetlabs/packages/puppet-agent@#{sol11_package_version},5.11-1.i386.p5p").with({
'ensure' => 'present',
'source' => "puppet:///pe_packages/#{pe_version}/solaris-11-i386/puppet-agent@#{sol11_package_version},5.11-1.i386.p5p",
})
end

it do
is_expected.to contain_exec('puppet_agent remove existing repo').with_command("rm -rf '/etc/puppetlabs/installer/solaris.repo'")
is_expected.to contain_exec('puppet_agent create repo').with_command('pkgrepo create /etc/puppetlabs/installer/solaris.repo')
is_expected.to contain_exec('puppet_agent set publisher').with_command('pkgrepo set -s /etc/puppetlabs/installer/solaris.repo publisher/prefix=puppetlabs.com')
is_expected.to contain_exec('puppet_agent copy packages').with_command("pkgrecv -s file:///opt/puppetlabs/packages/puppet-agent@1.2.5,5.11-1.i386.p5p -d /etc/puppetlabs/installer/solaris.repo '*'")
is_expected.to contain_exec('puppet_agent copy packages').with_command("pkgrecv -s file:///opt/puppetlabs/packages/puppet-agent@#{sol11_package_version},5.11-1.i386.p5p -d /etc/puppetlabs/installer/solaris.repo '*'")
is_expected.to contain_exec('puppet_agent ensure pkgrepo is up-to-date').with_command('pkgrepo refresh -s /etc/puppetlabs/installer/solaris.repo')
end

Expand Down Expand Up @@ -115,7 +123,7 @@
else
it do
is_expected.not_to contain_transition("remove puppet-agent")
is_expected.to contain_package('puppet-agent').with_ensure(package_version)
is_expected.to contain_package('puppet-agent').with_ensure(sol11_package_version)
end
end
end
Expand All @@ -134,17 +142,17 @@
it { is_expected.to contain_file('/opt/puppetlabs') }
it { is_expected.to contain_file('/opt/puppetlabs/packages') }
it do
is_expected.to contain_file('/opt/puppetlabs/packages/puppet-agent@1.2.5,5.11-1.sparc.p5p').with_ensure('present')
is_expected.to contain_file('/opt/puppetlabs/packages/puppet-agent@1.2.5,5.11-1.sparc.p5p').with({
'source' => "puppet:///pe_packages/#{pe_version}/solaris-11-sparc/puppet-agent@#{package_version},5.11-1.sparc.p5p",
is_expected.to contain_file("/opt/puppetlabs/packages/puppet-agent@#{sol11_package_version},5.11-1.sparc.p5p").with({
'ensure' => 'present',
'source' => "puppet:///pe_packages/#{pe_version}/solaris-11-sparc/puppet-agent@#{sol11_package_version},5.11-1.sparc.p5p",
})
end

it do
is_expected.to contain_exec('puppet_agent remove existing repo').with_command("rm -rf '/etc/puppetlabs/installer/solaris.repo'")
is_expected.to contain_exec('puppet_agent create repo').with_command('pkgrepo create /etc/puppetlabs/installer/solaris.repo')
is_expected.to contain_exec('puppet_agent set publisher').with_command('pkgrepo set -s /etc/puppetlabs/installer/solaris.repo publisher/prefix=puppetlabs.com')
is_expected.to contain_exec('puppet_agent copy packages').with_command("pkgrecv -s file:///opt/puppetlabs/packages/puppet-agent@1.2.5,5.11-1.sparc.p5p -d /etc/puppetlabs/installer/solaris.repo '*'")
is_expected.to contain_exec('puppet_agent copy packages').with_command("pkgrecv -s file:///opt/puppetlabs/packages/puppet-agent@#{sol11_package_version},5.11-1.sparc.p5p -d /etc/puppetlabs/installer/solaris.repo '*'")
is_expected.to contain_exec('puppet_agent ensure pkgrepo is up-to-date').with_command('pkgrepo refresh -s /etc/puppetlabs/installer/solaris.repo')

end
Expand Down Expand Up @@ -185,7 +193,7 @@
else
it do
is_expected.not_to contain_transition("remove puppet-agent")
is_expected.to contain_package('puppet-agent').with_ensure(package_version)
is_expected.to contain_package('puppet-agent').with_ensure(sol11_package_version)
end
end
end
Expand All @@ -203,8 +211,10 @@
it { is_expected.to contain_file('/opt/puppetlabs') }
it { is_expected.to contain_file('/opt/puppetlabs/packages') }
it do
is_expected.to contain_file("/opt/puppetlabs/packages/puppet-agent-#{package_version}-1.i386.pkg.gz").with_ensure('present')
is_expected.to contain_file("/opt/puppetlabs/packages/puppet-agent-#{package_version}-1.i386.pkg.gz").with_source("puppet:///pe_packages/#{pe_version}/solaris-10-i386/puppet-agent-#{package_version}-1.i386.pkg.gz")
is_expected.to contain_file("/opt/puppetlabs/packages/puppet-agent-#{package_version}-1.i386.pkg.gz").with({
'ensure' => 'present',
'source' => "puppet:///pe_packages/#{pe_version}/solaris-10-i386/puppet-agent-#{package_version}-1.i386.pkg.gz"
})
end

it { is_expected.to contain_file('/opt/puppetlabs/packages/solaris-noask').with_source("puppet:///pe_packages/#{pe_version}/solaris-10-i386/solaris-noask") }
Expand Down Expand Up @@ -283,8 +293,10 @@

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

it { is_expected.to contain_file('/opt/puppetlabs/packages/solaris-noask').with_source("puppet:///pe_packages/#{pe_version}/solaris-10-sparc/solaris-noask") }
Expand Down

0 comments on commit 50ec7f9

Please sign in to comment.