From 432ef346db9b1b59735e3ac91cd098f273a56e4f Mon Sep 17 00:00:00 2001 From: Wenzheng Jiang Date: Tue, 3 Jul 2018 14:37:15 +1000 Subject: [PATCH 1/3] Make sure PPA source file is absent when apt-add-repository fails --- manifests/ppa.pp | 2 +- spec/defines/ppa_spec.rb | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/manifests/ppa.pp b/manifests/ppa.pp index a67e1a1945..b766d59d3b 100644 --- a/manifests/ppa.pp +++ b/manifests/ppa.pp @@ -46,7 +46,7 @@ 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', diff --git a/spec/defines/ppa_spec.rb b/spec/defines/ppa_spec.rb index 497822109d..a68dc62150 100644 --- a/spec/defines/ppa_spec.rb +++ b/spec/defines/ppa_spec.rb @@ -22,7 +22,7 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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') From 7c489e05ff0e4b1a948ce18c994067f42f91d2fb Mon Sep 17 00:00:00 2001 From: Wenzheng Jiang Date: Wed, 4 Jul 2018 10:57:10 +1000 Subject: [PATCH 2/3] Fix lint error --- spec/defines/ppa_spec.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/spec/defines/ppa_spec.rb b/spec/defines/ppa_spec.rb index a68dc62150..f9ea8cefb5 100644 --- a/spec/defines/ppa_spec.rb +++ b/spec/defines/ppa_spec.rb @@ -46,7 +46,7 @@ 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 || rm /etc/apt/sources.list.d/user-ubuntu-foo-wily.list && false', + command: '/usr/bin/add-apt-repository -y ppa:user/foo || rm /etc/apt/sources.list.d/user-ubuntu-foo-wily.list && false', # rubocop:disable Metrics/LineLength unless: '/usr/bin/test -f /etc/apt/sources.list.d/user-ubuntu-foo-wily.list', user: 'root', logoutput: 'on_failure') @@ -158,7 +158,7 @@ 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 || rm /etc/apt/sources.list.d/user-foo-trusty.list && false', + command: '/usr/bin/add-apt-repository ppa:user/foo || rm /etc/apt/sources.list.d/user-foo-trusty.list && false', # rubocop:disable Metrics/LineLength unless: '/usr/bin/test -f /etc/apt/sources.list.d/user-foo-trusty.list', user: 'root', logoutput: 'on_failure') @@ -193,7 +193,7 @@ 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 || rm /etc/apt/sources.list.d/user-foo-trusty.list && false', + command: '/usr/bin/add-apt-repository ppa:user/foo || rm /etc/apt/sources.list.d/user-foo-trusty.list && false', # rubocop:disable Metrics/LineLength unless: '/usr/bin/test -f /etc/apt/sources.list.d/user-foo-trusty.list', user: 'root', logoutput: 'on_failure') @@ -228,7 +228,7 @@ 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 || rm /etc/apt/sources.list.d/user-foo-trusty.list && false', + command: '/usr/bin/add-apt-repository ppa:user/foo || rm /etc/apt/sources.list.d/user-foo-trusty.list && false', # rubocop:disable Metrics/LineLength unless: '/usr/bin/test -f /etc/apt/sources.list.d/user-foo-trusty.list', user: 'root', logoutput: 'on_failure') @@ -263,7 +263,7 @@ 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 || rm /etc/apt/sources.list.d/user-foo-trusty.list && false', + command: '/usr/bin/add-apt-repository ppa:user/foo || rm /etc/apt/sources.list.d/user-foo-trusty.list && false', # rubocop:disable Metrics/LineLength unless: '/usr/bin/test -f /etc/apt/sources.list.d/user-foo-trusty.list', user: 'root', logoutput: 'on_failure') From b3b1c068e33ecd4cd86253b272a599ddd5ffecd2 Mon Sep 17 00:00:00 2001 From: Wenzheng Jiang Date: Tue, 17 Jul 2018 14:56:52 +1000 Subject: [PATCH 3/3] Add brackets --- manifests/ppa.pp | 2 +- spec/defines/ppa_spec.rb | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/manifests/ppa.pp b/manifests/ppa.pp index b766d59d3b..4ee08ba3c4 100644 --- a/manifests/ppa.pp +++ b/manifests/ppa.pp @@ -46,7 +46,7 @@ exec { "add-apt-repository-${name}": environment => $_proxy_env, - command => "/usr/bin/add-apt-repository ${options} ${name} || rm ${::apt::sources_list_d}/${sources_list_d_filename} && false", + 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', diff --git a/spec/defines/ppa_spec.rb b/spec/defines/ppa_spec.rb index f9ea8cefb5..984c3e872c 100644 --- a/spec/defines/ppa_spec.rb +++ b/spec/defines/ppa_spec.rb @@ -22,7 +22,7 @@ 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 || rm /etc/apt/sources.list.d/needs-such_substitution-wow_type-trusty.list && false', # 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 @@ 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 || rm /etc/apt/sources.list.d/user-ubuntu-foo-wily.list && false', # rubocop:disable Metrics/LineLength + command: '/usr/bin/add-apt-repository -y ppa:user/foo || (rm /etc/apt/sources.list.d/user-ubuntu-foo-wily.list && false)', # rubocop:disable Metrics/LineLength unless: '/usr/bin/test -f /etc/apt/sources.list.d/user-ubuntu-foo-wily.list', user: 'root', logoutput: 'on_failure') @@ -80,7 +80,7 @@ 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 || rm /etc/apt/sources.list.d/needs-such_substitution-wow-trusty.list && false', # 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 @@ 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 || rm /etc/apt/sources.list.d/needs-such_substitution-wow-trusty.list && false', # 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 @@ 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 || rm /etc/apt/sources.list.d/user-foo-trusty.list && false', # rubocop:disable Metrics/LineLength + command: '/usr/bin/add-apt-repository ppa:user/foo || (rm /etc/apt/sources.list.d/user-foo-trusty.list && false)', # rubocop:disable Metrics/LineLength unless: '/usr/bin/test -f /etc/apt/sources.list.d/user-foo-trusty.list', user: 'root', logoutput: 'on_failure') @@ -193,7 +193,7 @@ 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 || rm /etc/apt/sources.list.d/user-foo-trusty.list && false', # rubocop:disable Metrics/LineLength + command: '/usr/bin/add-apt-repository ppa:user/foo || (rm /etc/apt/sources.list.d/user-foo-trusty.list && false)', # rubocop:disable Metrics/LineLength unless: '/usr/bin/test -f /etc/apt/sources.list.d/user-foo-trusty.list', user: 'root', logoutput: 'on_failure') @@ -228,7 +228,7 @@ 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 || rm /etc/apt/sources.list.d/user-foo-trusty.list && false', # rubocop:disable Metrics/LineLength + command: '/usr/bin/add-apt-repository ppa:user/foo || (rm /etc/apt/sources.list.d/user-foo-trusty.list && false)', # rubocop:disable Metrics/LineLength unless: '/usr/bin/test -f /etc/apt/sources.list.d/user-foo-trusty.list', user: 'root', logoutput: 'on_failure') @@ -263,7 +263,7 @@ 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 || rm /etc/apt/sources.list.d/user-foo-trusty.list && false', # rubocop:disable Metrics/LineLength + command: '/usr/bin/add-apt-repository ppa:user/foo || (rm /etc/apt/sources.list.d/user-foo-trusty.list && false)', # rubocop:disable Metrics/LineLength unless: '/usr/bin/test -f /etc/apt/sources.list.d/user-foo-trusty.list', user: 'root', logoutput: 'on_failure')