Merge pull request #511 from mhaskel/pup34_compat

Restore Puppet 3.4 and earlier compatibility
This commit is contained in:
Bryan Jen 2015-04-27 14:44:38 -07:00
commit 19b416e86e
13 changed files with 112 additions and 53 deletions

View file

@ -133,7 +133,7 @@ class apt(
notify => Exec['apt_update'],
}
contain 'apt::update'
anchor { 'apt_first': } -> Class['apt::update'] -> anchor { 'apt_last': }
# manage sources if present
if $sources {

View file

@ -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 = {

View file

@ -27,11 +27,11 @@
"requirements": [
{
"name": "pe",
"version_requirement": "3.x"
"version_requirement": ">= 3.3.0"
},
{
"name": "puppet",
"version_requirement": ">= 3.4.0"
"version_requirement": "3.x"
}
],
"dependencies": [

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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'

View file

@ -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

View file

@ -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' }

View file

@ -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' } }

View file

@ -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