Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F9697435
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
23 KB
Subscribers
None
View Options
diff --git a/manifests/source.pp b/manifests/source.pp
index 8db3b28..9cb2133 100644
--- a/manifests/source.pp
+++ b/manifests/source.pp
@@ -1,152 +1,152 @@
# source.pp
# add an apt source
define apt::source(
Optional[Variant[String, Stdlib::Compat::String]] $location = undef,
Variant[String, Stdlib::Compat::String] $comment = $name,
Variant[String, Stdlib::Compat::String] $ensure = present,
Optional[Variant[String, Stdlib::Compat::String]] $release = undef,
Variant[String, Stdlib::Compat::String] $repos = 'main',
Optional[Variant[Hash, Stdlib::Compat::Hash]] $include = {},
Optional[Variant[String, Stdlib::Compat::String, Hash, Stdlib::Compat::Hash]] $key = undef,
$pin = undef,
Optional[Variant[String, Stdlib::Compat::String]] $architecture = undef,
Boolean $allow_unsigned = false,
Boolean $notify_update = true,
Optional[Variant[String, Stdlib::Compat::String]] $key_server = undef,
Optional[Variant[String, Stdlib::Compat::String]] $key_content = undef,
Optional[Variant[String, Stdlib::Compat::String]] $key_source = undef,
Optional[Boolean] $include_src = undef,
Optional[Boolean] $include_deb = undef,
$required_packages = undef,
$trusted_source = undef,
) {
validate_legacy(String, 'validate_string', $architecture, $comment, $location, $repos)
validate_legacy(Boolean, 'validate_bool', $allow_unsigned)
validate_legacy(Hash, 'validate_hash', $include)
# This is needed for compat with 1.8.x
include ::apt
$_before = Apt::Setting["list-${title}"]
if $required_packages != undef {
deprecation('apt $required_packages', '$required_packages is deprecated and will be removed in the next major release, please use package resources instead.')
exec { "Required packages: '${required_packages}' for ${name}":
command => "${::apt::provider} -y install ${required_packages}",
logoutput => 'on_failure',
refreshonly => true,
tries => 3,
try_sleep => 1,
before => $_before,
}
}
if $trusted_source != undef {
deprecation('apt $trusted_source', '$trusted_source is deprecated and will be removed in the next major release, please use $allow_unsigned instead.')
$_allow_unsigned = $trusted_source
} else {
$_allow_unsigned = $allow_unsigned
}
if ! $release {
if $facts['lsbdistcodename'] {
$_release = $facts['lsbdistcodename']
} else {
fail('lsbdistcodename fact not available: release parameter required')
}
} else {
$_release = $release
}
if $ensure == 'present' and ! $location {
fail('cannot create a source entry without specifying a location')
}
if $include_src != undef and $include_deb != undef {
$_deprecated_include = {
'src' => $include_src,
'deb' => $include_deb,
}
} elsif $include_src != undef {
$_deprecated_include = { 'src' => $include_src }
} elsif $include_deb != undef {
$_deprecated_include = { 'deb' => $include_deb }
} else {
$_deprecated_include = {}
}
$includes = merge($::apt::include_defaults, $_deprecated_include, $include)
$_deprecated_key = {
'key_server' => $key_server,
'key_content' => $key_content,
'key_source' => $key_source,
}
if $key {
if is_hash($key) {
unless $key['id'] {
fail('key hash must contain at least an id entry')
}
$_key = merge($::apt::source_key_defaults, $_deprecated_key, $key)
} else {
validate_legacy(String, 'validate_string', $key)
$_key = merge( { 'id' => $key }, $_deprecated_key)
}
}
$header = epp('apt/_header.epp')
$sourcelist = epp('apt/source.list.epp', {
- 'comment' => $comment,
- 'includes' => $includes,
- 'architecture' => $architecture,
- 'allow_unsigned' => $_allow_unsigned,
- 'location' => $location,
- 'release' => $_release,
- 'repos' => $repos,
+ 'comment' => $comment,
+ 'includes' => $includes,
+ 'opt_architecture' => $architecture,
+ 'allow_unsigned' => $_allow_unsigned,
+ 'location' => $location,
+ 'release' => $_release,
+ 'repos' => $repos,
})
apt::setting { "list-${name}":
ensure => $ensure,
content => "${header}${sourcelist}",
notify_update => $notify_update,
}
if $pin {
if is_hash($pin) {
$_pin = merge($pin, { 'ensure' => $ensure, 'before' => $_before })
} elsif (is_numeric($pin) or is_string($pin)) {
$url_split = split($location, '[:\/]+')
$host = $url_split[1]
$_pin = {
'ensure' => $ensure,
'priority' => $pin,
'before' => $_before,
'origin' => $host,
}
} else {
fail('Received invalid value for pin parameter')
}
create_resources('apt::pin', { "${name}" => $_pin })
}
# We do not want to remove keys when the source is absent.
if $key and ($ensure == 'present') {
if is_hash($_key) {
apt::key { "Add key: ${$_key['id']} from Apt::Source ${title}":
ensure => present,
id => $_key['id'],
server => $_key['server'],
content => $_key['content'],
source => $_key['source'],
options => $_key['options'],
key_server => $_key['key_server'],
key_content => $_key['key_content'],
key_source => $_key['key_source'],
before => $_before,
}
}
}
}
diff --git a/spec/defines/source_spec.rb b/spec/defines/source_spec.rb
index 0972512..10a8062 100644
--- a/spec/defines/source_spec.rb
+++ b/spec/defines/source_spec.rb
@@ -1,460 +1,484 @@
require 'spec_helper'
describe 'apt::source' do
GPG_KEY_ID = '6F6B15509CF8E59E6E469F327F438280EF8D349F'
let :pre_condition do
'class { "apt": }'
end
let :title do
'my_source'
end
context 'defaults' do
context 'without location' do
let :facts do
{
:os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }},
:osfamily => 'Debian',
:lsbdistcodename => 'wheezy',
:puppetversion => Puppet.version,
}
end
it do
expect {
subject.call
}.to raise_error(Puppet::Error, /source entry without specifying a location/)
end
end
context 'with location' do
let :facts do
{
:os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }},
:lsbdistid => 'Debian',
:lsbdistcodename => 'wheezy',
:osfamily => 'Debian',
:puppetversion => Puppet.version,
}
end
let(:params) { { :location => 'hello.there', } }
it { is_expected.to contain_apt__setting('list-my_source').with({
:ensure => 'present',
}).without_content(/# my_source\ndeb-src hello.there wheezy main\n/)
}
end
end
describe 'no defaults' do
let :facts do
{
:os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }},
:lsbdistid => 'Debian',
:lsbdistcodename => 'wheezy',
:osfamily => 'Debian',
:operatingsystem => 'Debian',
:lsbdistrelease => '7.0',
:puppetversion => Puppet.version,
}
end
context 'with complex pin' do
let :params do
{
:location => 'hello.there',
:pin => { 'release' => 'wishwash',
'explanation' => 'wishwash',
'priority' => 1001, },
}
end
it { is_expected.to contain_apt__setting('list-my_source').with({
:ensure => 'present',
}).with_content(/hello.there wheezy main\n/)
}
it { is_expected.to contain_file('/etc/apt/sources.list.d/my_source.list').that_notifies('Class[Apt::Update]')}
it { is_expected.to contain_apt__pin('my_source').that_comes_before('Apt::Setting[list-my_source]').with({
:ensure => 'present',
:priority => 1001,
:explanation => 'wishwash',
:release => 'wishwash',
})
}
end
context 'with simple key' do
let :params do
{
:comment => 'foo',
:location => 'http://debian.mirror.iweb.ca/debian/',
:release => 'sid',
:repos => 'testing',
:key => GPG_KEY_ID,
:pin => '10',
:architecture => 'x86_64',
:allow_unsigned => true,
}
end
it { is_expected.to contain_apt__setting('list-my_source').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[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[list-my_source]').with({
:ensure => 'present',
:id => GPG_KEY_ID,
})
}
end
context 'with complex key' do
let :params do
{
:comment => 'foo',
:location => 'http://debian.mirror.iweb.ca/debian/',
:release => 'sid',
:repos => 'testing',
:key => { 'id' => GPG_KEY_ID, 'server' => 'pgp.mit.edu',
'content' => 'GPG key content',
'source' => 'http://apt.puppetlabs.com/pubkey.gpg',},
:pin => '10',
:architecture => 'x86_64',
:allow_unsigned => true,
}
end
it { is_expected.to contain_apt__setting('list-my_source').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[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[list-my_source]').with({
:ensure => 'present',
:id => GPG_KEY_ID,
:server => 'pgp.mit.edu',
:content => 'GPG key content',
:source => 'http://apt.puppetlabs.com/pubkey.gpg',
})
}
end
context 'with simple key' do
let :params do
{
:comment => 'foo',
:location => 'http://debian.mirror.iweb.ca/debian/',
:release => 'sid',
:repos => 'testing',
:key => GPG_KEY_ID,
:pin => '10',
:architecture => 'x86_64',
:allow_unsigned => true,
}
end
it { is_expected.to contain_apt__setting('list-my_source').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[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[list-my_source]').with({
:ensure => 'present',
:id => GPG_KEY_ID,
})
}
end
end
context 'allow_unsigned true' do
let :facts do
{
:os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }},
:lsbdistid => 'Debian',
:lsbdistcodename => 'wheezy',
:osfamily => 'Debian',
:puppetversion => Puppet.version,
}
end
let :params do
{
:location => 'hello.there',
:allow_unsigned => true,
}
end
it { is_expected.to contain_apt__setting('list-my_source').with({
:ensure => 'present',
}).with_content(/# my_source\ndeb \[trusted=yes\] hello.there wheezy main\n/)
}
end
context 'architecture equals x86_64' do
let :facts do
{
:os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }},
:lsbdistid => 'Debian',
:lsbdistcodename => 'wheezy',
:osfamily => 'Debian',
:puppetversion => Puppet.version,
}
end
let :params do
{
:location => 'hello.there',
:include => {'deb' => false, 'src' => true,},
:architecture => 'x86_64',
}
end
it { is_expected.to contain_apt__setting('list-my_source').with({
:ensure => 'present',
}).with_content(/# my_source\ndeb-src \[arch=x86_64\] hello.there wheezy main\n/)
}
end
+ context 'with architecture fact and unset architecture parameter' do
+ let :facts do
+ {
+ :architecture => 'amd64',
+ :os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }},
+ :lsbdistid => 'Debian',
+ :lsbdistcodename => 'wheezy',
+ :osfamily => 'Debian',
+ :puppetversion => Puppet.version,
+ }
+ end
+ let :params do
+ {
+ :location => 'hello.there',
+ :include => {'deb' => false, 'src' => true,},
+ }
+ end
+
+ it { is_expected.to contain_apt__setting('list-my_source').with({
+ :ensure => 'present',
+ }).with_content(/# my_source\ndeb-src hello.there wheezy main\n/)
+ }
+ end
+
context 'include_src => true' do
let :facts do
{
:os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }},
:lsbdistid => 'Debian',
:lsbdistcodename => 'wheezy',
:osfamily => 'Debian',
:puppetversion => Puppet.version,
}
end
let :params do
{
:location => 'hello.there',
:include_src => true,
}
end
it { is_expected.to contain_apt__setting('list-my_source').with({
:ensure => 'present',
}).with_content(/# my_source\ndeb hello.there wheezy main\ndeb-src hello.there wheezy main\n/)
}
end
context 'include_deb => false' do
let :facts do
{
:os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }},
:lsbdistid => 'debian',
:lsbdistcodename => 'wheezy',
:osfamily => 'debian',
:puppetversion => Puppet.version,
}
end
let :params do
{
:location => 'hello.there',
:include_deb => false,
}
end
it { is_expected.to contain_apt__setting('list-my_source').with({
:ensure => 'present',
}).without_content(/deb-src hello.there wheezy main\n/)
}
it { is_expected.to contain_apt__setting('list-my_source').without_content(/deb hello.there wheezy main\n/) }
end
context 'include_src => true and include_deb => false' do
let :facts do
{
:os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }},
:lsbdistid => 'debian',
:lsbdistcodename => 'wheezy',
:osfamily => 'debian',
:puppetversion => Puppet.version,
}
end
let :params do
{
:location => 'hello.there',
:include_deb => false,
:include_src => true,
}
end
it { is_expected.to contain_apt__setting('list-my_source').with({
:ensure => 'present',
}).with_content(/deb-src hello.there wheezy main\n/)
}
it { is_expected.to contain_apt__setting('list-my_source').without_content(/deb hello.there wheezy main\n/) }
end
context 'include precedence' do
let :facts do
{
:os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }},
:lsbdistid => 'debian',
:lsbdistcodename => 'wheezy',
:osfamily => 'debian',
:puppetversion => Puppet.version,
}
end
let :params do
{
:location => 'hello.there',
:include_deb => true,
:include_src => false,
:include => { 'deb' => false, 'src' => true },
}
end
it { is_expected.to contain_apt__setting('list-my_source').with({
:ensure => 'present',
}).with_content(/deb-src hello.there wheezy main\n/)
}
it { is_expected.to contain_apt__setting('list-my_source').without_content(/deb hello.there wheezy main\n/) }
end
context 'ensure => absent' do
let :facts do
{
:os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }},
:lsbdistid => 'Debian',
:lsbdistcodename => 'wheezy',
:osfamily => 'Debian',
:puppetversion => Puppet.version,
}
end
let :params do
{
:ensure => 'absent',
}
end
it { is_expected.to contain_apt__setting('list-my_source').with({
:ensure => 'absent'
})
}
end
describe 'validation' do
context 'no release' do
let :facts do
{
:os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }},
:lsbdistid => 'Debian',
:osfamily => 'Debian',
:puppetversion => Puppet.version,
}
end
let(:params) { { :location => 'hello.there', } }
it do
expect {
subject.call
}.to raise_error(Puppet::Error, /lsbdistcodename fact not available: release parameter required/)
end
end
context 'invalid pin' do
let :facts do
{
:os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }},
:lsbdistid => 'Debian',
:lsbdistcodename => 'wheezy',
:osfamily => 'Debian',
:puppetversion => Puppet.version,
}
end
let :params do
{
:location => 'hello.there',
:pin => true,
}
end
it do
expect {
subject.call
}.to raise_error(Puppet::Error, /invalid value for pin/)
end
end
context "with notify_update = undef (default)" do
let :facts do
{
:os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }},
:lsbdistid => 'Debian',
:lsbdistcodename => 'wheezy',
:osfamily => 'Debian',
:puppetversion => Puppet.version,
}
end
let :params do
{
:location => 'hello.there',
}
end
it { is_expected.to contain_apt__setting("list-#{title}").with_notify_update(true) }
end
context "with notify_update = true" do
let :facts do
{
:os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }},
:lsbdistid => 'Debian',
:lsbdistcodename => 'wheezy',
:osfamily => 'Debian',
:puppetversion => Puppet.version,
}
end
let :params do
{
:location => 'hello.there',
:notify_update => true,
}
end
it { is_expected.to contain_apt__setting("list-#{title}").with_notify_update(true) }
end
context "with notify_update = false" do
let :facts do
{
:os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }},
:lsbdistid => 'Debian',
:lsbdistcodename => 'wheezy',
:osfamily => 'Debian',
:puppetversion => Puppet.version,
}
end
let :params do
{
:location => 'hello.there',
:notify_update => false,
}
end
it { is_expected.to contain_apt__setting("list-#{title}").with_notify_update(false) }
end
end
end
diff --git a/templates/source.list.epp b/templates/source.list.epp
index 727766c..4b29726 100644
--- a/templates/source.list.epp
+++ b/templates/source.list.epp
@@ -1,10 +1,10 @@
-<%- | String $comment, Hash $includes, $architecture, Boolean $allow_unsigned, $location, $release, String $repos | -%>
+<%- | String $comment, Hash $includes, $opt_architecture, Boolean $allow_unsigned, $location, $release, String $repos | -%>
# <%= $comment %>
<%- if $includes['deb'] { -%>
-deb <%- if ($architecture or $allow_unsigned) {-%>
- [<%- if ($architecture) {%>arch=<%= $architecture %><% } %><%if ($architecture and $allow_unsigned) {%> <% }%><% if ($allow_unsigned) {%>trusted=yes<% } %>] <%- } %> <%= $location %> <%= $release %> <%= $repos %>
+deb <%- if ($opt_architecture or $allow_unsigned) {-%>
+ [<%- if ($opt_architecture) {%>arch=<%= $opt_architecture %><% } %><%if ($opt_architecture and $allow_unsigned) {%> <% }%><% if ($allow_unsigned) {%>trusted=yes<% } %>] <%- } %> <%= $location %> <%= $release %> <%= $repos %>
<%- } -%>
<%- if $includes['src'] { -%>
-deb-src <%- if $architecture or $allow_unsigned { -%>
- [<%- if ($architecture) {%>arch=<%= $architecture %><% } %><%if ($architecture and $allow_unsigned) {%> <% }%><% if ($allow_unsigned) {%>trusted=yes<% } %>] <%- } %> <%= $location %> <%= $release %> <%= $repos %>
+deb-src <%- if $opt_architecture or $allow_unsigned { -%>
+ [<%- if ($opt_architecture) {%>arch=<%= $opt_architecture %><% } %><%if ($opt_architecture and $allow_unsigned) {%> <% }%><% if ($allow_unsigned) {%>trusted=yes<% } %>] <%- } %> <%= $location %> <%= $release %> <%= $repos %>
<%- } -%>
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Mon, Aug 18, 11:45 PM (1 w, 5 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3254594
Attached To
rSPAPT Puppetlabs - APT
Event Timeline
Log In to Comment