Skip to content

Commit

Permalink
Convert to use apt::setting instead of file resources
Browse files Browse the repository at this point in the history
This adds consistency across the module
  • Loading branch information
Morgan Haskel committed Feb 25, 2015
1 parent 1c0c6f1 commit 351c8d5
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 70 deletions.
15 changes: 7 additions & 8 deletions manifests/conf.pp
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
define apt::conf (
$content,
$ensure = present,
$priority = '50'
$priority = '50',
) {

file { "${apt::conf_d}/${priority}${name}":
ensure => $ensure,
content => template('apt/_header.erb', 'apt/conf.erb'),
owner => root,
group => root,
mode => '0644',
apt::setting { "conf-${name}":
ensure => $ensure,
base_name => $name,
setting_type => 'conf',
priority => $priority,
content => template('apt/_header.erb', 'apt/conf.erb'),
}
}
11 changes: 5 additions & 6 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,11 @@
}
}

file { '/etc/apt/apt.conf.d/15update-stamp':
ensure => 'file',
content => template('apt/_header.erb', 'apt/15update-stamp.erb'),
group => 'root',
mode => '0644',
owner => 'root',
apt::setting { 'conf-update-stamp':
base_name => 'update-stamp',
setting_type => 'conf',
priority => 15,
content => template('apt/_header.erb', 'apt/15update-stamp.erb'),
}

file { 'sources.list':
Expand Down
22 changes: 8 additions & 14 deletions manifests/pin.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
define apt::pin(
$ensure = present,
$explanation = "${caller_module_name}: ${name}",
$order = '',
$order = undef,

This comment has been minimized.

Copy link
@Vincent--

Vincent-- Aug 24, 2015

With that change, apt::setting is called with "undef" priority param, so it seems that the default value is used ('50'). Due to that, after the upgrade of the module from 1.8.0 to 2.1.1, all my existing pref files have been kept but new files with 50xxx have been created.

I think the old behavior should be kept or the old files should be renamed...
Same issue with the *.pref extension (see #554 )

$packages = '*',
$priority = 0,
$release = '', # a=
Expand All @@ -16,7 +16,7 @@
$originator = '', # o=
$label = '' # l=
) {
if $order != '' and !is_integer($order) {
if $order and !is_integer($order) {
fail('Only integers are allowed in the apt::pin order param')
}

Expand Down Expand Up @@ -52,7 +52,6 @@
}
}


# According to man 5 apt_preferences:
# The files have either no or "pref" as filename extension
# and only contain alphanumeric, hyphen (-), underscore (_) and period
Expand All @@ -62,16 +61,11 @@
# be silently ignored.
$file_name = regsubst($title, '[^0-9a-z\-_\.]', '_', 'IG')

$path = $order ? {
'' => "${::apt::preferences_d}/${file_name}.pref",
default => "${::apt::preferences_d}/${order}-${file_name}.pref",
}
file { "${file_name}.pref":
ensure => $ensure,
path => $path,
owner => root,
group => root,
mode => '0644',
content => template('apt/_header.erb', 'apt/pin.pref.erb'),
apt::setting { "pref-${file_name}":
ensure => $ensure,
base_name => $file_name,
setting_type => 'pref',
priority => $order,
content => template('apt/_header.erb', 'apt/pin.pref.erb'),
}
}
7 changes: 4 additions & 3 deletions manifests/source.pp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@
fail('lsbdistcodename fact not available: release parameter required')
}

apt::setting { $name:
apt::setting { "list-${name}":
ensure => $ensure,
base_name => $name,
setting_type => 'list',
content => template('apt/_header.erb', 'apt/source.list.erb'),
notify => Exec['apt_update'],
Expand All @@ -38,7 +39,7 @@
apt::pin { $name:
ensure => $ensure,
priority => $pin,
before => Apt::Setting[$name],
before => Apt::Setting["list-${name}"],
origin => $host,
}
}
Expand All @@ -51,7 +52,7 @@
key_server => $key_server,
key_content => $key_content,
key_source => $key_source,
before => Apt::Setting[$name],
before => Apt::Setting["list-${name}"],
}
}

Expand Down
4 changes: 2 additions & 2 deletions spec/classes/apt_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
} } }

