Merge pull request #447 from puppetlabs/daenney/hulk-smash-2

It's been a long time - how have you been
This commit is contained in:
Morgan Haskel 2015-03-02 10:10:37 -08:00
commit 396036892d
12 changed files with 478 additions and 269 deletions

View file

@ -62,7 +62,7 @@ Puppet::Type.newtype(:apt_key) do
newvalues(/\A((hkp|http|https):\/\/)?([a-z\d])([a-z\d-]{0,61}\.)+[a-z\d]+(:\d{2,5})?$/) newvalues(/\A((hkp|http|https):\/\/)?([a-z\d])([a-z\d-]{0,61}\.)+[a-z\d]+(:\d{2,5})?$/)
end end
newparam(:keyserver_options) do newparam(:options) do
desc 'Additional options to pass to apt-key\'s --keyserver-options.' desc 'Additional options to pass to apt-key\'s --keyserver-options.'
end end

View file

@ -1,24 +1,51 @@
# #
class apt( class apt(
$update = {},
$purge = {},
$proxy = {}, $proxy = {},
$always_apt_update = false, $sources = {},
$apt_update_frequency = 'reluctantly', $keys = {},
$purge_sources_list = false, $ppas = {},
$purge_sources_list_d = false, $settings = {},
$purge_preferences = false,
$purge_preferences_d = false,
$update_timeout = undef,
$update_tries = undef,
$sources = undef,
) inherits ::apt::params { ) inherits ::apt::params {
$frequency_options = ['always','daily','weekly','reluctantly']
validate_hash($update)
if $update['frequency'] {
validate_re($update['frequency'], $frequency_options)
}
if $update['always'] {
validate_bool($update['always'])
}
if $update['timeout'] {
unless is_integer($update['timeout']) {
fail('timeout value for update must be an integer')
}
}
if $update['tries'] {
unless is_integer($update['tries']) {
fail('tries value for update must be an integer')
}
}
$_update = merge($::apt::update_defaults, $update)
include apt::update include apt::update
$frequency_options = ['always','daily','weekly','reluctantly'] validate_hash($purge)
validate_re($apt_update_frequency, $frequency_options) if $purge['sources.list'] {
validate_bool($purge['sources.list'])
}
if $purge['sources.list.d'] {
validate_bool($purge['sources.list.d'])
}
if $purge['preferences'] {
validate_bool($purge['preferences'])
}
if $purge['preferences.d'] {
validate_bool($purge['preferences.d'])
}
validate_bool($purge_sources_list, $purge_sources_list_d, $_purge = merge($::apt::purge_defaults, $purge)
$purge_preferences, $purge_preferences_d)
validate_hash($proxy) validate_hash($proxy)
if $proxy['host'] { if $proxy['host'] {
@ -35,6 +62,11 @@ class apt(
$_proxy = merge($apt::proxy_defaults, $proxy) $_proxy = merge($apt::proxy_defaults, $proxy)
validate_hash($sources)
validate_hash($keys)
validate_hash($settings)
validate_hash($ppas)
if $proxy['host'] { if $proxy['host'] {
apt::setting { 'conf-proxy': apt::setting { 'conf-proxy':
priority => '01', priority => '01',
@ -42,12 +74,17 @@ class apt(
} }
} }
$sources_list_content = $purge_sources_list ? { $sources_list_content = $_purge['sources.list'] ? {
false => undef, false => undef,
true => "# Repos managed by puppet.\n", true => "# Repos managed by puppet.\n",
} }
if $always_apt_update == true { $preferences_ensure = $_purge['preferences'] ? {
false => file,
true => absent,
}
if $_update['always'] {
Exec <| title=='apt_update' |> { Exec <| title=='apt_update' |> {
refreshonly => false, refreshonly => false,
} }
@ -59,7 +96,7 @@ class apt(
} }
file { 'sources.list': file { 'sources.list':
ensure => present, ensure => file,
path => $::apt::sources_list, path => $::apt::sources_list,
owner => root, owner => root,
group => root, group => root,
@ -73,16 +110,19 @@ class apt(
path => $::apt::sources_list_d, path => $::apt::sources_list_d,
owner => root, owner => root,
group => root, group => root,
purge => $purge_sources_list_d, mode => '0644',
recurse => $purge_sources_list_d, purge => $_purge['sources.list.d'],
recurse => $_purge['sources.list.d'],
notify => Exec['apt_update'], notify => Exec['apt_update'],
} }
if $purge_preferences { file { 'preferences':
file { 'apt-preferences': ensure => $preferences_ensure,
ensure => absent,
path => $::apt::preferences, path => $::apt::preferences,
} owner => root,
group => root,
mode => '0644',
notify => Exec['apt_update'],
} }
file { 'preferences.d': file { 'preferences.d':
@ -90,8 +130,10 @@ class apt(
path => $::apt::preferences_d, path => $::apt::preferences_d,
owner => root, owner => root,
group => root, group => root,
purge => $purge_preferences_d, mode => '0644',
recurse => $purge_preferences_d, purge => $_purge['preferences.d'],
recurse => $_purge['preferences.d'],
notify => Exec['apt_update'],
} }
# Need anchor to provide containment for dependencies. # Need anchor to provide containment for dependencies.
@ -100,8 +142,19 @@ class apt(
} }
# manage sources if present # manage sources if present
if $sources != undef { if $sources {
validate_hash($sources)
create_resources('apt::source', $sources) create_resources('apt::source', $sources)
} }
# manage keys if present
if $keys {
create_resources('apt::key', $keys)
}
# manage ppas if present
if $ppas {
create_resources('apt::ppa', $ppas)
}
# manage settings if present
if $settings {
create_resources('apt::setting', $settings)
}
} }

View file

@ -7,7 +7,7 @@
# #
# === Parameters # === Parameters
# #
# [*key*] # [*id*]
# _default_: +$title+, the title/name of the resource # _default_: +$title+, the title/name of the resource
# #
# Is a GPG key ID or full key fingerprint. This value is validated with # Is a GPG key ID or full key fingerprint. This value is validated with
@ -23,14 +23,14 @@
# * +present+ # * +present+
# * +absent+ # * +absent+
# #
# [*key_content*] # [*content*]
# _default_: +undef+ # _default_: +undef+
# #
# This parameter can be used to pass in a GPG key as a # This parameter can be used to pass in a GPG key as a
# string in case it cannot be fetched from a remote location # string in case it cannot be fetched from a remote location
# and using a file resource is for other reasons inconvenient. # and using a file resource is for other reasons inconvenient.
# #
# [*key_source*] # [*source*]
# _default_: +undef+ # _default_: +undef+
# #
# This parameter can be used to pass in the location of a GPG # This parameter can be used to pass in the location of a GPG
@ -38,80 +38,78 @@
# * +URL+: ftp, http or https # * +URL+: ftp, http or https
# * +path+: absolute path to a file on the target system. # * +path+: absolute path to a file on the target system.
# #
# [*key_server*] # [*server*]
# _default_: +undef+ # _default_: +undef+
# #
# The keyserver from where to fetch our GPG key. It can either be a domain # The keyserver from where to fetch our GPG key. It can either be a domain
# name or url. It defaults to # name or url. It defaults to +keyserver.ubuntu.com+.
# undef which results in apt_key's default keyserver being used,
# currently +keyserver.ubuntu.com+.
# #
# [*key_options*] # [*options*]
# _default_: +undef+ # _default_: +undef+
# #
# Additional options to pass on to `apt-key adv --keyserver-options`. # Additional options to pass on to `apt-key adv --keyserver-options`.
define apt::key ( define apt::key (
$key = $title, $id = $title,
$ensure = present, $ensure = present,
$key_content = undef, $content = undef,
$key_source = undef, $source = undef,
$key_server = undef, $server = $::apt::keyserver,
$key_options = undef, $options = undef,
) { ) {
validate_re($key, ['\A(0x)?[0-9a-fA-F]{8}\Z', '\A(0x)?[0-9a-fA-F]{16}\Z', '\A(0x)?[0-9a-fA-F]{40}\Z']) validate_re($id, ['\A(0x)?[0-9a-fA-F]{8}\Z', '\A(0x)?[0-9a-fA-F]{16}\Z', '\A(0x)?[0-9a-fA-F]{40}\Z'])
validate_re($ensure, ['\Aabsent|present\Z',]) validate_re($ensure, ['\Aabsent|present\Z',])
if $key_content { if $content {
validate_string($key_content) validate_string($content)
} }
if $key_source { if $source {
validate_re($key_source, ['\Ahttps?:\/\/', '\Aftp:\/\/', '\A\/\w+']) validate_re($source, ['\Ahttps?:\/\/', '\Aftp:\/\/', '\A\/\w+'])
} }
if $key_server { if $server {
validate_re($key_server,['\A((hkp|http|https):\/\/)?([a-z\d])([a-z\d-]{0,61}\.)+[a-z\d]+(:\d{2,5})?$']) validate_re($server,['\A((hkp|http|https):\/\/)?([a-z\d])([a-z\d-]{0,61}\.)+[a-z\d]+(:\d{2,5})?$'])
} }
if $key_options { if $options {
validate_string($key_options) validate_string($options)
} }
case $ensure { case $ensure {
present: { present: {
if defined(Anchor["apt_key ${key} absent"]){ if defined(Anchor["apt_key ${id} absent"]){
fail("key with id ${key} already ensured as absent") fail("key with id ${id} already ensured as absent")
} }
if !defined(Anchor["apt_key ${key} present"]) { if !defined(Anchor["apt_key ${id} present"]) {
apt_key { $title: apt_key { $title:
ensure => $ensure, ensure => $ensure,
id => $key, id => $id,
source => $key_source, source => $source,
content => $key_content, content => $content,
server => $key_server, server => $server,
keyserver_options => $key_options, options => $options,
} -> } ->
anchor { "apt_key ${key} present": } anchor { "apt_key ${id} present": }
} }
} }
absent: { absent: {
if defined(Anchor["apt_key ${key} present"]){ if defined(Anchor["apt_key ${id} present"]){
fail("key with id ${key} already ensured as present") fail("key with id ${id} already ensured as present")
} }
if !defined(Anchor["apt_key ${key} absent"]){ if !defined(Anchor["apt_key ${id} absent"]){
apt_key { $title: apt_key { $title:
ensure => $ensure, ensure => $ensure,
id => $key, id => $id,
source => $key_source, source => $source,
content => $key_content, content => $content,
server => $key_server, server => $server,
keyserver_options => $key_options, options => $options,
} -> } ->
anchor { "apt_key ${key} absent": } anchor { "apt_key ${id} absent": }
} }
} }

View file

@ -11,6 +11,7 @@ class apt::params {
$conf_d = "${root}/apt.conf.d" $conf_d = "${root}/apt.conf.d"
$preferences = "${root}/preferences" $preferences = "${root}/preferences"
$preferences_d = "${root}/preferences.d" $preferences_d = "${root}/preferences.d"
$keyserver = 'keyserver.ubuntu.com'
if $::osfamily != 'Debian' { if $::osfamily != 'Debian' {
fail('This module only works on Debian or derivatives like Ubuntu') fail('This module only works on Debian or derivatives like Ubuntu')
@ -31,12 +32,33 @@ class apt::params {
} }
} }
$update_defaults = {
'always' => false,
'frequency' => 'reluctantly',
'timeout' => undef,
'tries' => undef,
}
$proxy_defaults = { $proxy_defaults = {
'host' => undef, 'host' => undef,
'port' => 8080, 'port' => 8080,
'https' => false, 'https' => false,
} }
$purge_defaults = {
'sources.list' => true,
'sources.list.d' => true,
'preferences' => true,
'preferences.d' => true,
}
$source_key_defaults = {
'server' => $keyserver,
'options' => undef,
'content' => undef,
'source' => undef,
}
$file_defaults = { $file_defaults = {
'owner' => 'root', 'owner' => 'root',
'group' => 'root', 'group' => 'root',

View file

@ -10,8 +10,8 @@ define apt::ppa(
fail('lsbdistcodename fact not available: release parameter required') fail('lsbdistcodename fact not available: release parameter required')
} }
if $::operatingsystem != 'Ubuntu' { if $::apt::distid != 'ubuntu' {
fail('apt::ppa is currently supported on Ubuntu only.') fail('apt::ppa is currently supported on Ubuntu and LinuxMint only.')
} }
$filename_without_slashes = regsubst($name, '/', '-', 'G') $filename_without_slashes = regsubst($name, '/', '-', 'G')

View file

@ -9,20 +9,30 @@ define apt::source(
$include_src = false, $include_src = false,
$include_deb = true, $include_deb = true,
$key = undef, $key = undef,
$key_server = 'keyserver.ubuntu.com',
$key_content = undef,
$key_source = undef,
$pin = false, $pin = false,
$architecture = undef, $architecture = undef,
$trusted_source = false, $trusted_source = false,
) { ) {
validate_string($architecture, $comment, $location, $release, $repos, $key_server) validate_string($architecture, $comment, $location, $release, $repos)
validate_bool($trusted_source, $include_src, $include_deb) validate_bool($trusted_source, $include_src, $include_deb)
if ! $release { if ! $release {
fail('lsbdistcodename fact not available: release parameter required') fail('lsbdistcodename fact not available: release parameter required')
} }
$_before = Apt::Setting["list-${title}"]
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, $key)
} else {
validate_string($key)
}
}
apt::setting { "list-${name}": apt::setting { "list-${name}":
ensure => $ensure, ensure => $ensure,
content => template('apt/_header.erb', 'apt/source.list.erb'), content => template('apt/_header.erb', 'apt/source.list.erb'),
@ -36,20 +46,29 @@ define apt::source(
apt::pin { $name: apt::pin { $name:
ensure => $ensure, ensure => $ensure,
priority => $pin, priority => $pin,
before => Apt::Setting["list-${name}"], before => $_before,
origin => $host, origin => $host,
} }
} }
# We do not want to remove keys when the source is absent. # We do not want to remove keys when the source is absent.
if $key and ($ensure == 'present') { 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'],
before => $_before,
}
} else {
apt::key { "Add key: ${key} from Apt::Source ${title}": apt::key { "Add key: ${key} from Apt::Source ${title}":
ensure => present, ensure => present,
key => $key, id => $key,
key_server => $key_server, before => $_before,
key_content => $key_content, }
key_source => $key_source,
before => Apt::Setting["list-${name}"],
} }
} }
} }

View file

@ -4,10 +4,10 @@ class apt::update {
#on the first run, but if it's not run in awhile something is likely borked #on the first run, but if it's not run in awhile something is likely borked
#with apt and we'd want to know about it. #with apt and we'd want to know about it.
if $::apt::always_apt_update == false { if $::apt::_update['always'] == false {
#if always_apt_update is true there's no point in parsing this logic. #if always_apt_update is true there's no point in parsing this logic.
case $apt::apt_update_frequency { case $::apt::_update['frequency'] {
'always': { 'always': {
$_kick_apt = true $_kick_apt = true
} }
@ -60,8 +60,8 @@ class apt::update {
command => "${::apt::provider} update", command => "${::apt::provider} update",
logoutput => 'on_failure', logoutput => 'on_failure',
refreshonly => $_refresh, refreshonly => $_refresh,
timeout => $apt::update_timeout, timeout => $::apt::_update['timeout'],
tries => $apt::update_tries, tries => $::apt::_update['tries'],
try_sleep => 1 try_sleep => 1
} }
} }

View file

@ -4,11 +4,12 @@ describe 'apt' do
context 'defaults' do context 'defaults' do
it { is_expected.to contain_file('sources.list').that_notifies('Exec[apt_update]').only_with({ it { is_expected.to contain_file('sources.list').that_notifies('Exec[apt_update]').only_with({
:ensure => 'present', :ensure => 'file',
:path => '/etc/apt/sources.list', :path => '/etc/apt/sources.list',
:owner => 'root', :owner => 'root',
:group => 'root', :group => 'root',
:mode => '0644', :mode => '0644',
:content => "# Repos managed by puppet.\n",
:notify => 'Exec[apt_update]', :notify => 'Exec[apt_update]',
})} })}
@ -17,18 +18,30 @@ describe 'apt' do
:path => '/etc/apt/sources.list.d', :path => '/etc/apt/sources.list.d',
:owner => 'root', :owner => 'root',
:group => 'root', :group => 'root',
:purge => false, :mode => '0644',
:recurse => false, :purge => true,
:recurse => true,
:notify => 'Exec[apt_update]', :notify => 'Exec[apt_update]',
})} })}
it { is_expected.to contain_file('preferences.d').only_with({ it { is_expected.to contain_file('preferences').that_notifies('Exec[apt_update]').only_with({
:ensure => 'absent',
:path => '/etc/apt/preferences',
:owner => 'root',
:group => 'root',
:mode => '0644',
:notify => 'Exec[apt_update]',
})}
it { is_expected.to contain_file('preferences.d').that_notifies('Exec[apt_update]').only_with({
:ensure => 'directory', :ensure => 'directory',
:path => '/etc/apt/preferences.d', :path => '/etc/apt/preferences.d',
:owner => 'root', :owner => 'root',
:group => 'root', :group => 'root',
:purge => false, :mode => '0644',
:recurse => false, :purge => true,
:recurse => true,
:notify => 'Exec[apt_update]',
})} })}
it 'should lay down /etc/apt/apt.conf.d/15update-stamp' do it 'should lay down /etc/apt/apt.conf.d/15update-stamp' do
@ -83,39 +96,34 @@ describe 'apt' do
context 'lots of non-defaults' do context 'lots of non-defaults' do
let :params do let :params do
{ {
:always_apt_update => true, :update => { 'always' => true, 'timeout' => 1, 'tries' => 3 },
:purge_sources_list => true, :purge => { 'sources.list' => false, 'sources.list.d' => false,
:purge_sources_list_d => true, 'preferences' => false, 'preferences.d' => false, },
:purge_preferences => true,
:purge_preferences_d => true,
:update_timeout => '1',
:update_tries => '3',
} }
end end
it { is_expected.to contain_file('sources.list').with({ it { is_expected.to contain_file('sources.list').without({
:content => "# Repos managed by puppet.\n" :content => "# Repos managed by puppet.\n",
})} })}
it { is_expected.to contain_file('sources.list.d').with({ it { is_expected.to contain_file('sources.list.d').with({
:purge => 'true', :purge => false,
:recurse => 'true', :recurse => false,
})} })}
it { is_expected.to contain_file('apt-preferences').only_with({ it { is_expected.to contain_file('preferences').with({
:ensure => 'absent', :ensure => 'file',
:path => '/etc/apt/preferences',
})} })}
it { is_expected.to contain_file('preferences.d').with({ it { is_expected.to contain_file('preferences.d').with({
:purge => 'true', :purge => false,
:recurse => 'true', :recurse => false,
})} })}
it { is_expected.to contain_exec('apt_update').with({ it { is_expected.to contain_exec('apt_update').with({
:refreshonly => 'false', :refreshonly => false,
:timeout => '1', :timeout => 1,
:tries => '3', :tries => 3,
})} })}
end end
@ -132,16 +140,14 @@ describe 'apt' do
'location' => 'http://debian.mirror.iweb.ca/debian/', 'location' => 'http://debian.mirror.iweb.ca/debian/',
'release' => 'unstable', 'release' => 'unstable',
'repos' => 'main contrib non-free', 'repos' => 'main contrib non-free',
'key' => '55BE302B', 'key' => { 'id' => '55BE302B', 'server' => 'subkeys.pgp.net' },
'key_server' => 'subkeys.pgp.net',
'pin' => '-10', 'pin' => '-10',
'include_src' => true, 'include_src' => true,
}, },
'puppetlabs' => { 'puppetlabs' => {
'location' => 'http://apt.puppetlabs.com', 'location' => 'http://apt.puppetlabs.com',
'repos' => 'main', 'repos' => 'main',
'key' => '4BD6EC30', 'key' => { 'id' => '4BD6EC30', 'server' => 'pgp.mit.edu' },
'key_server' => 'pgp.mit.edu',
} }
} } } } } }
@ -163,13 +169,66 @@ describe 'apt' do
it { is_expected.to contain_file('/etc/apt/sources.list.d/puppetlabs.list').with_content(/^deb http:\/\/apt.puppetlabs.com precise main$/) } it { is_expected.to contain_file('/etc/apt/sources.list.d/puppetlabs.list').with_content(/^deb http:\/\/apt.puppetlabs.com precise main$/) }
end end
context 'with keys defined on valid osfamily' do
let :facts do
{ :osfamily => 'Debian',
:lsbdistcodename => 'precise',
:lsbdistid => 'Debian',
}
end
let(:params) { { :keys => {
'55BE302B' => {
'server' => 'subkeys.pgp.net',
},
'4BD6EC30' => {
'server' => 'pgp.mit.edu',
}
} } }
it { is_expected.to contain_apt__key('55BE302B').with({
:server => 'subkeys.pgp.net',
})}
it { is_expected.to contain_apt__key('4BD6EC30').with({
:server => 'pgp.mit.edu',
})}
end
context 'with ppas defined on valid osfamily' do
let :facts do
{ :osfamily => 'Debian',
:lsbdistcodename => 'precise',
:lsbdistid => 'ubuntu',
}
end
let(:params) { { :ppas => {
'ppa:drizzle-developers/ppa' => {},
'ppa:nginx/stable' => {},
} } }
it { is_expected.to contain_apt__ppa('ppa:drizzle-developers/ppa')}
it { is_expected.to contain_apt__ppa('ppa:nginx/stable')}
end
context 'with settings defined on valid osfamily' do
let :facts do
{ :osfamily => 'Debian',
:lsbdistcodename => 'precise',
:lsbdistid => 'Debian',
}
end
let(:params) { { :settings => {
'conf-banana' => { 'content' => 'banana' },
'pref-banana' => { 'content' => 'banana' },
} } }
it { is_expected.to contain_apt__setting('conf-banana')}
it { is_expected.to contain_apt__setting('pref-banana')}
end
describe 'failing tests' do describe 'failing tests' do
context 'bad purge_sources_list' do context "purge['sources.list']=>'banana'" do
let :params do let(:params) { { :purge => { 'sources.list' => 'banana' }, } }
{
:purge_sources_list => 'foo'
}
end
it do it do
expect { expect {
is_expected.to compile is_expected.to compile
@ -177,12 +236,8 @@ describe 'apt' do
end end
end end
context 'bad purge_sources_list_d' do context "purge['sources.list.d']=>'banana'" do
let :params do let(:params) { { :purge => { 'sources.list.d' => 'banana' }, } }
{
:purge_sources_list_d => 'foo'
}
end
it do it do
expect { expect {
is_expected.to compile is_expected.to compile
@ -190,12 +245,8 @@ describe 'apt' do
end end
end end
context 'bad purge_preferences' do context "purge['preferences']=>'banana'" do
let :params do let(:params) { { :purge => { 'preferences' => 'banana' }, } }
{
:purge_preferences => 'foo'
}
end
it do it do
expect { expect {
is_expected.to compile is_expected.to compile
@ -203,12 +254,8 @@ describe 'apt' do
end end
end end
context 'bad purge_preferences_d' do context "purge['preferences.d']=>'banana'" do
let :params do let(:params) { { :purge => { 'preferences.d' => 'banana' }, } }
{
:purge_preferences_d => 'foo'
}
end
it do it do
expect { expect {
is_expected.to compile is_expected.to compile

View file

@ -2,20 +2,20 @@
require 'spec_helper' require 'spec_helper'
describe 'apt::update', :type => :class do describe 'apt::update', :type => :class do
context 'when apt::always_apt_update is true' do context "when update['always']=true" do
#This should completely disable all of this logic. These tests are to guarantee that we don't somehow magically change the behavior. #This should completely disable all of this logic. These tests are to guarantee that we don't somehow magically change the behavior.
let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian' } } let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian' } }
let (:pre_condition) { "class{'::apt': always_apt_update => true}" } let (:pre_condition) { "class{'::apt': update => {'always' => true},}" }
it 'should trigger an apt-get update run' do it 'should trigger an apt-get update run' do
#set the apt_update exec's refreshonly attribute to false #set the apt_update exec's refreshonly attribute to false
is_expected.to contain_exec('apt_update').with({'refreshonly' => false }) is_expected.to contain_exec('apt_update').with({'refreshonly' => false })
end end
['always','daily','weekly','reluctantly'].each do |update_frequency| ['always','daily','weekly','reluctantly'].each do |update_frequency|
context "when apt::apt_update_frequency has the value of #{update_frequency}" do context "when apt::update['frequency'] has the value of #{update_frequency}" do
{ 'a recent run' => Time.now.to_i, 'we are due for a run' => 1406660561,'the update-success-stamp file does not exist' => -1 }.each_pair do |desc, factval| { 'a recent run' => Time.now.to_i, 'we are due for a run' => 1406660561,'the update-success-stamp file does not exist' => -1 }.each_pair do |desc, factval|
context "and $::apt_update_last_success indicates #{desc}" do context "and $::apt_update_last_success indicates #{desc}" do
let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :apt_update_last_success => factval } } let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :apt_update_last_success => factval } }
let (:pre_condition) { "class{'::apt': always_apt_update => true, apt_update_frequency => '#{update_frequency}' }" } let (:pre_condition) { "class{'::apt': update => {'always' => true, 'frequency' => '#{update_frequency}'}, }" }
it 'should trigger an apt-get update run' do it 'should trigger an apt-get update run' do
# set the apt_update exec's refreshonly attribute to false # set the apt_update exec's refreshonly attribute to false
is_expected.to contain_exec('apt_update').with({'refreshonly' => false}) is_expected.to contain_exec('apt_update').with({'refreshonly' => false})
@ -23,7 +23,7 @@ describe 'apt::update', :type => :class do
end end
context 'when $::apt_update_last_success is nil' do context 'when $::apt_update_last_success is nil' do
let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian' } } let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian' } }
let (:pre_condition) { "class{'::apt': always_apt_update => true, apt_update_frequency => '#{update_frequency}' }" } let (:pre_condition) { "class{'::apt': update => {'always' => true, 'frequency' => '#{update_frequency}'}, }" }
it 'should trigger an apt-get update run' do it 'should trigger an apt-get update run' do
#set the apt_update exec\'s refreshonly attribute to false #set the apt_update exec\'s refreshonly attribute to false
is_expected.to contain_exec('apt_update').with({'refreshonly' => false}) is_expected.to contain_exec('apt_update').with({'refreshonly' => false})
@ -34,12 +34,12 @@ describe 'apt::update', :type => :class do
end end
end end
context 'when apt::always_apt_update is false' do context "when apt::update['always']=false" do
context "and apt::apt_update_frequency has the value of always" do context "and apt::update['frequency']='always'" do
{ 'a recent run' => Time.now.to_i, 'we are due for a run' => 1406660561,'the update-success-stamp file does not exist' => -1 }.each_pair do |desc, factval| { 'a recent run' => Time.now.to_i, 'we are due for a run' => 1406660561,'the update-success-stamp file does not exist' => -1 }.each_pair do |desc, factval|
context "and $::apt_update_last_success indicates #{desc}" do context "and $::apt_update_last_success indicates #{desc}" do
let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :apt_update_last_success => factval } } let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :apt_update_last_success => factval } }
let (:pre_condition) { "class{'::apt': always_apt_update => false, apt_update_frequency => 'always' }" } let (:pre_condition) { "class{'::apt': update => {'always' => false, 'frequency' => 'always' },}" }
it 'should trigger an apt-get update run' do it 'should trigger an apt-get update run' do
#set the apt_update exec's refreshonly attribute to false #set the apt_update exec's refreshonly attribute to false
is_expected.to contain_exec('apt_update').with({'refreshonly' => false}) is_expected.to contain_exec('apt_update').with({'refreshonly' => false})
@ -48,18 +48,18 @@ describe 'apt::update', :type => :class do
end end
context 'when $::apt_update_last_success is nil' do context 'when $::apt_update_last_success is nil' do
let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian' } } let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian' } }
let (:pre_condition) { "class{ '::apt': always_apt_update => false, apt_update_frequency => 'always' }" } let (:pre_condition) { "class{ '::apt': update => {'always' => false, 'frequency' => 'always' },}" }
it 'should trigger an apt-get update run' do it 'should trigger an apt-get update run' do
#set the apt_update exec\'s refreshonly attribute to false #set the apt_update exec\'s refreshonly attribute to false
is_expected.to contain_exec('apt_update').with({'refreshonly' => false}) is_expected.to contain_exec('apt_update').with({'refreshonly' => false})
end end
end end
end end
context "and apt::apt_update_frequency has the value of reluctantly" do context "and apt::update['frequency']='reluctantly'" do
{'a recent run' => Time.now.to_i, 'we are due for a run' => 1406660561,'the update-success-stamp file does not exist' => -1 }.each_pair do |desc, factval| {'a recent run' => Time.now.to_i, 'we are due for a run' => 1406660561,'the update-success-stamp file does not exist' => -1 }.each_pair do |desc, factval|
context "and $::apt_update_last_success indicates #{desc}" do context "and $::apt_update_last_success indicates #{desc}" do
let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :apt_update_last_success => factval} } let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :apt_update_last_success => factval} }
let (:pre_condition) { "class{ '::apt': always_apt_update => false, apt_update_frequency => 'reluctantly' }" } let (:pre_condition) { "class{ '::apt': update => {'always' => false, 'frequency' => 'reluctantly' },}" }
it 'should not trigger an apt-get update run' do it 'should not trigger an apt-get update run' do
#don't change the apt_update exec's refreshonly attribute. (it should be true) #don't change the apt_update exec's refreshonly attribute. (it should be true)
is_expected.to contain_exec('apt_update').with({'refreshonly' => true}) is_expected.to contain_exec('apt_update').with({'refreshonly' => true})
@ -68,7 +68,7 @@ describe 'apt::update', :type => :class do
end end
context 'when $::apt_update_last_success is nil' do context 'when $::apt_update_last_success is nil' do
let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian' } } let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian' } }
let (:pre_condition) { "class{ '::apt': always_apt_update => false, apt_update_frequency => 'reluctantly' }" } let (:pre_condition) { "class{ '::apt': update => {'always' => false, 'frequency' => 'reluctantly' },}" }
it 'should not trigger an apt-get update run' do it 'should not trigger an apt-get update run' do
#don't change the apt_update exec's refreshonly attribute. (it should be true) #don't change the apt_update exec's refreshonly attribute. (it should be true)
is_expected.to contain_exec('apt_update').with({'refreshonly' => true}) is_expected.to contain_exec('apt_update').with({'refreshonly' => true})
@ -76,11 +76,11 @@ describe 'apt::update', :type => :class do
end end
end end
['daily','weekly'].each do |update_frequency| ['daily','weekly'].each do |update_frequency|
context "and apt::apt_update_frequency has the value of #{update_frequency}" do context "and apt::update['frequency'] has the value of #{update_frequency}" do
{ 'we are due for a run' => 1406660561,'the update-success-stamp file does not exist' => -1 }.each_pair do |desc, factval| { 'we are due for a run' => 1406660561,'the update-success-stamp file does not exist' => -1 }.each_pair do |desc, factval|
context "and $::apt_update_last_success indicates #{desc}" do context "and $::apt_update_last_success indicates #{desc}" do
let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :apt_update_last_success => factval } } let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :apt_update_last_success => factval } }
let (:pre_condition) { "class{ '::apt': always_apt_update => false, apt_update_frequency => '#{update_frequency}' }" } let (:pre_condition) { "class{ '::apt': update => {'always' => false, 'frequency' => '#{update_frequency}',} }" }
it 'should trigger an apt-get update run' do it 'should trigger an apt-get update run' do
#set the apt_update exec\'s refreshonly attribute to false #set the apt_update exec\'s refreshonly attribute to false
is_expected.to contain_exec('apt_update').with({'refreshonly' => false}) is_expected.to contain_exec('apt_update').with({'refreshonly' => false})
@ -89,7 +89,7 @@ describe 'apt::update', :type => :class do
end end
context 'when the $::apt_update_last_success fact has a recent value' do context 'when the $::apt_update_last_success fact has a recent value' do
let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :apt_update_last_success => Time.now.to_i } } let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :apt_update_last_success => Time.now.to_i } }
let (:pre_condition) { "class{ '::apt': always_apt_update => false, apt_update_frequency => '#{update_frequency}' }" } let (:pre_condition) { "class{ '::apt': update => {'always' => false, 'frequency' => '#{update_frequency}',} }" }
it 'should not trigger an apt-get update run' do it 'should not trigger an apt-get update run' do
#don't change the apt_update exec\'s refreshonly attribute. (it should be true) #don't change the apt_update exec\'s refreshonly attribute. (it should be true)
is_expected.to contain_exec('apt_update').with({'refreshonly' => true}) is_expected.to contain_exec('apt_update').with({'refreshonly' => true})
@ -97,7 +97,7 @@ describe 'apt::update', :type => :class do
end end
context 'when $::apt_update_last_success is nil' do context 'when $::apt_update_last_success is nil' do
let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian' } } let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian' } }
let (:pre_condition) { "class{ '::apt': always_apt_update => false, apt_update_frequency => '#{update_frequency}' }" } let (:pre_condition) { "class{ '::apt': update => {'always' => false, 'frequency' => '#{update_frequency}',} }" }
it 'should trigger an apt-get update run' do it 'should trigger an apt-get update run' do
#set the apt_update exec\'s refreshonly attribute to false #set the apt_update exec\'s refreshonly attribute to false
is_expected.to contain_exec('apt_update').with({'refreshonly' => false}) is_expected.to contain_exec('apt_update').with({'refreshonly' => false})

