Compatibility between 1.8.x and 2.x for apt::source

This commit is contained in:
Morgan Haskel 2015-06-03 17:19:16 -07:00
parent b55dd49b17
commit 396f308e6a
6 changed files with 377 additions and 40 deletions

View file

@ -418,11 +418,11 @@ Manages the Apt sources in `/etc/apt/sources.list.d/`.
* `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. * `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.
* `include`: Configures include options. Valid options: a hash made up from the following keys: * `include`: Configures include options. Valid options: a hash made up from the following keys: Default: {}
* 'deb' - Specifies whether to request the distribution's compiled binaries. Valid options: 'true' and 'false. Default: 'true'. * 'deb' - Specifies whether to request the distribution's compiled binaries. Valid options: 'true' and 'false'. Default: 'true'.
* 'src' - Specifies whether to request the distribution's uncompiled source code. Valid options: 'true' and 'false'. Default: 'false'. Default: {}. * 'src' - Specifies whether to request the distribution's uncompiled source code. Valid options: 'true' and 'false'. Default: 'false'.
* `location`: *Required, unless `ensure` is set to 'absent'.* Specifies an Apt repository. Valid options: a string containing a repository URL. Default: undef. * `location`: *Required, unless `ensure` is set to 'absent'.* Specifies an Apt repository. Valid options: a string containing a repository URL. Default: undef.
@ -432,6 +432,20 @@ Manages the Apt sources in `/etc/apt/sources.list.d/`.
* `repos`: Specifies a component of the Apt repository. Valid options: a string. Default: 'main'. * `repos`: Specifies a component of the Apt repository. Valid options: a string. Default: 'main'.
* `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.
* `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.
* `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.
* `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.
* `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.
* `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.
* `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.
#### Type: `apt_key` #### Type: `apt_key`
Manages the GPG keys that Apt uses to authenticate packages. Manages the GPG keys that Apt uses to authenticate packages.

View file

@ -6,6 +6,7 @@ define apt::setting (
$notify_update = true, $notify_update = true,
) { ) {
include 'apt::params'
if $content and $source { if $content and $source {
fail('apt::setting cannot have both content and source') fail('apt::setting cannot have both content and source')
} }
@ -42,8 +43,8 @@ define apt::setting (
$_priority = $priority $_priority = $priority
} }
$_path = $::apt::config_files[$setting_type]['path'] $_path = $::apt::params::config_files[$setting_type]['path']
$_ext = $::apt::config_files[$setting_type]['ext'] $_ext = $::apt::params::config_files[$setting_type]['ext']
if $notify_update { if $notify_update {
$_notify = Exec['apt_update'] $_notify = Exec['apt_update']

View file

@ -1,41 +1,114 @@
# source.pp # source.pp
# add an apt source # add an apt source
define apt::source( define apt::source(
$location = undef, $location = undef,
$comment = $name, $comment = $name,
$ensure = present, $ensure = present,
$release = $::apt::xfacts['lsbdistcodename'], $release = undef,
$repos = 'main', $repos = 'main',
$include = {}, $include = {},
$key = undef, $key = undef,
$pin = undef, $pin = undef,
$architecture = undef, $architecture = undef,
$allow_unsigned = false, $allow_unsigned = false,
$include_src = undef,
$include_deb = undef,
$required_packages = undef,
$key_server = undef,
$key_content = undef,
$key_source = undef,
$trusted_source = undef,
) { ) {
validate_string($architecture, $comment, $location, $repos) validate_string($architecture, $comment, $location, $repos)
validate_bool($allow_unsigned) validate_bool($allow_unsigned)
validate_hash($include) validate_hash($include)
unless $release { include 'apt::params'
fail('lsbdistcodename fact not available: release parameter required')
$_before = Apt::Setting["list-${title}"]
if $include_src != undef {
warning("\$include_src is deprecated and will be removed in the next major release, please use \$include => { 'src' => ${include_src} } instead")
}
if $include_deb != undef {
warning("\$include_deb is deprecated and will be removed in the next major release, please use \$include => { 'deb' => ${include_deb} } instead")
}
if $required_packages != undef {
warning('$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::params::provider} -y install ${required_packages}",
logoutput => 'on_failure',
refreshonly => true,
tries => 3,
try_sleep => 1,
before => $_before,
}
}
if $key_server != undef {
warning("\$key_server is deprecated and will be removed in the next major release, please use \$key => { 'server' => ${key_server} } instead.")
}
if $key_content != undef {
warning("\$key_content is deprecated and will be removed in the next major release, please use \$key => { 'content' => ${key_content} } instead.")
}
if $key_source != undef {
warning("\$key_source is deprecated and will be removed in the next major release, please use \$key => { 'source' => ${key_source} } instead.")
}
if $trusted_source != undef {
warning('$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 {
$_release = $::apt::params::xfacts['lsbdistcodename']
unless $_release {
fail('lsbdistcodename fact not available: release parameter required')
}
} else {
$_release = $release
} }
if $ensure == 'present' and ! $location { if $ensure == 'present' and ! $location {
fail('cannot create a source entry without specifying a location') fail('cannot create a source entry without specifying a location')
} }
$_before = Apt::Setting["list-${title}"] if $include_src != undef and $include_deb != undef {
$_include = merge($::apt::include_defaults, $include) $_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 = {}
}
$_include = merge($::apt::params::include_defaults, $_deprecated_include, $include)
$_deprecated_key = {
'key_server' => $key_server,
'key_content' => $key_content,
'key_source' => $key_source,
}
if $key { if $key {
if is_hash($key) { if is_hash($key) {
unless $key['id'] { unless $key['id'] {
fail('key hash must contain at least an id entry') fail('key hash must contain at least an id entry')
} }
$_key = merge($::apt::source_key_defaults, $key) $_key = merge($::apt::params::source_key_defaults, $_deprecated_key, $key)
} else { } else {
validate_string($key) validate_string($key)
$_key = $key $_key = merge( { 'id' => $key }, $_deprecated_key)
} }
} }
@ -66,19 +139,16 @@ define apt::source(
if $key and ($ensure == 'present') { if $key and ($ensure == 'present') {
if is_hash($_key) { if is_hash($_key) {
apt::key { "Add key: ${$_key['id']} from Apt::Source ${title}": apt::key { "Add key: ${$_key['id']} from Apt::Source ${title}":
ensure => present, ensure => present,
id => $_key['id'], id => $_key['id'],
server => $_key['server'], server => $_key['server'],
content => $_key['content'], content => $_key['content'],
source => $_key['source'], source => $_key['source'],
options => $_key['options'], options => $_key['options'],
before => $_before, key_server => $_key['key_server'],
} key_content => $_key['key_content'],
} else { key_source => $_key['key_source'],
apt::key { "Add key: ${_key} from Apt::Source ${title}": before => $_before,
ensure => present,
id => $_key,
before => $_before,
} }
} }
} }

View file

@ -0,0 +1,158 @@
require 'spec_helper'
describe 'apt::source', :type => :define do
GPG_KEY_ID = '47B320EB4C7C375AA9DAE1A01054B7A24BD6EC30'
let :title do
'my_source'
end
context 'mostly defaults' do
let :facts do
{
:lsbdistid => 'Debian',
:lsbdistcodename => 'wheezy',
:osfamily => 'Debian',
}
end
let :params do
{
'include_deb' => false,
'include_src' => true,
'location' => 'http://debian.mirror.iweb.ca/debian/',
}
end
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/)
}
end
context 'no defaults' do
let :facts do
{
:lsbdistid => 'Debian',
:lsbdistcodename => 'wheezy',
:osfamily => 'Debian'
}
end
let :params do
{
'comment' => 'foo',
'location' => 'http://debian.mirror.iweb.ca/debian/',
'release' => 'sid',
'repos' => 'testing',
'include_src' => false,
'required_packages' => 'vim',
'key' => GPG_KEY_ID,
'key_server' => 'pgp.mit.edu',
'key_content' => 'GPG key content',
'key_source' => 'http://apt.puppetlabs.com/pubkey.gpg',
'pin' => '10',
'architecture' => 'x86_64',
'trusted_source' => true,
}
end
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/)
}
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_exec("Required packages: 'vim' for my_source").that_comes_before('Apt::Setting[list-my_source]').with({
'command' => '/usr/bin/apt-get -y install vim',
'logoutput' => 'on_failure',
'refreshonly' => true,
'tries' => '3',
'try_sleep' => '1',
})
}
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,
'key_server' => 'pgp.mit.edu',
'key_content' => 'GPG key content',
'key_source' => 'http://apt.puppetlabs.com/pubkey.gpg',
})
}
end
context 'trusted_source true' do
let :facts do
{
:lsbdistid => 'Debian',
:lsbdistcodename => 'wheezy',
:osfamily => 'Debian'
}
end
let :params do
{
'include_src' => false,
'location' => 'http://debian.mirror.iweb.ca/debian/',
'trusted_source' => true,
}
end
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/) }
end
context 'architecture equals x86_64' do
let :facts do
{
:lsbdistid => 'Debian',
:lsbdistcodename => 'wheezy',
:osfamily => 'Debian'
}
end
let :params do
{
'location' => 'http://debian.mirror.iweb.ca/debian/',
'architecture' => 'x86_64',
}
end
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/)
}
end
context 'ensure => absent' do
let :facts do
{
:lsbdistid => 'Debian',
:lsbdistcodename => 'wheezy',
:osfamily => 'Debian'
}
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
{
:lsbdistid => 'Debian',
:osfamily => 'Debian'
}
end
it do
expect { subject.call }.to raise_error(Puppet::Error, /lsbdistcodename fact not available: release parameter required/)
end
end
end
end

View file

@ -229,6 +229,100 @@ describe 'apt::source' do
} }
end end
context 'include_src => true' do
let :facts do
{
: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
{
: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
{
: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
{
: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 context 'ensure => absent' do
let :facts do let :facts do
{ {

View file

@ -1,11 +1,11 @@
# <%= @comment %> # <%= @comment %>
<%- if @_include['deb'] then -%> <%- if @_include['deb'] then -%>
deb <%- if @architecture or @allow_unsigned -%> deb <%- if @architecture or @_allow_unsigned -%>
[<%- if @architecture %>arch=<%= @architecture %> <% end %><% if @allow_unsigned %>trusted=yes<% end -%> [<%- if @architecture %>arch=<%= @architecture %> <% end %><% if @_allow_unsigned %>trusted=yes<% end -%>
] <%- end %><%= @location %> <%= @release %> <%= @repos %> ] <%- end %><%= @location %> <%= @_release %> <%= @repos %>
<%- end -%> <%- end -%>
<%- if @_include['src'] then -%> <%- if @_include['src'] then -%>
deb-src <%- if @architecture or @allow_unsigned -%> deb-src <%- if @architecture or @_allow_unsigned -%>
[<%- if @architecture %>arch=<%= @architecture %> <% end %><% if @allow_unsigned %>trusted=yes<% end -%> [<%- if @architecture %>arch=<%= @architecture %> <% end %><% if @_allow_unsigned %>trusted=yes<% end -%>
] <%- end %><%= @location %> <%= @release %> <%= @repos %> ] <%- end %><%= @location %> <%= @_release %> <%= @repos %>
<%- end -%> <%- end -%>