source: Support complex pin, like key does.
This adds support for passing in a full pin declaration as the pin parameter on a source declaration. It keeps the old behaviour intact, you can still simply do `pin => '10'` and it will pin on origin with a priority of 10. Should that not be what you want you can now pass in a full pin declaration instead. We make no assumptions here, whatever you pass in will be passed through to pin as-is with the exception of the values for `ensure` and `before` which are always overridden by us to ensure everything keeps working as designed.
This commit is contained in:
parent
778aae8e13
commit
791012b2c9
2 changed files with 64 additions and 11 deletions
|
@ -8,7 +8,7 @@ define apt::source(
|
|||
$repos = 'main',
|
||||
$include = {},
|
||||
$key = undef,
|
||||
$pin = false,
|
||||
$pin = undef,
|
||||
$architecture = undef,
|
||||
$allow_unsigned = false,
|
||||
) {
|
||||
|
@ -44,17 +44,22 @@ define apt::source(
|
|||
content => template('apt/_header.erb', 'apt/source.list.erb'),
|
||||
}
|
||||
|
||||
if ($pin != false) {
|
||||
# Get the host portion out of the url so we can pin to origin
|
||||
$url_split = split($location, '/')
|
||||
$host = $url_split[2]
|
||||
|
||||
apt::pin { $name:
|
||||
ensure => $ensure,
|
||||
priority => $pin,
|
||||
before => $_before,
|
||||
origin => $host,
|
||||
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[2]
|
||||
$_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.
|
||||
|
|
|
@ -51,6 +51,31 @@ describe 'apt::source' do
|
|||
:osfamily => 'Debian'
|
||||
}
|
||||
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_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
|
||||
{
|
||||
|
@ -235,5 +260,28 @@ describe 'apt::source' do
|
|||
}.to raise_error(Puppet::Error, /lsbdistcodename fact not available: release parameter required/)
|
||||
end
|
||||
end
|
||||
|
||||
context 'invalid pin' do
|
||||
let :facts do
|
||||
{
|
||||
:lsbdistid => 'Debian',
|
||||
:lsbdistcodename => 'wheezy',
|
||||
:osfamily => 'Debian'
|
||||
}
|
||||
end
|
||||
let :params do
|
||||
{
|
||||
:location => 'hello.there',
|
||||
:pin => true,
|
||||
}
|
||||
end
|
||||
|
||||
it do
|
||||
expect {
|
||||
is_expected.to compile
|
||||
}.to raise_error(Puppet::Error, /invalid value for pin/)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue