Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore Puppet 3.4 and earlier compatibility #511

Merged
merged 3 commits into from
Apr 27, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
notify => Exec['apt_update'],
}

contain 'apt::update'
anchor { 'apt_first': } -> Class['apt::update'] -> anchor { 'apt_last': }

# manage sources if present
if $sources {
Expand Down
69 changes: 43 additions & 26 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,45 @@
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'
Expand Down Expand Up @@ -105,6 +118,10 @@
}
}
}

$ppa_options = undef
$ppa_package = undef

}
'ubuntu': {
$backports = {
Expand Down
4 changes: 2 additions & 2 deletions metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
"requirements": [
{
"name": "pe",
"version_requirement": "3.x"
"version_requirement": ">= 3.3.0"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? If we support OSS 3.x we should be able to support PE 3.x too no?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stdlib couldn't be upgraded to 4.x until PE 3.3

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Oh well.

},
{
"name": "puppet",
"version_requirement": ">= 3.4.0"
"version_requirement": "3.x"
}
],
"dependencies": [
Expand Down
7 changes: 7 additions & 0 deletions spec/classes/apt_backports_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
:lsbdistid => 'Debian',
:osfamily => 'Debian',
:lsbdistcodename => 'wheezy',
:puppetversion => '3.5.0',
}
end
it { is_expected.to contain_apt__source('backports').with({
Expand All @@ -27,6 +28,7 @@
:lsbdistid => 'Debian',
:osfamily => 'Debian',
:lsbdistcodename => 'squeeze',
:puppetversion => '3.5.0',
}
end
it { is_expected.to contain_apt__source('backports').with({
Expand All @@ -44,6 +46,7 @@
:lsbdistid => 'Ubuntu',
:osfamily => 'Debian',
:lsbdistcodename => 'trusty',
:puppetversion => '3.5.0',
}
end
it { is_expected.to contain_apt__source('backports').with({
Expand All @@ -61,6 +64,7 @@
:lsbdistid => 'Ubuntu',
:osfamily => 'Debian',
:lsbdistcodename => 'trusty',
:puppetversion => '3.5.0',
}
end
let(:params) do
Expand All @@ -87,6 +91,7 @@
:lsbdistid => 'Ubuntu',
:osfamily => 'Debian',
:lsbdistcodename => 'trusty',
:puppetversion => '3.5.0',
}
end
let(:params) do
Expand All @@ -112,6 +117,7 @@
:lsbdistid => 'linuxmint',
:osfamily => 'Debian',
:lsbdistcodename => 'qiana',
:puppetversion => '3.5.0',
}
end
context 'sets all the needed things' do
Expand Down Expand Up @@ -195,6 +201,7 @@
:lsbdistid => 'Ubuntu',
:osfamily => 'Debian',
:lsbdistcodename => 'trusty',
:puppetversion => '3.5.0',
}
end
context 'invalid location' do
Expand Down
8 changes: 6 additions & 2 deletions spec/classes/apt_spec.rb
Original file line number Diff line number Diff line change
@@ -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({
Expand Down Expand Up @@ -132,6 +132,7 @@
{ :osfamily => 'Debian',
:lsbdistcodename => 'precise',
:lsbdistid => 'Debian',
:puppetversion => '3.5.0',
}
end
let(:params) { { :sources => {
Expand Down Expand Up @@ -173,6 +174,7 @@
{ :osfamily => 'Debian',
:lsbdistcodename => 'precise',
:lsbdistid => 'Debian',
:puppetversion => '3.5.0',
}
end
let(:params) { { :keys => {
Expand All @@ -198,6 +200,7 @@
{ :osfamily => 'Debian',
:lsbdistcodename => 'precise',
:lsbdistid => 'ubuntu',
:puppetversion => '3.5.0',
}
end
let(:params) { { :ppas => {
Expand All @@ -214,6 +217,7 @@
{ :osfamily => 'Debian',
:lsbdistcodename => 'precise',
:lsbdistid => 'Debian',
:puppetversion => '3.5.0',
}
end
let(:params) { { :settings => {
Expand Down Expand Up @@ -264,7 +268,7 @@

context 'with unsupported osfamily' do
let :facts do
{ :osfamily => 'Darwin', }
{ :osfamily => 'Darwin', :puppetversion => '3.5.0',}
end

it do
Expand Down
14 changes: 7 additions & 7 deletions spec/classes/apt_update_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
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
Expand All @@ -14,7 +14,7 @@
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
Expand All @@ -25,7 +25,7 @@
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)
Expand All @@ -34,7 +34,7 @@
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)
Expand All @@ -46,7 +46,7 @@
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
Expand All @@ -55,15 +55,15 @@
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)
is_expected.to contain_exec('apt_update').with({'refreshonly' => true})
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
Expand Down
17 changes: 15 additions & 2 deletions spec/classes/params_spec.rb
Original file line number Diff line number Diff line change
@@ -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 }
Expand All @@ -13,7 +13,7 @@
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
Expand All @@ -23,4 +23,17 @@
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
2 changes: 1 addition & 1 deletion spec/defines/conf_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
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
Expand Down
2 changes: 1 addition & 1 deletion spec/defines/key_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
'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'

Expand Down
2 changes: 1 addition & 1 deletion spec/defines/pin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
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
Expand Down
Loading