Make sure PPA source file is absent when apt-add-repository fails
authorWenzheng Jiang <wjiang@freelancer.com>
Tue, 3 Jul 2018 04:37:15 +0000 (14:37 +1000)
committerWenzheng Jiang <wjiang@freelancer.com>
Tue, 3 Jul 2018 04:37:15 +0000 (14:37 +1000)
manifests/ppa.pp
spec/defines/ppa_spec.rb

index a67e1a19457e204ce7e5cfb1237115b0081bbc0d..b766d59d3b07bc18317eb82b547b1b9e90cac36f 100644 (file)
@@ -46,7 +46,7 @@ define apt::ppa(
 
     exec { "add-apt-repository-${name}":
       environment => $_proxy_env,
-      command     => "/usr/bin/add-apt-repository ${options} ${name}",
+      command     => "/usr/bin/add-apt-repository ${options} ${name} || rm ${::apt::sources_list_d}/${sources_list_d_filename} && false",
       unless      => "/usr/bin/test -f ${::apt::sources_list_d}/${sources_list_d_filename}",
       user        => 'root',
       logoutput   => 'on_failure',
index 497822109d4115aaf0655a3cc09cbc1571a1122a..a68dc621502e93108699703e7db34f1e2be8125c 100644 (file)
@@ -22,7 +22,7 @@ describe 'apt::ppa' do
     it { is_expected.not_to contain_package('python-software-properties') }
     it {
       is_expected.to contain_exec('add-apt-repository-ppa:needs/such.substitution/wow+type').that_notifies('Class[Apt::Update]').with(environment: [],
-                                                                                                                                      command: '/usr/bin/add-apt-repository -y ppa:needs/such.substitution/wow+type', # rubocop:disable Metrics/LineLength
+                                                                                                                                      command: '/usr/bin/add-apt-repository -y ppa:needs/such.substitution/wow+type || rm /etc/apt/sources.list.d/needs-such_substitution-wow_type-trusty.list && false', # rubocop:disable Metrics/LineLength
                                                                                                                                       unless: '/usr/bin/test -f /etc/apt/sources.list.d/needs-such_substitution-wow_type-trusty.list', # rubocop:disable Metrics/LineLength
                                                                                                                                       user: 'root',
                                                                                                                                       logoutput: 'on_failure')
@@ -46,7 +46,7 @@ describe 'apt::ppa' do
 
     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',
+                                                                                                              command: '/usr/bin/add-apt-repository -y ppa:user/foo || rm /etc/apt/sources.list.d/user-ubuntu-foo-wily.list && false',
                                                                                                               unless: '/usr/bin/test -f /etc/apt/sources.list.d/user-ubuntu-foo-wily.list',
                                                                                                               user: 'root',
                                                                                                               logoutput: 'on_failure')
@@ -80,7 +80,7 @@ describe 'apt::ppa' do
     it { is_expected.to contain_package('software-properties-common') }
     it {
       is_expected.to contain_exec('add-apt-repository-ppa:needs/such.substitution/wow').that_notifies('Class[Apt::Update]').with('environment' => [],
-                                                                                                                                 'command'     => '/usr/bin/add-apt-repository -y ppa:needs/such.substitution/wow', # rubocop:disable Metrics/LineLength
+                                                                                                                                 'command'     => '/usr/bin/add-apt-repository -y ppa:needs/such.substitution/wow || rm /etc/apt/sources.list.d/needs-such_substitution-wow-trusty.list && false', # rubocop:disable Metrics/LineLength
                                                                                                                                  'unless'      => '/usr/bin/test -f /etc/apt/sources.list.d/needs-such_substitution-wow-trusty.list', # rubocop:disable Metrics/LineLength
                                                                                                                                  'user'        => 'root',
                                                                                                                                  'logoutput'   => 'on_failure')
@@ -117,7 +117,7 @@ describe 'apt::ppa' do
     it { is_expected.not_to contain_package('python-software-properties') }
     it {
       is_expected.to contain_exec('add-apt-repository-ppa:needs/such.substitution/wow').that_notifies('Class[Apt::Update]').with('environment' => [],
-                                                                                                                                 'command'     => '/usr/bin/add-apt-repository -y ppa:needs/such.substitution/wow', # rubocop:disable Metrics/LineLength
+                                                                                                                                 'command'     => '/usr/bin/add-apt-repository -y ppa:needs/such.substitution/wow || rm /etc/apt/sources.list.d/needs-such_substitution-wow-trusty.list && false', # rubocop:disable Metrics/LineLength
                                                                                                                                  'unless'      => '/usr/bin/test -f /etc/apt/sources.list.d/needs-such_substitution-wow-trusty.list', # rubocop:disable Metrics/LineLength
                                                                                                                                  'user'        => 'root',
                                                                                                                                  'logoutput'   => 'on_failure')
@@ -158,7 +158,7 @@ describe 'apt::ppa' do
     it { is_expected.to contain_package('software-properties-common') }
     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:user/foo',
+                                                                                                              command: '/usr/bin/add-apt-repository  ppa:user/foo || rm /etc/apt/sources.list.d/user-foo-trusty.list && false',
                                                                                                               unless: '/usr/bin/test -f /etc/apt/sources.list.d/user-foo-trusty.list',
                                                                                                               user: 'root',
                                                                                                               logoutput: 'on_failure')
@@ -193,7 +193,7 @@ describe 'apt::ppa' do
     it { is_expected.to contain_package('software-properties-common') }
     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:user/foo',
+                                                                                                              command: '/usr/bin/add-apt-repository  ppa:user/foo || rm /etc/apt/sources.list.d/user-foo-trusty.list && false',
                                                                                                               unless: '/usr/bin/test -f /etc/apt/sources.list.d/user-foo-trusty.list',
                                                                                                               user: 'root',
                                                                                                               logoutput: 'on_failure')
@@ -228,7 +228,7 @@ describe 'apt::ppa' do
     it { is_expected.to contain_package('software-properties-common') }
     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:user/foo',
+                                                                                                              command: '/usr/bin/add-apt-repository  ppa:user/foo || rm /etc/apt/sources.list.d/user-foo-trusty.list && false',
                                                                                                               unless: '/usr/bin/test -f /etc/apt/sources.list.d/user-foo-trusty.list',
                                                                                                               user: 'root',
                                                                                                               logoutput: 'on_failure')
@@ -263,7 +263,7 @@ describe 'apt::ppa' do
     it { is_expected.to contain_package('software-properties-common') }
     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:user/foo',
+                                                                                                              command: '/usr/bin/add-apt-repository  ppa:user/foo || rm /etc/apt/sources.list.d/user-foo-trusty.list && false',
                                                                                                               unless: '/usr/bin/test -f /etc/apt/sources.list.d/user-foo-trusty.list',
                                                                                                               user: 'root',
                                                                                                               logoutput: 'on_failure')