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

apt: Fix all strict variable cases. #449

Merged
merged 1 commit into from
Mar 3, 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
23 changes: 17 additions & 6 deletions manifests/params.pp
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
class apt::params {

if $caller_module_name and $caller_module_name != $module_name {
if defined('$caller_module_name') and $caller_module_name and $caller_module_name != $module_name {
fail('apt::params is a private class and cannot be accessed directly')
}

if $::osfamily != 'Debian' {
fail('This module only works on Debian or derivatives like Ubuntu')
}

$xfacts = {
'lsbdistcodename' => defined('$lsbdistcodename') ? {
true => $::lsbdistcodename,
default => undef
},
}

$root = '/etc/apt'
$provider = '/usr/bin/apt-get'
$sources_list = "${root}/sources.list"
Expand All @@ -13,10 +24,6 @@
$preferences_d = "${root}/preferences.d"
$keyserver = 'keyserver.ubuntu.com'

if $::osfamily != 'Debian' {
fail('This module only works on Debian or derivatives like Ubuntu')
}

$config_files = {
'conf' => {
'path' => $conf_d,
Expand Down Expand Up @@ -68,7 +75,7 @@
case $::lsbdistid {
'ubuntu', 'debian': {
$distid = $::lsbdistid
$distcodename = $::lsbdistcodename
$distcodename = $xfacts['lsbdistcodename']
}
'linuxmint': {
if $::lsbdistcodename == 'debian' {
Expand Down Expand Up @@ -113,5 +120,9 @@
}
}
}
'', default: {
$ppa_options = undef
$ppa_package = undef
}
}
}
12 changes: 11 additions & 1 deletion manifests/pin.pp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

define apt::pin(
$ensure = present,
$explanation = "${caller_module_name}: ${name}",
$explanation = undef,
$order = undef,
$packages = '*',
$priority = 0,
Expand All @@ -20,6 +20,16 @@
fail('Only integers are allowed in the apt::pin order param')
}

if $explanation {
$_explanation = $explanation
} else {
if defined('$caller_module_name') { # strict vars check
$_explanation = "${caller_module_name}: ${name}"
} else {
$_explanation = ": ${name}"
}
}

$pin_release_array = [
$release,
$codename,
Expand Down
4 changes: 2 additions & 2 deletions manifests/ppa.pp
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# ppa.pp
define apt::ppa(
$ensure = 'present',
$release = $::lsbdistcodename,
$options = $::apt::ppa_options,
$release = $::apt::xfacts['lsbdistcodename'],
$package_name = $::apt::ppa_package,
$package_manage = false,
) {
if ! $release {
unless $release {
fail('lsbdistcodename fact not available: release parameter required')
}

Expand Down
31 changes: 16 additions & 15 deletions manifests/source.pp
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
# source.pp
# add an apt source
define apt::source(
$comment = $name,
$ensure = present,
$location = '',
$release = $::lsbdistcodename,
$repos = 'main',
$include_src = false,
$include_deb = true,
$key = undef,
$pin = false,
$architecture = undef,
$trusted_source = false,
$comment = $name,
$ensure = present,
$location = '',
$release = $::apt::xfacts['lsbdistcodename'],
$repos = 'main',
$include_src = false,
$include_deb = true,
$key = undef,
$pin = false,
$architecture = undef,
$trusted_source = false,
) {
validate_string($architecture, $comment, $location, $release, $repos)
validate_string($architecture, $comment, $location, $repos)
validate_bool($trusted_source, $include_src, $include_deb)

if ! $release {
unless $release {
fail('lsbdistcodename fact not available: release parameter required')
}

Expand All @@ -30,6 +30,7 @@
$_key = merge($::apt::source_key_defaults, $key)
} else {
validate_string($key)
$_key = $key
}
}

Expand Down Expand Up @@ -64,9 +65,9 @@
before => $_before,
}
} else {
apt::key { "Add key: ${key} from Apt::Source ${title}":
apt::key { "Add key: ${_key} from Apt::Source ${title}":
ensure => present,
id => $key,
id => $_key,
before => $_before,
}
}
Expand Down
2 changes: 1 addition & 1 deletion 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' } }
let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy'} }

context 'defaults' do
it { is_expected.to contain_file('sources.list').that_notifies('Exec[apt_update]').only_with({
Expand Down
20 changes: 10 additions & 10 deletions spec/classes/apt_update_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
describe 'apt::update', :type => :class do
context "when update['always']=true" do
#This should completely disable all of this logic. These tests are to guarantee that we don't somehow magically change the behavior.
let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian' } }
let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy' } }
let (:pre_condition) { "class{'::apt': update => {'always' => true},}" }
it 'should trigger an apt-get update run' do
#set the apt_update exec's refreshonly attribute to false
Expand All @@ -14,15 +14,15 @@
context "when apt::update['frequency'] has the value of #{update_frequency}" 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 } }
let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :apt_update_last_success => factval, :lsbdistcodename => 'wheezy' } }
let (:pre_condition) { "class{'::apt': update => {'always' => true, 'frequency' => '#{update_frequency}'}, }" }
it 'should trigger an apt-get update run' do
# set the apt_update exec's refreshonly attribute to false
is_expected.to contain_exec('apt_update').with({'refreshonly' => false})
end
end
context 'when $::apt_update_last_success is nil' do
let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian' } }
let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy' } }
let (:pre_condition) { "class{'::apt': update => {'always' => true, 'frequency' => '#{update_frequency}'}, }" }
it 'should trigger an apt-get update run' do
#set the apt_update exec\'s refreshonly attribute to false
Expand All @@ -38,7 +38,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 } }
let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :apt_update_last_success => factval, :lsbdistcodename => 'wheezy' } }
let (:pre_condition) { "class{'::apt': update => {'always' => false, 'frequency' => 'always' },}" }
it 'should trigger an apt-get update run' do
#set the apt_update exec's refreshonly attribute to false
Expand All @@ -47,7 +47,7 @@
end
end
context 'when $::apt_update_last_success is nil' do
let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian' } }
let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy' } }
let (:pre_condition) { "class{ '::apt': update => {'always' => false, 'frequency' => 'always' },}" }
it 'should trigger an apt-get update run' do
#set the apt_update exec\'s refreshonly attribute to false
Expand All @@ -58,7 +58,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} }
let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :apt_update_last_success => factval, :lsbdistcodename => 'wheezy'} }
let (:pre_condition) { "class{ '::apt': update => {'always' => false, '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 @@ -67,7 +67,7 @@
end
end
context 'when $::apt_update_last_success is nil' do
let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian' } }
let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy' } }
let (:pre_condition) { "class{ '::apt': update => {'always' => false, '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 @@ -79,7 +79,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 } }
let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :apt_update_last_success => factval, :lsbdistcodename => 'wheezy' } }
let (:pre_condition) { "class{ '::apt': update => {'always' => false, 'frequency' => '#{update_frequency}',} }" }
it 'should trigger an apt-get update run' do
#set the apt_update exec\'s refreshonly attribute to false
Expand All @@ -88,15 +88,15 @@
end
end
context 'when the $::apt_update_last_success fact has a recent value' do
let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :apt_update_last_success => Time.now.to_i } }
let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy', :apt_update_last_success => Time.now.to_i } }
let (:pre_condition) { "class{ '::apt': update => {'always' => false, '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' } }
let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy', :apt_update_last_success => nil } }
let (:pre_condition) { "class{ '::apt': update => {'always' => false, 'frequency' => '#{update_frequency}',} }" }
it 'should trigger an apt-get update run' do
#set the apt_update exec\'s refreshonly attribute to false
Expand Down
2 changes: 1 addition & 1 deletion 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' } }
let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy' } }
let (:title) { 'my_package' }

it { is_expected.to contain_apt__params }
Expand Down
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' } }
let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy' } }
let :title do
'norecommends'
end
Expand Down
21 changes: 14 additions & 7 deletions spec/defines/key_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
require 'spec_helper'

describe 'apt::key' do
let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian' } }
let :pre_condition do
'class { "apt": }'
end

let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy' } }

GPG_KEY_ID = '47B320EB4C7C375AA9DAE1A01054B7A24BD6EC30'

let :title do
Expand All @@ -15,7 +20,7 @@
:id => title,
:ensure => 'present',
:source => nil,
:server => nil,
:server => 'keyserver.ubuntu.com',
:content => nil,
:options => nil,
})
Expand All @@ -39,7 +44,7 @@
:id => GPG_KEY_ID,
:ensure => 'present',
:source => nil,
:server => nil,
:server => 'keyserver.ubuntu.com',
:content => nil,
:options => nil,
})
Expand All @@ -59,7 +64,7 @@
:id => title,
:ensure => 'absent',
:source => nil,
:server => nil,
:server => 'keyserver.ubuntu.com',
:content => nil,
:keyserver => nil,
})
Expand Down Expand Up @@ -276,7 +281,8 @@
describe 'duplication' do
context 'two apt::key resources for same key, different titles' do
let :pre_condition do
"apt::key { 'duplicate': id => '#{title}', }"
"class { 'apt': }
apt::key { 'duplicate': id => '#{title}', }"
end