View file

@ -1,6 +1,6 @@
require 'spec_helper' require 'spec_helper'
describe 'apt::key', :type => :define do describe 'apt::key' do
let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian' } } let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian' } }
GPG_KEY_ID = '47B320EB4C7C375AA9DAE1A01054B7A24BD6EC30' GPG_KEY_ID = '47B320EB4C7C375AA9DAE1A01054B7A24BD6EC30'
@ -17,7 +17,7 @@ describe 'apt::key', :type => :define do
:source => nil, :source => nil,
:server => nil, :server => nil,
:content => nil, :content => nil,
:keyserver_options => nil, :options => nil,
}) })
end end
it 'contains the apt_key present anchor' do it 'contains the apt_key present anchor' do
@ -31,7 +31,7 @@ describe 'apt::key', :type => :define do
end end
let :params do { let :params do {
:key => GPG_KEY_ID, :id => GPG_KEY_ID,
} end } end
it 'contains the apt_key' do it 'contains the apt_key' do
@ -41,7 +41,7 @@ describe 'apt::key', :type => :define do
:source => nil, :source => nil,
:server => nil, :server => nil,
:content => nil, :content => nil,
:keyserver_options => nil, :options => nil,
}) })
end end
it 'contains the apt_key present anchor' do it 'contains the apt_key present anchor' do
@ -61,7 +61,7 @@ describe 'apt::key', :type => :define do
:source => nil, :source => nil,
:server => nil, :server => nil,
:content => nil, :content => nil,
:keyserver_options => nil, :keyserver => nil,
}) })
end end
it 'contains the apt_key absent anchor' do it 'contains the apt_key absent anchor' do
@ -71,10 +71,10 @@ describe 'apt::key', :type => :define do
describe 'set a bunch of things!' do describe 'set a bunch of things!' do
let :params do { let :params do {
:key_content => 'GPG key content', :content => 'GPG key content',
:key_source => 'http://apt.puppetlabs.com/pubkey.gpg', :source => 'http://apt.puppetlabs.com/pubkey.gpg',
:key_server => 'pgp.mit.edu', :server => 'pgp.mit.edu',
:key_options => 'debug', :options => 'debug',
} end } end
it 'contains the apt_key' do it 'contains the apt_key' do
@ -83,8 +83,8 @@ describe 'apt::key', :type => :define do
:ensure => 'present', :ensure => 'present',
:source => 'http://apt.puppetlabs.com/pubkey.gpg', :source => 'http://apt.puppetlabs.com/pubkey.gpg',
:server => 'pgp.mit.edu', :server => 'pgp.mit.edu',
:content => params[:key_content], :content => params[:content],
:keyserver_options => 'debug', :options => 'debug',
}) })
end end
it 'contains the apt_key present anchor' do it 'contains the apt_key present anchor' do
@ -94,7 +94,7 @@ describe 'apt::key', :type => :define do
context "domain with dash" do context "domain with dash" do
let(:params) do{ let(:params) do{
:key_server => 'p-gp.m-it.edu', :server => 'p-gp.m-it.edu',
} end } end
it 'contains the apt_key' do it 'contains the apt_key' do
is_expected.to contain_apt_key(title).with({ is_expected.to contain_apt_key(title).with({
@ -107,7 +107,7 @@ describe 'apt::key', :type => :define do
context "url" do context "url" do
let :params do let :params do
{ {
:key_server => 'hkp://pgp.mit.edu', :server => 'hkp://pgp.mit.edu',
} }
end end
it 'contains the apt_key' do it 'contains the apt_key' do
@ -120,7 +120,7 @@ describe 'apt::key', :type => :define do
context "url with port number" do context "url with port number" do
let :params do let :params do
{ {
:key_server => 'hkp://pgp.mit.edu:80', :server => 'hkp://pgp.mit.edu:80',
} }
end end
it 'contains the apt_key' do it 'contains the apt_key' do
@ -135,7 +135,7 @@ describe 'apt::key', :type => :define do
describe 'validation' do describe 'validation' do
context "domain begin with dash" do context "domain begin with dash" do
let(:params) do{ let(:params) do{
:key_server => '-pgp.mit.edu', :server => '-pgp.mit.edu',
} end } end
it 'fails' do it 'fails' do
expect { subject } .to raise_error(/does not match/) expect { subject } .to raise_error(/does not match/)
@ -144,7 +144,7 @@ describe 'apt::key', :type => :define do
context "domain begin with dot" do context "domain begin with dot" do
let(:params) do{ let(:params) do{
:key_server => '.pgp.mit.edu', :server => '.pgp.mit.edu',
} end } end
it 'fails' do it 'fails' do
expect { subject } .to raise_error(/does not match/) expect { subject } .to raise_error(/does not match/)
@ -153,7 +153,7 @@ describe 'apt::key', :type => :define do
context "domain end with dot" do context "domain end with dot" do
let(:params) do{ let(:params) do{
:key_server => "pgp.mit.edu.", :server => "pgp.mit.edu.",
} end } end
it 'fails' do it 'fails' do
expect { subject } .to raise_error(/does not match/) expect { subject } .to raise_error(/does not match/)
@ -162,7 +162,7 @@ describe 'apt::key', :type => :define do
context "exceed character url" do context "exceed character url" do
let :params do let :params do
{ {
:key_server => 'hkp://pgpiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii.mit.edu' :server => 'hkp://pgpiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii.mit.edu'
} }
end end
it 'fails' do it 'fails' do
@ -172,7 +172,7 @@ describe 'apt::key', :type => :define do
context "incorrect port number url" do context "incorrect port number url" do
let :params do let :params do
{ {
:key_server => 'hkp://pgp.mit.edu:8008080' :server => 'hkp://pgp.mit.edu:8008080'
} }
end end
it 'fails' do it 'fails' do
@ -182,7 +182,7 @@ describe 'apt::key', :type => :define do
context "incorrect protocol for url" do context "incorrect protocol for url" do
let :params do let :params do
{ {
:key_server => 'abc://pgp.mit.edu:80' :server => 'abc://pgp.mit.edu:80'
} }
end end
it 'fails' do it 'fails' do
@ -192,7 +192,7 @@ describe 'apt::key', :type => :define do
context "missing port number url" do context "missing port number url" do
let :params do let :params do
{ {
:key_server => 'hkp://pgp.mit.edu:' :server => 'hkp://pgp.mit.edu:'
} }
end end
it 'fails' do it 'fails' do
@ -202,7 +202,7 @@ describe 'apt::key', :type => :define do
context "url ending with a dot" do context "url ending with a dot" do
let :params do let :params do
{ {
:key_server => 'hkp://pgp.mit.edu.' :server => 'hkp://pgp.mit.edu.'
} }
end end
it 'fails' do it 'fails' do
@ -211,7 +211,7 @@ describe 'apt::key', :type => :define do
end end
context "url begin with a dash" do context "url begin with a dash" do
let(:params) do{ let(:params) do{
:key_server => "hkp://-pgp.mit.edu", :server => "hkp://-pgp.mit.edu",
} end } end
it 'fails' do it 'fails' do
expect { subject }.to raise_error(/does not match/) expect { subject }.to raise_error(/does not match/)
@ -228,7 +228,7 @@ describe 'apt::key', :type => :define do
context 'invalid source' do context 'invalid source' do
let :params do { let :params do {
:key_source => 'afp://puppetlabs.com/key.gpg', :source => 'afp://puppetlabs.com/key.gpg',
} end } end
it 'fails' do it 'fails' do
expect { subject }.to raise_error(/does not match/) expect { subject }.to raise_error(/does not match/)
@ -237,7 +237,7 @@ describe 'apt::key', :type => :define do
context 'invalid content' do context 'invalid content' do
let :params do { let :params do {
:key_content => [], :content => [],
} end } end
it 'fails' do it 'fails' do
expect { subject }.to raise_error(/is not a string/) expect { subject }.to raise_error(/is not a string/)
@ -246,16 +246,16 @@ describe 'apt::key', :type => :define do
context 'invalid server' do context 'invalid server' do
let :params do { let :params do {
:key_server => 'two bottles of rum', :server => 'two bottles of rum',
} end } end
it 'fails' do it 'fails' do
expect { subject }.to raise_error(/does not match/) expect { subject }.to raise_error(/does not match/)
end end
end end
context 'invalid keyserver_options' do context 'invalid options' do
let :params do { let :params do {
:key_options => {}, :options => {},
} end } end
it 'fails' do it 'fails' do
expect { subject }.to raise_error(/is not a string/) expect { subject }.to raise_error(/is not a string/)
@ -276,16 +276,16 @@ describe 'apt::key', :type => :define do
describe 'duplication' do describe 'duplication' do
context 'two apt::key resources for same key, different titles' do context 'two apt::key resources for same key, different titles' do
let :pre_condition do let :pre_condition do
"apt::key { 'duplicate': key => '#{title}', }" "apt::key { 'duplicate': id => '#{title}', }"
end end
it 'contains two apt::key resources' do it 'contains two apt::key resources' do
is_expected.to contain_apt__key('duplicate').with({ is_expected.to contain_apt__key('duplicate').with({
:key => title, :id => title,
:ensure => 'present', :ensure => 'present',
}) })
is_expected.to contain_apt__key(title).with({ is_expected.to contain_apt__key(title).with({
:key => title, :id => title,
:ensure => 'present', :ensure => 'present',
}) })
end end
@ -297,7 +297,7 @@ describe 'apt::key', :type => :define do
:source => nil, :source => nil,
:server => nil, :server => nil,
:content => nil, :content => nil,
:keyserver_options => nil, :options => nil,
}) })
is_expected.not_to contain_apt_key(title) is_expected.not_to contain_apt_key(title)
end end
@ -305,7 +305,7 @@ describe 'apt::key', :type => :define do
context 'two apt::key resources, different ensure' do context 'two apt::key resources, different ensure' do
let :pre_condition do let :pre_condition do
"apt::key { 'duplicate': key => '#{title}', ensure => 'absent', }" "apt::key { 'duplicate': id => '#{title}', ensure => 'absent', }"
end end
it 'informs the user of the impossibility' do it 'informs the user of the impossibility' do
expect { subject }.to raise_error(/already ensured as absent/) expect { subject }.to raise_error(/already ensured as absent/)

