From 988bfb9fdd7ad64b3de0c677dfe00a7910724e4e Mon Sep 17 00:00:00 2001 From: Michael Smith Date: Tue, 5 Apr 2016 14:10:03 -0700 Subject: [PATCH] (maint) Fix issue #98, don't require `pe_compiling_server_aio_build` Compilation should not require `pe_compiling_server_aio_build`. Skip calling it if not defined even if `is_pe` is true. --- manifests/params.pp | 7 +-- spec/classes/puppet_agent_spec.rb | 76 ++++++++++++++++++++++++++----- 2 files changed, 69 insertions(+), 14 deletions(-) diff --git a/manifests/params.pp b/manifests/params.pp index 5b366ece0..af7622fd4 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -77,9 +77,10 @@ # The aio puppet-agent version currently installed on the compiling master # (only used in PE) - $master_agent_version = $_is_pe ? { - true => pe_compiling_server_aio_build(), - default => undef, + if ($_is_pe and is_function_available('pe_compiling_server_aio_build')) { + $master_agent_version = pe_compiling_server_aio_build() + } else { + $master_agent_version = undef } if ($master_agent_version != undef and versioncmp("${::clientversion}", '4.0.0') < 0) { diff --git a/spec/classes/puppet_agent_spec.rb b/spec/classes/puppet_agent_spec.rb index a64a913a3..fee67f4b7 100644 --- a/spec/classes/puppet_agent_spec.rb +++ b/spec/classes/puppet_agent_spec.rb @@ -5,24 +5,78 @@ global_params = { :package_version => package_version } + def global_facts(facts, os) + facts.merge( + if os =~ /sles/ + { + :is_pe => true, + :operatingsystemmajrelease => facts[:operatingsystemrelease].split('.')[0], + } + elsif os =~ /solaris/ + { + :is_pe => true, + } + else + {} + end).merge({:servername => 'master.example.vm'}) + end - context 'supported operating systems' do + context 'supported_operating systems' do on_supported_os.each do |os, facts| context "on #{os}" do let(:facts) do - if os =~ /sles/ - facts.merge({ - :is_pe => true, - :operatingsystemmajrelease => facts[:operatingsystemrelease].split('.')[0], - }) - elsif os =~ /solaris/ - facts.merge({ - :is_pe => true, - }) + global_facts(facts, os) + end + + if os !~ /sles/ and os !~ /sles/ + context 'package_version is undef by default' do + let(:facts) do + global_facts(facts, os).merge({:is_pe => false}) + end + it { is_expected.to contain_class('puppet_agent').with_package_version(nil) } + end + end + + context 'package_version is undef if pe_compiling_server_aio_build is not defined' do + let(:facts) do + global_facts(facts, os).merge({:is_pe => true}) + end + it { is_expected.to contain_class('puppet_agent').with_package_version(nil) } + end + end + end + end + + context 'supported_operating systems' do + on_supported_os.each do |os, facts| + context "on #{os}" do + let(:facts) do + global_facts(facts, os).merge({:is_pe => true}) + end + + before(:each) do + Puppet::Parser::Functions.newfunction(:pe_build_version, :type => :rvalue) {|args| '4.0.0'} + Puppet::Parser::Functions.newfunction(:pe_compiling_server_aio_build, :type => :rvalue) {|args| '1.2.5'} + Puppet::Parser::Functions.newfunction(:pe_compiling_server_version, :type => :rvalue) {|args| '2.2.0'} + end + + context 'package_version is initialized automatically' do + if Puppet.version < '4.0.0' + it { is_expected.to contain_class('puppet_agent').with_package_version('1.2.5') } else - facts + it { is_expected.to contain_class('puppet_agent').with_package_version(nil) } end end + end + end + end + + context 'supported operating systems' do + on_supported_os.each do |os, facts| + context "on #{os}" do + let(:facts) do + global_facts(facts, os) + end before(:each) do if os =~ /sles/ || os =~ /solaris/