From: Morgan Haskel Date: Mon, 27 Apr 2015 18:31:39 +0000 (-0700) Subject: Compatibility for puppet < 3.5.0 X-Git-Tag: 2.0.1~2^2~1 X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=21a2462a58938d126b66985c0b0fa1f8e09f27cd;p=puppet-modules%2Fpuppetlabs-apt.git Compatibility for puppet < 3.5.0 --- diff --git a/manifests/params.pp b/manifests/params.pp index 5a0c170..32e4dba 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -4,32 +4,45 @@ class apt::params { fail('This module only works on Debian or derivatives like Ubuntu') } - # Strict variables facts lookup compatibility - $xfacts = { - 'lsbdistcodename' => defined('$lsbdistcodename') ? { - true => $::lsbdistcodename, - default => undef, - }, - 'lsbdistrelease' => defined('$lsbdistrelease') ? { - true => $::lsbdistrelease, - default => undef, - }, - 'lsbmajdistrelease' => defined('$lsbmajdistrelease') ? { - true => $::lsbmajdistrelease, - default => undef, - }, - 'lsbdistdescription' => defined('$lsbdistdescription') ? { - true => $::lsbdistdescription, - default => undef, - }, - 'lsbminordistrelease' => defined('$lsbminordistrelease') ? { - true => $::lsbminordistrelease, - default => undef, - }, - 'lsbdistid' => defined('$lsbdistid') ? { - true => $::lsbdistid, - default => undef, - }, + # prior to puppet 3.5.0, defined couldn't test if a variable was defined + # strict variables wasn't added until 3.5.0, so this should be fine. + if versioncmp($::puppetversion, '3.5.0') < 0 { + $xfacts = { + 'lsbdistcodename' => $::lsbdistcodename, + 'lsbdistrelease' => $::lsbdistrelease, + 'lsbmajdistrelease' => $::lsbmajdistrelease, + 'lsbdistdescription' => $::lsbdistdescription, + 'lsbminordistrelease' => $::lsbminordistrelease, + 'lsbdistid' => $::lsbdistid, + } + } else { + # Strict variables facts lookup compatibility + $xfacts = { + 'lsbdistcodename' => defined('$lsbdistcodename') ? { + true => $::lsbdistcodename, + default => undef, + }, + 'lsbdistrelease' => defined('$lsbdistrelease') ? { + true => $::lsbdistrelease, + default => undef, + }, + 'lsbmajdistrelease' => defined('$lsbmajdistrelease') ? { + true => $::lsbmajdistrelease, + default => undef, + }, + 'lsbdistdescription' => defined('$lsbdistdescription') ? { + true => $::lsbdistdescription, + default => undef, + }, + 'lsbminordistrelease' => defined('$lsbminordistrelease') ? { + true => $::lsbminordistrelease, + default => undef, + }, + 'lsbdistid' => defined('$lsbdistid') ? { + true => $::lsbdistid, + default => undef, + }, + } } $root = '/etc/apt' @@ -105,6 +118,10 @@ class apt::params { } } } + + $ppa_options = undef + $ppa_package = undef + } 'ubuntu': { $backports = { diff --git a/spec/classes/apt_backports_spec.rb b/spec/classes/apt_backports_spec.rb index 1b59678..200d6f1 100644 --- a/spec/classes/apt_backports_spec.rb +++ b/spec/classes/apt_backports_spec.rb @@ -10,6 +10,7 @@ describe 'apt::backports', :type => :class do :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy', + :puppetversion => '3.5.0', } end it { is_expected.to contain_apt__source('backports').with({ @@ -27,6 +28,7 @@ describe 'apt::backports', :type => :class do :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'squeeze', + :puppetversion => '3.5.0', } end it { is_expected.to contain_apt__source('backports').with({ @@ -44,6 +46,7 @@ describe 'apt::backports', :type => :class do :lsbdistid => 'Ubuntu', :osfamily => 'Debian', :lsbdistcodename => 'trusty', + :puppetversion => '3.5.0', } end it { is_expected.to contain_apt__source('backports').with({ @@ -61,6 +64,7 @@ describe 'apt::backports', :type => :class do :lsbdistid => 'Ubuntu', :osfamily => 'Debian', :lsbdistcodename => 'trusty', + :puppetversion => '3.5.0', } end let(:params) do @@ -87,6 +91,7 @@ describe 'apt::backports', :type => :class do :lsbdistid => 'Ubuntu', :osfamily => 'Debian', :lsbdistcodename => 'trusty', + :puppetversion => '3.5.0', } end let(:params) do @@ -112,6 +117,7 @@ describe 'apt::backports', :type => :class do :lsbdistid => 'linuxmint', :osfamily => 'Debian', :lsbdistcodename => 'qiana', + :puppetversion => '3.5.0', } end context 'sets all the needed things' do @@ -195,6 +201,7 @@ describe 'apt::backports', :type => :class do :lsbdistid => 'Ubuntu', :osfamily => 'Debian', :lsbdistcodename => 'trusty', + :puppetversion => '3.5.0', } end context 'invalid location' do diff --git a/spec/classes/apt_spec.rb b/spec/classes/apt_spec.rb index a470667..7e97453 100644 --- a/spec/classes/apt_spec.rb +++ b/spec/classes/apt_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' describe 'apt' do - let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy'} } + let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy', :puppetversion => '3.5.0'} } context 'defaults' do it { is_expected.to contain_file('sources.list').that_notifies('Exec[apt_update]').only_with({ @@ -132,6 +132,7 @@ describe 'apt' do { :osfamily => 'Debian', :lsbdistcodename => 'precise', :lsbdistid => 'Debian', + :puppetversion => '3.5.0', } end let(:params) { { :sources => { @@ -173,6 +174,7 @@ describe 'apt' do { :osfamily => 'Debian', :lsbdistcodename => 'precise', :lsbdistid => 'Debian', + :puppetversion => '3.5.0', } end let(:params) { { :keys => { @@ -198,6 +200,7 @@ describe 'apt' do { :osfamily => 'Debian', :lsbdistcodename => 'precise', :lsbdistid => 'ubuntu', + :puppetversion => '3.5.0', } end let(:params) { { :ppas => { @@ -214,6 +217,7 @@ describe 'apt' do { :osfamily => 'Debian', :lsbdistcodename => 'precise', :lsbdistid => 'Debian', + :puppetversion => '3.5.0', } end let(:params) { { :settings => { @@ -264,7 +268,7 @@ describe 'apt' do context 'with unsupported osfamily' do let :facts do - { :osfamily => 'Darwin', } + { :osfamily => 'Darwin', :puppetversion => '3.5.0',} end it do diff --git a/spec/classes/apt_update_spec.rb b/spec/classes/apt_update_spec.rb index 8fba4a0..11de16a 100644 --- a/spec/classes/apt_update_spec.rb +++ b/spec/classes/apt_update_spec.rb @@ -5,7 +5,7 @@ describe 'apt::update', :type => :class do context "and apt::update['frequency']='always'" do { 'a recent run' => Time.now.to_i, 'we are due for a run' => 1406660561,'the update-success-stamp file does not exist' => -1 }.each_pair do |desc, factval| context "and $::apt_update_last_success indicates #{desc}" do - let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :apt_update_last_success => factval, :lsbdistcodename => 'wheezy' } } + let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :apt_update_last_success => factval, :lsbdistcodename => 'wheezy', :puppetversion => '3.5.0', } } let (:pre_condition) { "class{'::apt': update => {'frequency' => 'always' },}" } it 'should trigger an apt-get update run' do #set the apt_update exec's refreshonly attribute to false @@ -14,7 +14,7 @@ describe 'apt::update', :type => :class do end end context 'when $::apt_update_last_success is nil' do - let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy' } } + let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy', :puppetversion => '3.5.0', } } let (:pre_condition) { "class{ '::apt': update => {'frequency' => 'always' },}" } it 'should trigger an apt-get update run' do #set the apt_update exec\'s refreshonly attribute to false @@ -25,7 +25,7 @@ describe 'apt::update', :type => :class do context "and apt::update['frequency']='reluctantly'" do {'a recent run' => Time.now.to_i, 'we are due for a run' => 1406660561,'the update-success-stamp file does not exist' => -1 }.each_pair do |desc, factval| context "and $::apt_update_last_success indicates #{desc}" do - let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :apt_update_last_success => factval, :lsbdistcodename => 'wheezy'} } + let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :apt_update_last_success => factval, :lsbdistcodename => 'wheezy', :puppetversion => '3.5.0',} } let (:pre_condition) { "class{ '::apt': update => {'frequency' => 'reluctantly' },}" } it 'should not trigger an apt-get update run' do #don't change the apt_update exec's refreshonly attribute. (it should be true) @@ -34,7 +34,7 @@ describe 'apt::update', :type => :class do end end context 'when $::apt_update_last_success is nil' do - let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy' } } + let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy', :puppetversion => '3.5.0', } } let (:pre_condition) { "class{ '::apt': update => {'frequency' => 'reluctantly' },}" } it 'should not trigger an apt-get update run' do #don't change the apt_update exec's refreshonly attribute. (it should be true) @@ -46,7 +46,7 @@ describe 'apt::update', :type => :class do context "and apt::update['frequency'] has the value of #{update_frequency}" do { 'we are due for a run' => 1406660561,'the update-success-stamp file does not exist' => -1 }.each_pair do |desc, factval| context "and $::apt_update_last_success indicates #{desc}" do - let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :apt_update_last_success => factval, :lsbdistcodename => 'wheezy' } } + let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :apt_update_last_success => factval, :lsbdistcodename => 'wheezy', :puppetversion => '3.5.0', } } let (:pre_condition) { "class{ '::apt': update => {'frequency' => '#{update_frequency}',} }" } it 'should trigger an apt-get update run' do #set the apt_update exec\'s refreshonly attribute to false @@ -55,7 +55,7 @@ describe 'apt::update', :type => :class do end end context 'when the $::apt_update_last_success fact has a recent value' do - let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy', :apt_update_last_success => Time.now.to_i } } + let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy', :apt_update_last_success => Time.now.to_i, :puppetversion => '3.5.0', } } let (:pre_condition) { "class{ '::apt': update => {'frequency' => '#{update_frequency}',} }" } it 'should not trigger an apt-get update run' do #don't change the apt_update exec\'s refreshonly attribute. (it should be true) @@ -63,7 +63,7 @@ describe 'apt::update', :type => :class do end end context 'when $::apt_update_last_success is nil' do - let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy', :apt_update_last_success => nil } } + let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy', :apt_update_last_success => nil, :puppetversion => '3.5.0', } } let (:pre_condition) { "class{ '::apt': update => {'frequency' => '#{update_frequency}',} }" } it 'should trigger an apt-get update run' do #set the apt_update exec\'s refreshonly attribute to false diff --git a/spec/classes/params_spec.rb b/spec/classes/params_spec.rb index d90ae7e..e28296b 100644 --- a/spec/classes/params_spec.rb +++ b/spec/classes/params_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' describe 'apt::params', :type => :class do - let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy' } } + let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy', :puppetversion => '3.5.0', } } let (:title) { 'my_package' } it { is_expected.to contain_apt__params } @@ -13,7 +13,7 @@ describe 'apt::params', :type => :class do end describe "With lsb-release not installed" do - let(:facts) { { :osfamily => 'Debian' } } + let(:facts) { { :osfamily => 'Debian', :puppetversion => '3.5.0', } } let (:title) { 'my_package' } it do @@ -23,4 +23,17 @@ describe 'apt::params', :type => :class do end end + describe "With old puppet version" do + let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy', :lsbdistrelease => 'foo', :lsbdistdescription => 'bar', :lsbminordistrelease => 'baz', :lsbmajdistrelease => 'foobar', :puppetversion => '3.4.0', } } + let(:title) { 'my_package' } + it { is_expected.to contain_apt__params } + + # There are 4 resources in this class currently + # there should not be any more resources because it is a params class + # The resources are class[apt::params], class[main], class[settings], stage[main] + it "Should not contain any resources" do + expect(subject.call.resources.size).to eq(4) + end + end + end diff --git a/spec/defines/conf_spec.rb b/spec/defines/conf_spec.rb index d0c5ed9..1df0f34 100644 --- a/spec/defines/conf_spec.rb +++ b/spec/defines/conf_spec.rb @@ -3,7 +3,7 @@ describe 'apt::conf', :type => :define do let :pre_condition do 'class { "apt": }' end - let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy' } } + let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy', :puppetversion => '3.5.0', } } let :title do 'norecommends' end diff --git a/spec/defines/key_spec.rb b/spec/defines/key_spec.rb index 6725dc8..c13c255 100644 --- a/spec/defines/key_spec.rb +++ b/spec/defines/key_spec.rb @@ -5,7 +5,7 @@ describe 'apt::key' do 'class { "apt": }' end - let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy' } } + let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy', :puppetversion => '3.5.0', } } GPG_KEY_ID = '47B320EB4C7C375AA9DAE1A01054B7A24BD6EC30' diff --git a/spec/defines/pin_spec.rb b/spec/defines/pin_spec.rb index c77bb6b..7ae41a9 100644 --- a/spec/defines/pin_spec.rb +++ b/spec/defines/pin_spec.rb @@ -3,7 +3,7 @@ describe 'apt::pin', :type => :define do let :pre_condition do 'class { "apt": }' end - let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy' } } + let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy', :puppetversion => '3.5.0', } } let(:title) { 'my_pin' } context 'defaults' do diff --git a/spec/defines/ppa_spec.rb b/spec/defines/ppa_spec.rb index 7046475..63c297b 100644 --- a/spec/defines/ppa_spec.rb +++ b/spec/defines/ppa_spec.rb @@ -12,6 +12,7 @@ describe 'apt::ppa' do :operatingsystem => 'Ubuntu', :osfamily => 'Debian', :lsbdistid => 'Ubuntu', + :puppetversion => '3.5.0', } end @@ -50,6 +51,7 @@ describe 'apt::ppa' do :operatingsystem => 'Ubuntu', :osfamily => 'Debian', :lsbdistid => 'Ubuntu', + :puppetversion => '3.5.0', } end @@ -81,6 +83,7 @@ describe 'apt::ppa' do :operatingsystem => 'Ubuntu', :osfamily => 'Debian', :lsbdistid => 'Ubuntu', + :puppetversion => '3.5.0', } end let :params do @@ -119,6 +122,7 @@ describe 'apt::ppa' do :operatingsystem => 'Ubuntu', :lsbdistid => 'Ubuntu', :osfamily => 'Debian', + :puppetversion => '3.5.0', } end let :params do @@ -154,6 +158,7 @@ describe 'apt::ppa' do :operatingsystem => 'Ubuntu', :lsbdistid => 'Ubuntu', :osfamily => 'Debian', + :puppetversion => '3.5.0', } end let :params do @@ -187,6 +192,7 @@ describe 'apt::ppa' do :operatingsystem => 'Ubuntu', :lsbdistid => 'Ubuntu', :osfamily => 'Debian', + :puppetversion => '3.5.0', } end let :params do @@ -220,6 +226,7 @@ describe 'apt::ppa' do :operatingsystem => 'Ubuntu', :lsbdistid => 'Ubuntu', :osfamily => 'Debian', + :puppetversion => '3.5.0', } end let :params do @@ -251,6 +258,7 @@ describe 'apt::ppa' do :operatingsystem => 'Ubuntu', :lsbdistid => 'Ubuntu', :osfamily => 'Debian', + :puppetversion => '3.5.0', } end let(:title) { 'ppa:foo' } @@ -274,6 +282,7 @@ describe 'apt::ppa' do :lsbdistid => 'Ubuntu', :osfamily => 'Debian', :lsbdistcodeanme => nil, + :puppetversion => '3.5.0', } end let(:title) { 'ppa:foo' } @@ -292,6 +301,7 @@ describe 'apt::ppa' do :operatingsystem => 'Debian', :lsbdistid => 'debian', :osfamily => 'Debian', + :puppetversion => '3.5.0', } end let(:title) { 'ppa:foo' } diff --git a/spec/defines/setting_spec.rb b/spec/defines/setting_spec.rb index 16c8016..4ab7595 100644 --- a/spec/defines/setting_spec.rb +++ b/spec/defines/setting_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' describe 'apt::setting' do let(:pre_condition) { 'class { "apt": }' } - let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy' } } + let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy', :puppetversion => '3.5.0', } } let(:title) { 'conf-teddybear' } let(:default_params) { { :content => 'di' } } @@ -61,7 +61,7 @@ describe 'apt::setting' do apt::setting { "list-teddybear": content => "foo" } ' end - let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy' } } + let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy', :puppetversion => '3.5.0', } } let(:title) { 'conf-teddybear' } let(:default_params) { { :content => 'di' } } diff --git a/spec/defines/source_spec.rb b/spec/defines/source_spec.rb index 24f50f7..4dff24a 100644 --- a/spec/defines/source_spec.rb +++ b/spec/defines/source_spec.rb @@ -17,7 +17,8 @@ describe 'apt::source' do { :lsbdistid => 'Debian', :lsbdistcodename => 'wheezy', - :osfamily => 'Debian' + :osfamily => 'Debian', + :puppetversion => '3.5.0', } end it do @@ -31,7 +32,8 @@ describe 'apt::source' do { :lsbdistid => 'Debian', :lsbdistcodename => 'wheezy', - :osfamily => 'Debian' + :osfamily => 'Debian', + :puppetversion => '3.5.0', } end let(:params) { { :location => 'hello.there', } } @@ -48,7 +50,8 @@ describe 'apt::source' do { :lsbdistid => 'Debian', :lsbdistcodename => 'wheezy', - :osfamily => 'Debian' + :osfamily => 'Debian', + :puppetversion => '3.5.0', } end @@ -186,7 +189,8 @@ describe 'apt::source' do { :lsbdistid => 'Debian', :lsbdistcodename => 'wheezy', - :osfamily => 'Debian' + :osfamily => 'Debian', + :puppetversion => '3.5.0', } end let :params do @@ -207,7 +211,8 @@ describe 'apt::source' do { :lsbdistid => 'Debian', :lsbdistcodename => 'wheezy', - :osfamily => 'Debian' + :osfamily => 'Debian', + :puppetversion => '3.5.0', } end let :params do @@ -229,7 +234,8 @@ describe 'apt::source' do { :lsbdistid => 'Debian', :lsbdistcodename => 'wheezy', - :osfamily => 'Debian' + :osfamily => 'Debian', + :puppetversion => '3.5.0', } end let :params do @@ -249,7 +255,8 @@ describe 'apt::source' do let :facts do { :lsbdistid => 'Debian', - :osfamily => 'Debian' + :osfamily => 'Debian', + :puppetversion => '3.5.0', } end let(:params) { { :location => 'hello.there', } } @@ -266,7 +273,8 @@ describe 'apt::source' do { :lsbdistid => 'Debian', :lsbdistcodename => 'wheezy', - :osfamily => 'Debian' + :osfamily => 'Debian', + :puppetversion => '3.5.0', } end let :params do