View file

@ -214,7 +214,7 @@ describe 'apt::ppa' do
it do it do
expect { expect {
is_expected.to compile is_expected.to compile
}.to raise_error(Puppet::Error, /apt::ppa is currently supported on Ubuntu only./) }.to raise_error(Puppet::Error, /supported on Ubuntu and LinuxMint only/)
end end
end end
end end

View file

@ -1,6 +1,6 @@
require 'spec_helper' require 'spec_helper'
describe 'apt::source', :type => :define do describe 'apt::source' do
GPG_KEY_ID = '47B320EB4C7C375AA9DAE1A01054B7A24BD6EC30' GPG_KEY_ID = '47B320EB4C7C375AA9DAE1A01054B7A24BD6EC30'
let :pre_condition do let :pre_condition do
@ -22,18 +22,19 @@ describe 'apt::source', :type => :define do
let :params do let :params do
{ {
'include_deb' => false, :include_deb => false,
'include_src' => true, :include_src => true,
} }
end end
it { is_expected.to contain_apt__setting('list-my_source').with({ it { is_expected.to contain_apt__setting('list-my_source').with({
'ensure' => 'present', :ensure => 'present',
}).with_content(/# my_source\ndeb-src wheezy main\n/) }).with_content(/# my_source\ndeb-src wheezy main\n/)
} }
end end
context 'no defaults' do describe 'no defaults' do
let :facts do let :facts do
{ {
:lsbdistid => 'Debian', :lsbdistid => 'Debian',
@ -41,45 +42,114 @@ describe 'apt::source', :type => :define do
:osfamily => 'Debian' :osfamily => 'Debian'
} }
end end
context 'with simple key' do
let :params do let :params do
{ {
'comment' => 'foo', :comment => 'foo',
'location' => 'http://debian.mirror.iweb.ca/debian/', :location => 'http://debian.mirror.iweb.ca/debian/',
'release' => 'sid', :release => 'sid',
'repos' => 'testing', :repos => 'testing',
'include_src' => false, :include_src => false,
'key' => GPG_KEY_ID, :key => GPG_KEY_ID,
'key_server' => 'pgp.mit.edu', :pin => '10',
'key_content' => 'GPG key content', :architecture => 'x86_64',
'key_source' => 'http://apt.puppetlabs.com/pubkey.gpg', :trusted_source => true,
'pin' => '10',
'architecture' => 'x86_64',
'trusted_source' => true,
} }
end end
it { is_expected.to contain_apt__setting('list-my_source').with({ it { is_expected.to contain_apt__setting('list-my_source').with({
'ensure' => 'present', :ensure => 'present',
}).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('Apt::Setting[list-my_source]').with({ it { is_expected.to contain_apt__pin('my_source').that_comes_before('Apt::Setting[list-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('Apt::Setting[list-my_source]').with({ 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', :ensure => 'present',
'key' => GPG_KEY_ID, :id => GPG_KEY_ID,
'key_server' => 'pgp.mit.edu',
'key_content' => 'GPG key content',
'key_source' => 'http://apt.puppetlabs.com/pubkey.gpg',
}) })
} }
end end
context 'with complex key' do
let :params do
{
:comment => 'foo',
: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',},
:pin => '10',
:architecture => 'x86_64',
:trusted_source => 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',
:include_src => false,
:key => GPG_KEY_ID,
:pin => '10',
:architecture => 'x86_64',
:trusted_source => 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 'trusted_source true' do context 'trusted_source true' do
let :facts do let :facts do
{ {
@ -90,13 +160,13 @@ describe 'apt::source', :type => :define do
end end
let :params do let :params do
{ {
'include_src' => false, :include_src => false,
'trusted_source' => true, :trusted_source => true,
} }
end end
it { is_expected.to contain_apt__setting('list-my_source').with({ it { is_expected.to contain_apt__setting('list-my_source').with({
'ensure' => 'present', :ensure => 'present',
}).with_content(/# my_source\ndeb \[trusted=yes\] wheezy main\n/) }).with_content(/# my_source\ndeb \[trusted=yes\] wheezy main\n/)
} }
end end
@ -111,14 +181,14 @@ describe 'apt::source', :type => :define do
end end
let :params do let :params do
{ {
'include_deb' => false, :include_deb => false,
'include_src' => true, :include_src => true,
'architecture' => 'x86_64', :architecture => 'x86_64',
} }
end end
it { is_expected.to contain_apt__setting('list-my_source').with({ it { is_expected.to contain_apt__setting('list-my_source').with({
'ensure' => 'present', :ensure => 'present',
}).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
@ -133,12 +203,12 @@ describe 'apt::source', :type => :define do
end end
let :params do let :params do
{ {
'ensure' => 'absent', :ensure => 'absent',
} }
end end
it { is_expected.to contain_apt__setting('list-my_source').with({ it { is_expected.to contain_apt__setting('list-my_source').with({
'ensure' => 'absent' :ensure => 'absent'
}) })
} }
end end