Skip to content

Commit 396f308

Browse files
author
Morgan Haskel
committed
Compatibility between 1.8.x and 2.x for apt::source
1 parent b55dd49 commit 396f308

File tree

6 files changed

+377
-40
lines changed

6 files changed

+377
-40
lines changed

README.md

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -418,11 +418,11 @@ Manages the Apt sources in `/etc/apt/sources.list.d/`.
418418

419419
* `key`: Creates a declaration of the apt::key define Valid options: a string to be passed to the `id` parameter of the `apt::key` define, or a hash of `parameter => value` pairs to be passed to `apt::key`'s `id`, `server`, `content`, `source`, and/or `options` parameters. Default: undef.
420420

421-
* `include`: Configures include options. Valid options: a hash made up from the following keys:
421+
* `include`: Configures include options. Valid options: a hash made up from the following keys: Default: {}
422422

423-
* 'deb' - Specifies whether to request the distribution's compiled binaries. Valid options: 'true' and 'false. Default: 'true'.
423+
* 'deb' - Specifies whether to request the distribution's compiled binaries. Valid options: 'true' and 'false'. Default: 'true'.
424424

425-
* 'src' - Specifies whether to request the distribution's uncompiled source code. Valid options: 'true' and 'false'. Default: 'false'. Default: {}.
425+
* 'src' - Specifies whether to request the distribution's uncompiled source code. Valid options: 'true' and 'false'. Default: 'false'.
426426

427427
* `location`: *Required, unless `ensure` is set to 'absent'.* Specifies an Apt repository. Valid options: a string containing a repository URL. Default: undef.
428428

@@ -432,6 +432,20 @@ Manages the Apt sources in `/etc/apt/sources.list.d/`.
432432

433433
* `repos`: Specifies a component of the Apt repository. Valid options: a string. Default: 'main'.
434434

435+
* `include_deb`: Specify whether to request the distrubution's compiled binaries. Valid options: 'true' and 'false'. Default: undef **Note** this parameter is deprecated and will be removed in future versions of the module.
436+
437+
* `include_src`: Specifies whether to request the distribution's uncompiled source code. Valid options: 'true' and 'false'. Default: undef **Note** this parameter is deprecated andd will be removed in future versions of the module.
438+
439+
* `required_packages`: install packages required for this Apt source via an exec. Default: 'false'. **Note** this parameter is deprecated and will be removed in future versions of the module.
440+
441+
* `key_content`: Specify the content to be passed to `apt::key`. Default: undef. **Note** this parameter is deprecated and will be removed in future versions of the module.
442+
443+
* `key_server`: Specify the server to be passed to `apt::key`. Default: undef. **Note** this parameter is deprecated and will be removed in future versions of the module.
444+
445+
* `key_source`: Specify the source to be passed to `apt::key`. Default: undef. **Note** this parameter is deprecated and will be removed in future versions of the module.
446+
447+
* `trusted_source`: Specifies whether to authenticate packages from this release, even if the Release file is not signed or the signature can't be checked. Valid options: 'true' and 'false'. Default: undef. **Note** this parameter is deprecated and will be removed in future versions of the module.
448+
435449
#### Type: `apt_key`
436450

437451
Manages the GPG keys that Apt uses to authenticate packages.

manifests/setting.pp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
$notify_update = true,
77
) {
88

9+
include 'apt::params'
910
if $content and $source {
1011
fail('apt::setting cannot have both content and source')
1112
}
@@ -42,8 +43,8 @@
4243
$_priority = $priority
4344
}
4445

45-
$_path = $::apt::config_files[$setting_type]['path']
46-
$_ext = $::apt::config_files[$setting_type]['ext']
46+
$_path = $::apt::params::config_files[$setting_type]['path']
47+
$_ext = $::apt::params::config_files[$setting_type]['ext']
4748

