Merge pull request #432 from mhaskel/source_cleanup

Cleanup for `apt::source`
This commit is contained in:
Daniele Sluijters 2015-02-22 00:30:36 +01:00
commit c4981a0739
4 changed files with 29 additions and 63 deletions

View file

@ -1,13 +1,12 @@
# source.pp # source.pp
# add an apt source # add an apt source
define apt::source( define apt::source(
$comment = $name, $comment = $name,
$ensure = present, $ensure = present,
$location = '', $location = '',
$release = 'UNDEF', $release = $::lsbdistcodename,
$repos = 'main', $repos = 'main',
$include_src = true, $include_src = false,
$include_deb = true, $include_deb = true,
$key = undef, $key = undef,
$key_server = 'keyserver.ubuntu.com', $key_server = 'keyserver.ubuntu.com',
@ -17,30 +16,20 @@ define apt::source(
$architecture = undef, $architecture = undef,
$trusted_source = false, $trusted_source = false,
) { ) {
validate_string($architecture) validate_string($architecture, $comment, $location, $release, $repos, $key_server)
validate_bool($trusted_source) validate_bool($trusted_source, $include_src, $include_deb)
if $release == 'UNDEF' { if ! $release {
if $::lsbdistcodename == undef { fail('lsbdistcodename fact not available: release parameter required')
fail('lsbdistcodename fact not available: release parameter required')
} else {
$release_real = $::lsbdistcodename
}
} else {
$release_real = $release
} }
file { "${name}.list": apt::setting { $name:
ensure => $ensure, ensure => $ensure,
path => "${::apt::sources_list_d}/${name}.list", setting_type => 'list',
owner => root, content => template('apt/_header.erb', 'apt/source.list.erb'),
group => root, notify => Exec['apt_update'],
mode => '0644',
content => template('apt/_header.erb', 'apt/source.list.erb'),
notify => Exec['apt_update'],
} }
if ($pin != false) { if ($pin != false) {
# Get the host portion out of the url so we can pin to origin # Get the host portion out of the url so we can pin to origin
$url_split = split($location, '/') $url_split = split($location, '/')
@ -49,7 +38,7 @@ define apt::source(
apt::pin { $name: apt::pin { $name:
ensure => $ensure, ensure => $ensure,
priority => $pin, priority => $pin,
before => File["${name}.list"], before => Apt::Setting[$name],
origin => $host, origin => $host,
} }
} }
@ -62,7 +51,7 @@ define apt::source(
key_server => $key_server, key_server => $key_server,
key_content => $key_content, key_content => $key_content,
key_source => $key_source, key_source => $key_source,
before => File["${name}.list"], before => Apt::Setting[$name],
} }
} }

View file

@ -110,32 +110,23 @@ describe 'apt', :type => :class do
} } } } } }
it { it {
should contain_file('debian_unstable.list').with({ should contain_apt__setting('debian_unstable').with({
'ensure' => 'present', 'ensure' => 'present',
'path' => '/etc/apt/sources.list.d/debian_unstable.list',
'owner' => 'root',
'group' => 'root',
'mode' => '0644',
'notify' => 'Exec[apt_update]', 'notify' => 'Exec[apt_update]',
}) })
} }
it { should contain_file('debian_unstable.list').with_content(/^deb http:\/\/debian.mirror.iweb.ca\/debian\/ unstable main contrib non-free$/) } it { should contain_file('/etc/apt/sources.list.d/debian_unstable.list').with_content(/^deb http:\/\/debian.mirror.iweb.ca\/debian\/ unstable main contrib non-free$/) }
it { should contain_file('debian_unstable.list').with_content(/^deb-src http:\/\/debian.mirror.iweb.ca\/debian\/ unstable main contrib non-free$/) } it { should 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 { it {
should contain_file('puppetlabs.list').with({ should contain_apt__setting('puppetlabs').with({
'ensure' => 'present', 'ensure' => 'present',
'path' => '/etc/apt/sources.list.d/puppetlabs.list',
'owner' => 'root',
'group' => 'root',
'mode' => '0644',
'notify' => 'Exec[apt_update]', 'notify' => 'Exec[apt_update]',
}) })
} }
it { should contain_file('puppetlabs.list').with_content(/^deb http:\/\/apt.puppetlabs.com precise main$/) } it { should contain_file('/etc/apt/sources.list.d/puppetlabs.list').with_content(/^deb http:\/\/apt.puppetlabs.com precise main$/) }
it { should contain_file('puppetlabs.list').with_content(/^deb-src http:\/\/apt.puppetlabs.com precise main$/) }
end end
describe 'failing tests' do describe 'failing tests' do

View file

@ -23,15 +23,12 @@ describe 'apt::source', :type => :define do
let :params do let :params do
{ {
'include_deb' => false, 'include_deb' => false,
'include_src' => true,
} }
end end
it { is_expected.to contain_file('my_source.list').that_notifies('Exec[apt_update]').with({ it { is_expected.to contain_apt__setting('my_source').that_notifies('Exec[apt_update]').with({
'ensure' => 'present', 'ensure' => 'present',
'path' => '/etc/apt/sources.list.d/my_source.list',
'owner' => 'root',
'group' => 'root',
'mode' => '0644',
}).with_content(/# my_source\ndeb-src wheezy main\n/) }).with_content(/# my_source\ndeb-src wheezy main\n/)
} }
end end
@ -61,23 +58,19 @@ describe 'apt::source', :type => :define do
} }
end end
it { is_expected.to contain_file('my_source.list').that_notifies('Exec[apt_update]').with({ it { is_expected.to contain_apt__setting('my_source').that_notifies('Exec[apt_update]').with({
'ensure' => 'present', 'ensure' => 'present',
'path' => '/etc/apt/sources.list.d/my_source.list',
'owner' => 'root',
'group' => 'root',
'mode' => '0644',
}).with_content(/# foo\ndeb \[arch=x86_64 trusted=yes\] http:\/\/debian\.mirror\.iweb\.ca\/debian\/ sid testing\n/).without_content(/deb-src/) }).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('File[my_source.list]').with({ it { is_expected.to contain_apt__pin('my_source').that_comes_before('Apt::Setting[my_source]').with({
'ensure' => 'present', 'ensure' => 'present',
'priority' => '10', 'priority' => '10',
'origin' => 'debian.mirror.iweb.ca', '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('File[my_source.list]').with({ 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({
'ensure' => 'present', 'ensure' => 'present',
'key' => GPG_KEY_ID, 'key' => GPG_KEY_ID,
'key_server' => 'pgp.mit.edu', 'key_server' => 'pgp.mit.edu',
@ -102,12 +95,8 @@ describe 'apt::source', :type => :define do
} }
end end
it { is_expected.to contain_file('my_source.list').that_notifies('Exec[apt_update]').with({ it { is_expected.to contain_apt__setting('my_source').that_notifies('Exec[apt_update]').with({
'ensure' => 'present', 'ensure' => 'present',
'path' => '/etc/apt/sources.list.d/my_source.list',
'owner' => 'root',
'group' => 'root',
'mode' => '0644',
}).with_content(/# my_source\ndeb \[trusted=yes\] wheezy main\n/) }).with_content(/# my_source\ndeb \[trusted=yes\] wheezy main\n/)
} }
end end
@ -123,16 +112,13 @@ describe 'apt::source', :type => :define do
let :params do let :params do
{ {
'include_deb' => false, 'include_deb' => false,
'include_src' => true,
'architecture' => 'x86_64', 'architecture' => 'x86_64',
} }
end end
it { is_expected.to contain_file('my_source.list').that_notifies('Exec[apt_update]').with({ it { is_expected.to contain_apt__setting('my_source').that_notifies('Exec[apt_update]').with({
'ensure' => 'present', 'ensure' => 'present',
'path' => '/etc/apt/sources.list.d/my_source.list',
'owner' => 'root',
'group' => 'root',
'mode' => '0644',
}).with_content(/# my_source\ndeb-src \[arch=x86_64 \] wheezy main\n/) }).with_content(/# my_source\ndeb-src \[arch=x86_64 \] wheezy main\n/)
} }
end end
@ -151,7 +137,7 @@ describe 'apt::source', :type => :define do
} }
end end
it { is_expected.to contain_file('my_source.list').that_notifies('Exec[apt_update]').with({ it { is_expected.to contain_apt__setting('my_source').that_notifies('Exec[apt_update]').with({
'ensure' => 'absent' 'ensure' => 'absent'
}) })
} }

View file

@ -2,10 +2,10 @@
<%- if @include_deb then -%> <%- if @include_deb then -%>
deb <%- if @architecture or @trusted_source -%> deb <%- if @architecture or @trusted_source -%>
[<%- if @architecture %>arch=<%= @architecture %> <% end %><% if @trusted_source %>trusted=yes<% end -%> [<%- if @architecture %>arch=<%= @architecture %> <% end %><% if @trusted_source %>trusted=yes<% end -%>
] <%- end %><%= @location %> <%= @release_real %> <%= @repos %> ] <%- end %><%= @location %> <%= @release %> <%= @repos %>
<%- end -%> <%- end -%>
<%- if @include_src then -%> <%- if @include_src then -%>
deb-src <%- if @architecture or @trusted_source -%> deb-src <%- if @architecture or @trusted_source -%>
[<%- if @architecture %>arch=<%= @architecture %> <% end %><% if @trusted_source %>trusted=yes<% end -%> [<%- if @architecture %>arch=<%= @architecture %> <% end %><% if @trusted_source %>trusted=yes<% end -%>
] <%- end %><%= @location %> <%= @release_real %> <%= @repos %> ] <%- end %><%= @location %> <%= @release %> <%= @repos %>
<%- end -%> <%- end -%>