Skip to content

Commit

Permalink
Merge pull request #451 from puppetlabs/daenney/consolidate-include
Browse files Browse the repository at this point in the history
apt::source: Merge `include_*` options into hash.
  • Loading branch information
Morgan Haskel committed Mar 5, 2015
2 parents acd280b + a220dcf commit 2a28938
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 23 deletions.
5 changes: 5 additions & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@
'source' => undef,
}

$include_defaults = {
'deb' => true,
'src' => false,
}

case $xfacts['lsbdistid'] {
'ubuntu', 'debian': {
$distid = $xfacts['lsbdistid']
Expand Down
7 changes: 4 additions & 3 deletions manifests/source.pp
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,22 @@
$location = '',
$release = $::apt::xfacts['lsbdistcodename'],
$repos = 'main',
$include_src = false,
$include_deb = true,
$include = {},
$key = undef,
$pin = false,
$architecture = undef,
$trusted_source = false,
) {
validate_string($architecture, $comment, $location, $repos)
validate_bool($trusted_source, $include_src, $include_deb)
validate_bool($trusted_source)
validate_hash($include)

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

$_before = Apt::Setting["list-${title}"]
$_include = merge($::apt::include_defaults, $include)

if $key {
if is_hash($key) {
Expand Down
2 changes: 1 addition & 1 deletion spec/classes/apt_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
'repos' => 'main contrib non-free',
'key' => { 'id' => '55BE302B', 'server' => 'subkeys.pgp.net' },
'pin' => '-10',
'include_src' => true,
'include' => {'src' => true,},
},
'puppetlabs' => {
'location' => 'http://apt.puppetlabs.com',
Expand Down
21 changes: 4 additions & 17 deletions spec/defines/source_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
'my_source'
end

context 'mostly defaults' do
context 'defaults' do
let :facts do
{
:lsbdistid => 'Debian',
Expand All @@ -20,17 +20,9 @@
}
end

let :params do
{
:include_deb => false,
:include_src => true,
}
end

it { is_expected.to contain_apt__setting('list-my_source').with({
:ensure => 'present',
}).with_content(/# my_source\ndeb-src wheezy main\n/)

:ensure => 'present',
}).without_content(/# my_source\ndeb-src wheezy main\n/)
}
end

Expand All @@ -49,7 +41,6 @@
:location => 'http://debian.mirror.iweb.ca/debian/',
:release => 'sid',
:repos => 'testing',
:include_src => false,
:key => GPG_KEY_ID,
:pin => '10',
:architecture => 'x86_64',
Expand Down Expand Up @@ -83,7 +74,6 @@
:location => 'http://debian.mirror.iweb.ca/debian/',
:release => 'sid',
:repos => 'testing',
:include_src => false,
:key => { 'id' => GPG_KEY_ID, 'server' => 'pgp.mit.edu',
'content' => 'GPG key content',
'source' => 'http://apt.puppetlabs.com/pubkey.gpg',},
Expand Down Expand Up @@ -122,7 +112,6 @@
:location => 'http://debian.mirror.iweb.ca/debian/',
:release => 'sid',
:repos => 'testing',
:include_src => false,
:key => GPG_KEY_ID,
:pin => '10',
:architecture => 'x86_64',
Expand Down Expand Up @@ -160,7 +149,6 @@
end
let :params do
{
:include_src => false,
:trusted_source => true,
}
end
Expand All @@ -181,8 +169,7 @@
end
let :params do
{
:include_deb => false,
:include_src => true,
:include => {'deb' => false, 'src' => true,},
:architecture => 'x86_64',
}
end
Expand Down
4 changes: 2 additions & 2 deletions templates/source.list.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# <%= @comment %>
<%- if @include_deb then -%>
<%- if @_include['deb'] then -%>
deb <%- if @architecture or @trusted_source -%>
[<%- if @architecture %>arch=<%= @architecture %> <% end %><% if @trusted_source %>trusted=yes<% end -%>
] <%- end %><%= @location %> <%= @release %> <%= @repos %>
<%- end -%>
<%- if @include_src then -%>
<%- if @_include['src'] then -%>
deb-src <%- if @architecture or @trusted_source -%>
[<%- if @architecture %>arch=<%= @architecture %> <% end %><% if @trusted_source %>trusted=yes<% end -%>
] <%- end %><%= @location %> <%= @release %> <%= @repos %>
Expand Down

0 comments on commit 2a28938

Please sign in to comment.