Merge pull request #582 from imphil/master

Look for correct sources.list.d file for apt::ppa
This commit is contained in:
Bryan Jen 2016-02-04 12:29:15 -07:00
commit cc537070e8
3 changed files with 65 additions and 33 deletions

View file

@ -14,11 +14,19 @@ define apt::ppa(
fail('apt::ppa is not currently supported on Debian.')
}
$filename_without_slashes = regsubst($name, '/', '-', 'G')
$filename_without_dots = regsubst($filename_without_slashes, '\.', '_', 'G')
$filename_without_pluses = regsubst($filename_without_dots, '\+', '_', 'G')
$filename_without_ppa = regsubst($filename_without_pluses, '^ppa:', '', 'G')
$sources_list_d_filename = "${filename_without_ppa}-${release}.list"
$ubuntu_release_year = regsubst($::apt::xfacts['lsbdistrelease'], '\.\d+$', '', 'G') + 0
$ubuntu_release_month = regsubst($::apt::xfacts['lsbdistrelease'], '^\d+\.', '', 'G') + 0
if $ubuntu_release_year >= 15 and $ubuntu_release_month >= 10 {
$distid = downcase($::apt::xfacts['lsbdistid'])
$filename = regsubst($name, '^ppa:([^/]+)/(.+)$', "\\1-${distid}-\\2-${release}")
} else {
$filename = regsubst($name, '^ppa:([^/]+)/(.+)$', "\\1-\\2-${release}")
}
$filename_no_slashes = regsubst($filename, '/', '-', 'G')
$filename_no_specialchars = regsubst($filename_no_slashes, '[\.\+]', '_', 'G')
$sources_list_d_filename = "${filename_no_specialchars}.list"
if $ensure == 'present' {
if $package_manage {

View file

@ -208,6 +208,7 @@ describe 'apt' do
{ :osfamily => 'Debian',
:lsbdistcodename => 'precise',
:lsbdistid => 'ubuntu',
:lsbdistrelease => '12.04',
:puppetversion => Puppet.version,
}
end

View file

@ -28,6 +28,29 @@ describe 'apt::ppa' do
}
end
describe 'Ubuntu 15.10 sources.list filename' do
let :facts do
{
:lsbdistrelease => '15.10',
:lsbdistcodename => 'wily',
:operatingsystem => 'Ubuntu',
:osfamily => 'Debian',
:lsbdistid => 'Ubuntu',
:puppetversion => Puppet.version,
}
end
let(:title) { 'ppa:user/foo' }
it { is_expected.to contain_exec('add-apt-repository-ppa:user/foo').that_notifies('Class[Apt::Update]').with({
:environment => [],
:command => '/usr/bin/add-apt-repository -y ppa:user/foo',
:unless => '/usr/bin/test -s /etc/apt/sources.list.d/user-ubuntu-foo-wily.list',
:user => 'root',
:logoutput => 'on_failure',
})
}
end
describe 'ppa depending on ppa, MODULES-1156' do
let :pre_condition do
'class { "apt": }'
@ -75,7 +98,7 @@ describe 'apt::ppa' do
describe 'package_manage => true, multiple ppas, MODULES-2873' do
let :pre_condition do
'class { "apt": }
apt::ppa {"ppa:foo":
apt::ppa {"ppa:user/foo":
package_manage => true
}'
end
@ -95,18 +118,18 @@ describe 'apt::ppa' do
}
end
let(:title) { 'ppa:bar' }
let(:title) { 'ppa:user/bar' }
it { is_expected.to contain_package('python-software-properties') }
it { is_expected.to contain_exec('add-apt-repository-ppa:bar').that_notifies('Class[Apt::Update]').with({
it { is_expected.to contain_exec('add-apt-repository-ppa:user/bar').that_notifies('Class[Apt::Update]').with({
'environment' => [],
'command' => '/usr/bin/add-apt-repository -y ppa:bar',
'unless' => '/usr/bin/test -s /etc/apt/sources.list.d/bar-natty.list',
'command' => '/usr/bin/add-apt-repository -y ppa:user/bar',
'unless' => '/usr/bin/test -s /etc/apt/sources.list.d/user-bar-natty.list',
'user' => 'root',
'logoutput' => 'on_failure',
})
}
it { is_expected.to contain_file('/etc/apt/sources.list.d/bar-natty.list').that_requires('Exec[add-apt-repository-ppa:bar]').with({
it { is_expected.to contain_file('/etc/apt/sources.list.d/user-bar-natty.list').that_requires('Exec[add-apt-repository-ppa:user/bar]').with({
'ensure' => 'file',
})
}
@ -152,7 +175,7 @@ describe 'apt::ppa' do
describe 'apt included, no proxy' do
let :pre_condition do
'class { "apt": }
apt::ppa { "ppa:foo2": }
apt::ppa { "ppa:user/foo2": }
'
end
let :facts do
@ -169,16 +192,16 @@ describe 'apt::ppa' do
{
:options => '',
:package_manage => true,
:require => 'Apt::Ppa[ppa:foo2]',
:require => 'Apt::Ppa[ppa:user/foo2]',
}
end
let(:title) { 'ppa:foo' }
let(:title) { 'ppa:user/foo' }
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_package('software-properties-common') }
it { is_expected.to contain_exec('add-apt-repository-ppa:foo').that_notifies('Class[Apt::Update]').with({
it { is_expected.to contain_exec('add-apt-repository-ppa:user/foo').that_notifies('Class[Apt::Update]').with({
:environment => [],
:command => '/usr/bin/add-apt-repository ppa:foo',
:unless => '/usr/bin/test -s /etc/apt/sources.list.d/foo-trusty.list',
:command => '/usr/bin/add-apt-repository ppa:user/foo',
:unless => '/usr/bin/test -s /etc/apt/sources.list.d/user-foo-trusty.list',
:user => 'root',
:logoutput => 'on_failure',
})
@ -207,12 +230,12 @@ describe 'apt::ppa' do
'package_manage' => true,
}
end
let(:title) { 'ppa:foo' }
let(:title) { 'ppa:user/foo' }
it { is_expected.to contain_package('software-properties-common') }
it { is_expected.to contain_exec('add-apt-repository-ppa:foo').that_notifies('Class[Apt::Update]').with({
it { is_expected.to contain_exec('add-apt-repository-ppa:user/foo').that_notifies('Class[Apt::Update]').with({
:environment => ['http_proxy=http://localhost:8080'],
:command => '/usr/bin/add-apt-repository ppa:foo',
:unless => '/usr/bin/test -s /etc/apt/sources.list.d/foo-trusty.list',
:command => '/usr/bin/add-apt-repository ppa:user/foo',
:unless => '/usr/bin/test -s /etc/apt/sources.list.d/user-foo-trusty.list',
:user => 'root',
:logoutput => 'on_failure',
})
@ -241,12 +264,12 @@ describe 'apt::ppa' do
:package_manage => true,
}
end
let(:title) { 'ppa:foo' }
let(:title) { 'ppa:user/foo' }
it { is_expected.to contain_package('software-properties-common') }
it { is_expected.to contain_exec('add-apt-repository-ppa:foo').that_notifies('Class[Apt::Update]').with({
it { is_expected.to contain_exec('add-apt-repository-ppa:user/foo').that_notifies('Class[Apt::Update]').with({
:environment => ['http_proxy=http://localhost:8180'],
:command => '/usr/bin/add-apt-repository ppa:foo',
:unless => '/usr/bin/test -s /etc/apt/sources.list.d/foo-trusty.list',
:command => '/usr/bin/add-apt-repository ppa:user/foo',
:unless => '/usr/bin/test -s /etc/apt/sources.list.d/user-foo-trusty.list',
:user => 'root',
:logoutput => 'on_failure',
})
@ -275,12 +298,12 @@ describe 'apt::ppa' do
:package_manage => true,
}
end
let(:title) { 'ppa:foo' }
let(:title) { 'ppa:user/foo' }
it { is_expected.to contain_package('software-properties-common') }
it { is_expected.to contain_exec('add-apt-repository-ppa:foo').that_notifies('Class[Apt::Update]').with({
it { is_expected.to contain_exec('add-apt-repository-ppa:user/foo').that_notifies('Class[Apt::Update]').with({
:environment => ['http_proxy=http://localhost:8180', 'https_proxy=https://localhost:8180'],
:command => '/usr/bin/add-apt-repository ppa:foo',
:unless => '/usr/bin/test -s /etc/apt/sources.list.d/foo-trusty.list',
:command => '/usr/bin/add-apt-repository ppa:user/foo',
:unless => '/usr/bin/test -s /etc/apt/sources.list.d/user-foo-trusty.list',
:user => 'root',
:logoutput => 'on_failure',
})
@ -301,13 +324,13 @@ describe 'apt::ppa' do
:puppetversion => Puppet.version,
}
end
let(:title) { 'ppa:foo' }
let(:title) { 'ppa:user/foo' }
let :params do
{
:ensure => 'absent'
}
end
it { is_expected.to contain_file('/etc/apt/sources.list.d/foo-trusty.list').that_notifies('Class[Apt::Update]').with({
it { is_expected.to contain_file('/etc/apt/sources.list.d/user-foo-trusty.list').that_notifies('Class[Apt::Update]').with({
:ensure => 'absent',
})
}
@ -325,7 +348,7 @@ describe 'apt::ppa' do
:puppetversion => Puppet.version,
}
end
let(:title) { 'ppa:foo' }
let(:title) { 'ppa:user/foo' }
it do
expect {
subject.call
@ -344,7 +367,7 @@ describe 'apt::ppa' do
:puppetversion => Puppet.version,
}
end
let(:title) { 'ppa:foo' }
let(:title) { 'ppa:user/foo' }
it do
expect {
subject.call