module-puppetlabs-apt/manifests/source.pp
Reid Vandewiele d4fec561f3 Modify apt::source release parameter test
This commit modifies the release parameter test in apt::source to work
correctly within puppet-rspec for edge-case resource definitions. Previously,
the test for the $release parameter was written as

`if ! $release { fail() }`

This commit updates the test to be written as

`if $release == undef { fail() }`

Additionally, the tests for correct behavior in the presence or absence of a
$release parameter have been beefed up.

The reason for making this change relates to examples such as the following
resource definition:

apt::source { "jenkins":
  location    => "http://pkg.jenkins-ci.org/debian",
  release     => "",
  repos       => "binary/",
  key         => "D50582E6",
  key_source  => "http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key",
  include_src => false,
}

Note that the $release parameter is given as the empty string. In practice,
this is perfectly valid and everything will work great. However, it seems that
the empty string gets interpreted by something in puppet-rspec as something
equivalent to "False", and thus when testing, the above resource definition
would fail with "Puppet::Error: lsbdistcodename fact not available: release
parameter required" even though the $release parameter has been explicitely
specified (as the empty string).

See also: https://github.com/rtyler/puppet-jenkins/issues/9
2012-03-07 10:10:46 -08:00

60 lines
1.4 KiB
Puppet

# source.pp
# add an apt source
define apt::source(
$location = '',
$release = $lsbdistcodename,
$repos = 'main',
$include_src = true,
$required_packages = false,
$key = false,
$key_server = 'keyserver.ubuntu.com',
$key_content = false,
$key_source = false,
$pin = false
) {
include apt::params
if $release == undef {
fail("lsbdistcodename fact not available: release parameter required")
}
file { "${name}.list":
path => "${apt::params::root}/sources.list.d/${name}.list",
ensure => file,
owner => root,
group => root,
mode => 644,
content => template("apt/source.list.erb"),
}
if $pin != false {
apt::pin { "${release}": priority => "${pin}" } -> File["${name}.list"]
}
exec { "${name} apt update":
command => "${apt::params::provider} update",
subscribe => File["${name}.list"],
refreshonly => true,
}
if $required_packages != false {
exec { "Required packages: '${required_packages}' for ${name}":
command => "${apt::params::provider} -y install ${required_packages}",
subscribe => File["${name}.list"],
refreshonly => true,
}
}
if $key != false {
apt::key { "Add key: ${key} from Apt::Source ${title}":
key => $key,
ensure => present,
key_server => $key_server,
key_content => $key_content,
key_source => $key_source,
before => File["${name}.list"],
}
}
}