it {
is_expected.to contain_apt__setting('debian_unstable').with({
is_expected.to contain_apt__setting('list-debian_unstable').with({
'ensure' => 'present',
'notify' => 'Exec[apt_update]',
})
Expand All @@ -120,7 +120,7 @@
it { is_expected.to contain_file('/etc/apt/sources.list.d/debian_unstable.list').with_content(/^deb-src http:\/\/debian.mirror.iweb.ca\/debian\/ unstable main contrib non-free$/) }

it {
is_expected.to contain_apt__setting('puppetlabs').with({
is_expected.to contain_apt__setting('list-puppetlabs').with({
'ensure' => 'present',
'notify' => 'Exec[apt_update]',
})
Expand Down
49 changes: 19 additions & 30 deletions spec/defines/pin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@
let(:title) { 'my_pin' }

context 'defaults' do
it { is_expected.to contain_file("my_pin.pref").with_content(/Explanation: : my_pin\nPackage: \*\nPin: release a=my_pin\nPin-Priority: 0\n/)}
it { is_expected.to contain_file("my_pin.pref").with({
'ensure' => 'present',
'path' => '/etc/apt/preferences.d/my_pin.pref',
'owner' => 'root',
'group' => 'root',
'mode' => '0644',
it { is_expected.to contain_apt__setting("pref-my_pin").with_content(/Explanation: : my_pin\nPackage: \*\nPin: release a=my_pin\nPin-Priority: 0\n/)}
it { is_expected.to contain_apt__setting("pref-my_pin").with({
'setting_type' => 'pref',
'base_name' => 'my_pin',
})
}
end
Expand All @@ -25,13 +22,10 @@
'version' => '1',
}
end
it { is_expected.to contain_file("my_pin.pref").with_content(/Explanation: : my_pin\nPackage: vim\nPin: version 1\nPin-Priority: 0\n/)}
it { is_expected.to contain_file("my_pin.pref").with({
'ensure' => 'present',
'path' => '/etc/apt/preferences.d/my_pin.pref',
'owner' => 'root',
'group' => 'root',
'mode' => '0644',
it { is_expected.to contain_apt__setting("pref-my_pin").with_content(/Explanation: : my_pin\nPackage: vim\nPin: version 1\nPin-Priority: 0\n/)}
it { is_expected.to contain_apt__setting("pref-my_pin").with({
'setting_type' => 'pref',
'base_name' => 'my_pin',
})
}
end
Expand All @@ -43,13 +37,10 @@
'origin' => 'test',
}
end
it { is_expected.to contain_file("my_pin.pref").with_content(/Explanation: : my_pin\nPackage: vim\nPin: origin test\nPin-Priority: 0\n/)}
it { is_expected.to contain_file("my_pin.pref").with({
'ensure' => 'present',
'path' => '/etc/apt/preferences.d/my_pin.pref',
'owner' => 'root',
'group' => 'root',
'mode' => '0644',
it { is_expected.to contain_apt__setting("pref-my_pin").with_content(/Explanation: : my_pin\nPackage: vim\nPin: origin test\nPin-Priority: 0\n/)}
it { is_expected.to contain_apt__setting("pref-my_pin").with({
'setting_type' => 'pref',
'base_name' => 'my_pin',
})
}
end
Expand All @@ -68,13 +59,11 @@
'priority' => 10,
}
end
it { is_expected.to contain_file("my_pin.pref").with_content(/Explanation: foo\nPackage: \*\nPin: release a=1, n=bar, v=2, c=baz, o=foobar, l=foobaz\nPin-Priority: 10\n/) }
it { is_expected.to contain_file("my_pin.pref").with({
'ensure' => 'present',
'path' => '/etc/apt/preferences.d/99-my_pin.pref',
'owner' => 'root',
'group' => 'root',
'mode' => '0644',
it { is_expected.to contain_apt__setting("pref-my_pin").with_content(/Explanation: foo\nPackage: \*\nPin: release a=1, n=bar, v=2, c=baz, o=foobar, l=foobaz\nPin-Priority: 10\n/) }
it { is_expected.to contain_apt__setting("pref-my_pin").with({
'setting_type' => 'pref',
'base_name' => 'my_pin',
'priority' => 99,
})
}
end
Expand All @@ -85,15 +74,15 @@
'ensure' => 'absent'
}
end
it { is_expected.to contain_file("my_pin.pref").with({
it { is_expected.to contain_apt__setting("pref-my_pin").with({
'ensure' => 'absent',
})
}
end

context 'bad characters' do
let(:title) { 'such bad && wow!' }
it { is_expected.to contain_file("such__bad____wow_.pref") }
it { is_expected.to contain_apt__setting("pref-such__bad____wow_") }
end

describe 'validation' do
Expand Down
14 changes: 7 additions & 7 deletions spec/defines/source_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
}
end

it { is_expected.to contain_apt__setting('my_source').that_notifies('Exec[apt_update]').with({
it { is_expected.to contain_apt__setting('list-my_source').that_notifies('Exec[apt_update]').with({
'ensure' => 'present',
}).with_content(/# my_source\ndeb-src wheezy main\n/)
}
Expand Down Expand Up @@ -58,19 +58,19 @@
}
end

it { is_expected.to contain_apt__setting('my_source').that_notifies('Exec[apt_update]').with({
it { is_expected.to contain_apt__setting('list-my_source').that_notifies('Exec[apt_update]').with({
'ensure' => 'present',
}).with_content(/# foo\ndeb \[arch=x86_64 trusted=yes\] http:\/\/debian\.mirror\.iweb\.ca\/debian\/ sid testing\n/).without_content(/deb-src/)
}

it { is_expected.to contain_apt__pin('my_source').that_comes_before('Apt::Setting[my_source]').with({
it { is_expected.to contain_apt__pin('my_source').that_comes_before('Apt::Setting[list-my_source]').with({
'ensure' => 'present',
'priority' => '10',
'origin' => 'debian.mirror.iweb.ca',
})
}

it { is_expected.to contain_apt__key("Add key: #{GPG_KEY_ID} from Apt::Source my_source").that_comes_before('Apt::Setting[my_source]').with({
it { is_expected.to contain_apt__key("Add key: #{GPG_KEY_ID} from Apt::Source my_source").that_comes_before('Apt::Setting[list-my_source]').with({
'ensure' => 'present',
'key' => GPG_KEY_ID,
'key_server' => 'pgp.mit.edu',
Expand All @@ -95,7 +95,7 @@
}
end

it { is_expected.to contain_apt__setting('my_source').that_notifies('Exec[apt_update]').with({
it { is_expected.to contain_apt__setting('list-my_source').that_notifies('Exec[apt_update]').with({
'ensure' => 'present',
}).with_content(/# my_source\ndeb \[trusted=yes\] wheezy main\n/)
}
Expand All @@ -117,7 +117,7 @@
}
end

it { is_expected.to contain_apt__setting('my_source').that_notifies('Exec[apt_update]').with({
it { is_expected.to contain_apt__setting('list-my_source').that_notifies('Exec[apt_update]').with({
'ensure' => 'present',
}).with_content(/# my_source\ndeb-src \[arch=x86_64 \] wheezy main\n/)
}
Expand All @@ -137,7 +137,7 @@
}
end

it { is_expected.to contain_apt__setting('my_source').that_notifies('Exec[apt_update]').with({
it { is_expected.to contain_apt__setting('list-my_source').that_notifies('Exec[apt_update]').with({
'ensure' => 'absent'
})
}
Expand Down

0 comments on commit 351c8d5

Please sign in to comment.