it 'contains two apt::key resources' do
Expand All @@ -295,7 +301,7 @@
:id => title,
:ensure => 'present',
:source => nil,
:server => nil,
:server => 'keyserver.ubuntu.com',
:content => nil,
:options => nil,
})
Expand All @@ -305,7 +311,8 @@

context 'two apt::key resources, different ensure' do
let :pre_condition do
"apt::key { 'duplicate': id => '#{title}', ensure => 'absent', }"
"class { 'apt': }
apt::key { 'duplicate': id => '#{title}', ensure => 'absent', }"
end
it 'informs the user of the impossibility' do
expect { subject }.to raise_error(/already ensured as absent/)
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' } }
let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy' } }
let(:title) { 'my_pin' }

context 'defaults' do
Expand Down
13 changes: 7 additions & 6 deletions spec/defines/ppa_spec.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
require 'spec_helper'
describe 'apt::ppa' do
let :pre_condition do
'class { "apt": }'
end

describe 'defaults' do
let :pre_condition do
'class { "apt": }'
end
let :facts do
{
:lsbdistrelease => '11.04',
Expand Down Expand Up @@ -190,6 +190,7 @@
:operatingsystem => 'Ubuntu',
:lsbdistid => 'Ubuntu',
:osfamily => 'Debian',
:lsbdistcodeanme => nil,
}
end
let(:title) { 'ppa:foo' }
Expand All @@ -203,10 +204,10 @@
describe 'not ubuntu' do
let :facts do
{
:lsbdistrelease => '14.04',
:lsbdistcodename => 'trusty',
:lsbdistrelease => '6.0.7',
:lsbdistcodename => 'wheezy',
:operatingsystem => 'Debian',
:lsbdistid => 'Ubuntu',
:lsbdistid => 'debian',
:osfamily => 'Debian',
}
end
Expand Down
2 changes: 1 addition & 1 deletion spec/defines/setting_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

describe 'apt::setting' do
let(:pre_condition) { 'class { "apt": }' }
let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian' } }
let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy' } }
let(:title) { 'conf-teddybear' }

let(:default_params) { { :content => 'di' } }
Expand Down
2 changes: 1 addition & 1 deletion templates/pin.pref.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ elsif @origin.length > 0
@pin = "origin #{@origin}"
end
-%>
Explanation: <%= @explanation %>
Explanation: <%= @_explanation %>
Package: <%= @packages_string %>
Pin: <%= @pin %>
Pin-Priority: <%= @priority %>