From 8cd8b57c9e9a84a73bce0df3a8b6f85f50cce41d Mon Sep 17 00:00:00 2001 From: Gabriel Nagy Date: Fri, 19 Jun 2020 16:57:18 +0300 Subject: [PATCH] (MODULES-10713) Fix agent upgrade on Solaris 11 Due to Solaris p5p limitations, we munge dev build versions by stripping all letters (i.e.: 5.5.20.102.g9e5216a6 turns to 5.5.20.102.952166). This causes `Gem::Version` to wrongly interpret the desired version on Solaris 11, making upgrades not idempotent. Use a regex instead of `Gem::Version` to make `package_version` more like the `aio_agent_version` fact. Move this logic from the provider to the Puppet manifests in order to be able to properly spec test this. --- .../puppet_agent_end_run/puppet_agent_end_run.rb | 3 --- manifests/install.pp | 5 +++-- manifests/install/solaris.pp | 5 +++-- spec/classes/puppet_agent_osfamily_solaris_spec.rb | 3 ++- spec/classes/puppet_agent_spec.rb | 14 ++++++++++++++ 5 files changed, 22 insertions(+), 8 deletions(-) diff --git a/lib/puppet/provider/puppet_agent_end_run/puppet_agent_end_run.rb b/lib/puppet/provider/puppet_agent_end_run/puppet_agent_end_run.rb index 453b28eba..dec6a8932 100644 --- a/lib/puppet/provider/puppet_agent_end_run/puppet_agent_end_run.rb +++ b/lib/puppet/provider/puppet_agent_end_run/puppet_agent_end_run.rb @@ -27,9 +27,6 @@ def needs_upgrade? current_version = Facter.value('aio_agent_version') desired_version = @resource.name - # Ensure version has no git SHA or Debian codenames - desired_version = Gem::Version.new(desired_version).release.version - Puppet::Util::Package.versioncmp(desired_version, current_version) != 0 end end diff --git a/manifests/install.pp b/manifests/install.pp index ce02b3ae1..22168d0b0 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -86,13 +86,14 @@ $_source = undef } } + $_aio_package_version = $package_version.match(/^\d+\.\d+\.\d+(\.\d+)?/)[0] package { $::puppet_agent::package_name: ensure => $_package_version, install_options => $_install_options, provider => $_provider, source => $_source, - notify => Puppet_agent_end_run[$_package_version], + notify => Puppet_agent_end_run[$_aio_package_version], } - puppet_agent_end_run { $_package_version : } + puppet_agent_end_run { $_aio_package_version : } } } diff --git a/manifests/install/solaris.pp b/manifests/install/solaris.pp index 8f6d1e367..7ba329b3a 100644 --- a/manifests/install/solaris.pp +++ b/manifests/install/solaris.pp @@ -45,11 +45,12 @@ } } } else { + $_aio_package_version = $package_version.match(/^\d+\.\d+\.\d+(\.\d+)?/)[0] package { $::puppet_agent::package_name: ensure => $package_version, install_options => $install_options, - notify => Puppet_agent_end_run[$package_version], + notify => Puppet_agent_end_run[$_aio_package_version], } - puppet_agent_end_run { $package_version : } + puppet_agent_end_run { $_aio_package_version : } } } diff --git a/spec/classes/puppet_agent_osfamily_solaris_spec.rb b/spec/classes/puppet_agent_osfamily_solaris_spec.rb index 54be18cff..c0e1bda4d 100644 --- a/spec/classes/puppet_agent_osfamily_solaris_spec.rb +++ b/spec/classes/puppet_agent_osfamily_solaris_spec.rb @@ -69,7 +69,7 @@ def install_script(ver, arch) :clientcert => 'foo.example.vm', :env_temp_variable => '/tmp', :puppet_agent_pid => 42, - :aio_agent_version => package_version, + :aio_agent_version => '1.10.100.90', } # Strips out strings in the version string on Solaris 11, # because pkg doesn't accept strings in version numbers. This @@ -148,6 +148,7 @@ def install_script(ver, arch) 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_puppet_agent_end_run(facts[:aio_agent_version]) } it do is_expected.to contain_file("/opt/puppetlabs/packages/puppet-agent@#{sol11_package_version},5.11-1.i386.p5p").with({ 'ensure' => 'present', diff --git a/spec/classes/puppet_agent_spec.rb b/spec/classes/puppet_agent_spec.rb index faa14d0df..7fe583f2f 100644 --- a/spec/classes/puppet_agent_spec.rb +++ b/spec/classes/puppet_agent_spec.rb @@ -95,6 +95,20 @@ def global_facts(facts, os) global_facts(facts, os) end + # Windows, Solaris 10 and OS X use scripts for upgrading agents + # We test Solaris 11 in its own class + if os !~ %r{windows|solaris|darwin} + context 'when using a dev build' do + let(:params) { { :package_version => '5.2.0.100.g23e53f2' } } + it { is_expected.to contain_puppet_agent_end_run('5.2.0.100') } + end + + context 'when using a release build' do + let(:params) { { :package_version => '5.2.0' } } + it { is_expected.to contain_puppet_agent_end_run('5.2.0') } + end + end + context 'when the aio_agent_version fact is undefined' do let(:facts) do global_facts(facts, os).merge(aio_agent_version: nil)