4849
if $notify_update {
4950
$_notify = Exec['apt_update']

manifests/source.pp

Lines changed: 99 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,114 @@
11
# source.pp
22
# add an apt source
33
define apt::source(
4-
$location = undef,
5-
$comment = $name,
6-
$ensure = present,
7-
$release = $::apt::xfacts['lsbdistcodename'],
8-
$repos = 'main',
9-
$include = {},
10-
$key = undef,
11-
$pin = undef,
12-
$architecture = undef,
13-
$allow_unsigned = false,
4+
$location = undef,
5+
$comment = $name,
6+
$ensure = present,
7+
$release = undef,
8+
$repos = 'main',
9+
$include = {},
10+
$key = undef,
11+
$pin = undef,
12+
$architecture = undef,
13+
$allow_unsigned = false,
14+
$include_src = undef,
15+
$include_deb = undef,
16+
$required_packages = undef,
17+
$key_server = undef,
18+
$key_content = undef,
19+
$key_source = undef,
20+
$trusted_source = undef,
1421
) {
1522
validate_string($architecture, $comment, $location, $repos)
1623
validate_bool($allow_unsigned)
1724
validate_hash($include)
1825

19-
unless $release {
20-
fail('lsbdistcodename fact not available: release parameter required')
26+
include 'apt::params'
27+
28+
$_before = Apt::Setting["list-${title}"]
29+
30+
if $include_src != undef {
31+
warning("\$include_src is deprecated and will be removed in the next major release, please use \$include => { 'src' => ${include_src} } instead")
32+
}
33+
34+
if $include_deb != undef {
35+
warning("\$include_deb is deprecated and will be removed in the next major release, please use \$include => { 'deb' => ${include_deb} } instead")
36+
}
37+
38+
if $required_packages != undef {
39+
warning('$required_packages is deprecated and will be removed in the next major release, please use package resources instead.')
40+
exec { "Required packages: '${required_packages}' for ${name}":
41+
command => "${::apt::params::provider} -y install ${required_packages}",
42+
logoutput => 'on_failure',
43+
refreshonly => true,
44+
tries => 3,
45+
try_sleep => 1,
46+
before => $_before,
47+
}
48+
}
49+
50+
if $key_server != undef {
51+
warning("\$key_server is deprecated and will be removed in the next major release, please use \$key => { 'server' => ${key_server} } instead.")
52+
}
53+
54+
if $key_content != undef {
55+
warning("\$key_content is deprecated and will be removed in the next major release, please use \$key => { 'content' => ${key_content} } instead.")
56+
}
57+
58+
if $key_source != undef {
59+
warning("\$key_source is deprecated and will be removed in the next major release, please use \$key => { 'source' => ${key_source} } instead.")
60+
}
61+
62+
if $trusted_source != undef {
63+
warning('$trusted_source is deprecated and will be removed in the next major release, please use $allow_unsigned instead.')
64+
$_allow_unsigned = $trusted_source
65+
} else {
66+
$_allow_unsigned = $allow_unsigned
67+
}
68+
69+
if ! $release {
70+
$_release = $::apt::params::xfacts['lsbdistcodename']
71+
unless $_release {
72+
fail('lsbdistcodename fact not available: release parameter required')
73+
}
74+
} else {
75+
$_release = $release
2176
}
2277

2378
if $ensure == 'present' and ! $location {
2479
fail('cannot create a source entry without specifying a location')
2580
}
2681

27-
$_before = Apt::Setting["list-${title}"]
28-
$_include = merge($::apt::include_defaults, $include)
82+
if $include_src != undef and $include_deb != undef {
83+
$_deprecated_include = {
84+
'src' => $include_src,
85+
'deb' => $include_deb,
86+
}
87+
} elsif $include_src != undef {
88+
$_deprecated_include = { 'src' => $include_src }
89+
} elsif $include_deb != undef {
90+
$_deprecated_include = { 'deb' => $include_deb }
91+
} else {
92+
$_deprecated_include = {}
93+
}
94+
95+
$_include = merge($::apt::params::include_defaults, $_deprecated_include, $include)
96+
97+
$_deprecated_key = {
98+
'key_server' => $key_server,
99+
'key_content' => $key_content,
100+
'key_source' => $key_source,
101+
}
29102

30103
if $key {
31104
if is_hash($key) {
32105
unless $key['id'] {
33106
fail('key hash must contain at least an id entry')
34107
}
35-
$_key = merge($::apt::source_key_defaults, $key)
108+
$_key = merge($::apt::params::source_key_defaults, $_deprecated_key, $key)
36109
} else {
37110
validate_string($key)
38-
$_key = $key
111+
$_key = merge( { 'id' => $key }, $_deprecated_key)
39112
}
40113
}
41114

@@ -66,19 +139,16 @@
66139
if $key and ($ensure == 'present') {
67140
if is_hash($_key) {
68141
apt::key { "Add key: ${$_key['id']} from Apt::Source ${title}":
69-
ensure => present,
70-
id => $_key['id'],
71-
server => $_key['server'],
72-
content => $_key['content'],
73-
source => $_key['source'],
74-
options => $_key['options'],
75-
before => $_before,
76-
}
77-
} else {
78-
apt::key { "Add key: ${_key} from Apt::Source ${title}":
79-
ensure => present,
80-
id => $_key,
81-
before => $_before,
142+
ensure => present,
143+
id => $_key['id'],
144+
server => $_key['server'],
145+
content => $_key['content'],
146+
source => $_key['source'],
147+
options => $_key['options'],
148+
key_server => $_key['key_server'],
149+
key_content => $_key['key_content'],
150+
key_source => $_key['key_source'],
151+
before => $_before,
82152
}
83153
}
84154
}

spec/defines/source_compat_spec.rb

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
require 'spec_helper'
2+
3+
describe 'apt::source', :type => :define do
4+
GPG_KEY_ID = '47B320EB4C7C375AA9DAE1A01054B7A24BD6EC30'
5+
6+
let :title do
7+
'my_source'
8+
end
9+
10+
context 'mostly defaults' do
11+
let :facts do
12+
{
13+
:lsbdistid => 'Debian',
14+
:lsbdistcodename => 'wheezy',
15+
:osfamily => 'Debian',
16+
}
17+
end
18+
19+
let :params do
20+
{
21+
'include_deb' => false,
22+
'include_src' => true,
23+
'location' => 'http://debian.mirror.iweb.ca/debian/',
24+
}
25+
end
26+
27+
it { is_expected.to contain_apt__setting('list-my_source').with_content(/# my_source\ndeb-src http:\/\/debian\.mirror\.iweb\.ca\/debian\/ wheezy main\n/)
28+
}
29+
end
30+
31+
context 'no defaults' do
32+
let :facts do
33+
{
34+
:lsbdistid => 'Debian',
35+
:lsbdistcodename => 'wheezy',
36+
:osfamily => 'Debian'
37+
}
38+
end
39+
let :params do
40+
{
41+
'comment' => 'foo',
42+
'location' => 'http://debian.mirror.iweb.ca/debian/',
43+
'release' => 'sid',
44+
'repos' => 'testing',
45+
'include_src' => false,
46+
'required_packages' => 'vim',
47+
'key' => GPG_KEY_ID,
48+
'key_server' => 'pgp.mit.edu',
49+
'key_content' => 'GPG key content',
50+
'key_source' => 'http://apt.puppetlabs.com/pubkey.gpg',
51+
'pin' => '10',
52+
'architecture' => 'x86_64',
53+
'trusted_source' => true,
54+
}
55+
end
56+
57+
it { is_expected.to contain_apt__setting('list-my_source').with_content(/# foo\ndeb \[arch=x86_64 trusted=yes\] http:\/\/debian\.mirror\.iweb\.ca\/debian\/ sid testing\n/).without_content(/deb-src/)
58+
}
59+
60+
it { is_expected.to contain_apt__pin('my_source').that_comes_before('Apt::Setting[list-my_source]').with({
61+
'ensure' => 'present',
62+
'priority' => '10',
63+
'origin' => 'debian.mirror.iweb.ca',
64+
})
65+
}
66+
67+
it { is_expected.to contain_exec("Required packages: 'vim' for my_source").that_comes_before('Apt::Setting[list-my_source]').with({
68+
'command' => '/usr/bin/apt-get -y install vim',
69+
'logoutput' => 'on_failure',
70+
'refreshonly' => true,
71+
'tries' => '3',
72+
'try_sleep' => '1',
73+
})
74+
}
75+
76+
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({
77+
'ensure' => 'present',
78+
'id' => GPG_KEY_ID,
79+
'key_server' => 'pgp.mit.edu',
80+
'key_content' => 'GPG key content',
81+
'key_source' => 'http://apt.puppetlabs.com/pubkey.gpg',
82+
})
83+
}
84+
end
85+
86+
context 'trusted_source true' do
87+
let :facts do
88+
{
89+
:lsbdistid => 'Debian',
90+
:lsbdistcodename => 'wheezy',
91+
:osfamily => 'Debian'
92+
}
93+
end
94+
let :params do
95+
{
96+
'include_src' => false,
97+
'location' => 'http://debian.mirror.iweb.ca/debian/',
98+
'trusted_source' => true,
99+
}
100+
end
101+
102+
it { is_expected.to contain_apt__setting('list-my_source').with_content(/# my_source\ndeb \[trusted=yes\] http:\/\/debian\.mirror\.iweb\.ca\/debian\/ wheezy main\n/) }
103+
end
104+
105+
context 'architecture equals x86_64' do
106+
let :facts do
107+
{
108+
:lsbdistid => 'Debian',
109+
:lsbdistcodename => 'wheezy',
110+
:osfamily => 'Debian'
111+
}
112+
end
113+
let :params do
114+
{
115+
'location' => 'http://debian.mirror.iweb.ca/debian/',
116+
'architecture' => 'x86_64',
117+
}
118+
end
119+
120+
it { is_expected.to contain_apt__setting('list-my_source').with_content(/# my_source\ndeb \[arch=x86_64 \] http:\/\/debian\.mirror\.iweb\.ca\/debian\/ wheezy main\n/)
121+
}
122+
end
123+
124+
context 'ensure => absent' do
125+
let :facts do
126+
{
127+
:lsbdistid => 'Debian',
128+
:lsbdistcodename => 'wheezy',
129+
:osfamily => 'Debian'
130+
}
131+
end
132+
let :params do
133+
{
134+
'ensure' => 'absent',
135+
}
136+
end
137+
138+
it { is_expected.to contain_apt__setting('list-my_source').with({
139+
'ensure' => 'absent'
140+
})
141+
}
142+
end
143+
144+
describe 'validation' do
145+
context 'no release' do
146+
let :facts do
147+
{
148+
:lsbdistid => 'Debian',
149+
:osfamily => 'Debian'
150+
}
151+
end
152+
153+
it do
154+
expect { subject.call }.to raise_error(Puppet::Error, /lsbdistcodename fact not available: release parameter required/)
155+
end
156+
end
157+
end
158+
end

0 commit comments

Comments
 (0)