From 3e612ca41be9e7af6da0ba8c613ac27cd2deaddc Mon Sep 17 00:00:00 2001 From: Wenzheng Jiang Date: Fri, 27 Jul 2018 10:56:37 +1000 Subject: [PATCH 1/3] Check existence of gpg key in ppa unless --- manifests/params.pp | 1 + manifests/ppa.pp | 6 +++++- spec/defines/ppa_spec.rb | 16 ++++++++-------- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/manifests/params.pp b/manifests/params.pp index b0ad60c71a..479ac12235 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -9,6 +9,7 @@ $provider = '/usr/bin/apt-get' $sources_list = "${root}/sources.list" $sources_list_d = "${root}/sources.list.d" + $trusted_gpg_d = "${root}/trusted.gpg.d" $conf_d = "${root}/apt.conf.d" $preferences = "${root}/preferences" $preferences_d = "${root}/preferences.d" diff --git a/manifests/ppa.pp b/manifests/ppa.pp index a67e1a1945..a6ef8036d8 100644 --- a/manifests/ppa.pp +++ b/manifests/ppa.pp @@ -25,6 +25,10 @@ $filename_no_specialchars = regsubst($filename_no_slashes, '[\.\+]', '_', 'G') $sources_list_d_filename = "${filename_no_specialchars}.list" + $name_no_slashes = regsubst($name, '/', '-', 'G') + $name_no_specialchars = regsubst($name_no_slashes, '[\.\+]', '_', 'G') + $trusted_gpg_d_filename = regsubst($name_no_specialchars, '^ppa:(.+)', "\\1.gpg") + if $ensure == 'present' { if $package_manage { ensure_packages($package_name) @@ -47,7 +51,7 @@ exec { "add-apt-repository-${name}": environment => $_proxy_env, command => "/usr/bin/add-apt-repository ${options} ${name}", - unless => "/usr/bin/test -f ${::apt::sources_list_d}/${sources_list_d_filename}", + unless => "/usr/bin/test -f ${::apt::sources_list_d}/${sources_list_d_filename} && /usr/bin/test -f ${::apt::trusted_gpg_d}/${trusted_gpg_d_filename}", user => 'root', logoutput => 'on_failure', notify => Class['apt::update'], diff --git a/spec/defines/ppa_spec.rb b/spec/defines/ppa_spec.rb index 497822109d..278e7fa4e4 100644 --- a/spec/defines/ppa_spec.rb +++ b/spec/defines/ppa_spec.rb @@ -23,7 +23,7 @@ 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 - unless: '/usr/bin/test -f /etc/apt/sources.list.d/needs-such_substitution-wow_type-trusty.list', # rubocop:disable Metrics/LineLength + unless: '/usr/bin/test -f /etc/apt/sources.list.d/needs-such_substitution-wow_type-trusty.list && /usr/bin/test -f /etc/apt/trusted.gpg.d/needs-such_substitution-wow_type.gpg', # rubocop:disable Metrics/LineLength user: 'root', logoutput: 'on_failure') } @@ -47,7 +47,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', - unless: '/usr/bin/test -f /etc/apt/sources.list.d/user-ubuntu-foo-wily.list', + unless: '/usr/bin/test -f /etc/apt/sources.list.d/user-ubuntu-foo-wily.list && /usr/bin/test -f /etc/apt/trusted.gpg.d/user-foo.gpg', # rubocop:disable Metrics/LineLength user: 'root', logoutput: 'on_failure') } @@ -81,7 +81,7 @@ 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 - 'unless' => '/usr/bin/test -f /etc/apt/sources.list.d/needs-such_substitution-wow-trusty.list', # rubocop:disable Metrics/LineLength + 'unless' => '/usr/bin/test -f /etc/apt/sources.list.d/needs-such_substitution-wow-trusty.list && /usr/bin/test -f /etc/apt/trusted.gpg.d/needs-such_substitution-wow.gpg', # rubocop:disable Metrics/LineLength 'user' => 'root', 'logoutput' => 'on_failure') } @@ -118,7 +118,7 @@ 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 - 'unless' => '/usr/bin/test -f /etc/apt/sources.list.d/needs-such_substitution-wow-trusty.list', # rubocop:disable Metrics/LineLength + 'unless' => '/usr/bin/test -f /etc/apt/sources.list.d/needs-such_substitution-wow-trusty.list && /usr/bin/test -f /etc/apt/trusted.gpg.d/needs-such_substitution-wow.gpg', # rubocop:disable Metrics/LineLength 'user' => 'root', 'logoutput' => 'on_failure') } @@ -159,7 +159,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 ppa:user/foo', - unless: '/usr/bin/test -f /etc/apt/sources.list.d/user-foo-trusty.list', + unless: '/usr/bin/test -f /etc/apt/sources.list.d/user-foo-trusty.list && /usr/bin/test -f /etc/apt/trusted.gpg.d/user-foo.gpg', user: 'root', logoutput: 'on_failure') } @@ -194,7 +194,7 @@ 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', - unless: '/usr/bin/test -f /etc/apt/sources.list.d/user-foo-trusty.list', + unless: '/usr/bin/test -f /etc/apt/sources.list.d/user-foo-trusty.list && /usr/bin/test -f /etc/apt/trusted.gpg.d/user-foo.gpg', user: 'root', logoutput: 'on_failure') } @@ -229,7 +229,7 @@ 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', - unless: '/usr/bin/test -f /etc/apt/sources.list.d/user-foo-trusty.list', + unless: '/usr/bin/test -f /etc/apt/sources.list.d/user-foo-trusty.list && /usr/bin/test -f /etc/apt/trusted.gpg.d/user-foo.gpg', user: 'root', logoutput: 'on_failure') } @@ -264,7 +264,7 @@ 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', - unless: '/usr/bin/test -f /etc/apt/sources.list.d/user-foo-trusty.list', + unless: '/usr/bin/test -f /etc/apt/sources.list.d/user-foo-trusty.list && /usr/bin/test -f /etc/apt/trusted.gpg.d/user-foo.gpg', user: 'root', logoutput: 'on_failure') } From 34f6ef68062fb7fb9da715c4c314d5d5363a6565 Mon Sep 17 00:00:00 2001 From: Wenzheng Jiang Date: Fri, 27 Jul 2018 11:35:35 +1000 Subject: [PATCH 2/3] Fix linting --- spec/defines/ppa_spec.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/defines/ppa_spec.rb b/spec/defines/ppa_spec.rb index 278e7fa4e4..efbf482e8d 100644 --- a/spec/defines/ppa_spec.rb +++ b/spec/defines/ppa_spec.rb @@ -159,7 +159,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 ppa:user/foo', - unless: '/usr/bin/test -f /etc/apt/sources.list.d/user-foo-trusty.list && /usr/bin/test -f /etc/apt/trusted.gpg.d/user-foo.gpg', + unless: '/usr/bin/test -f /etc/apt/sources.list.d/user-foo-trusty.list && /usr/bin/test -f /etc/apt/trusted.gpg.d/user-foo.gpg', # rubocop:disable Metrics/LineLength user: 'root', logoutput: 'on_failure') } @@ -194,7 +194,7 @@ 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', - unless: '/usr/bin/test -f /etc/apt/sources.list.d/user-foo-trusty.list && /usr/bin/test -f /etc/apt/trusted.gpg.d/user-foo.gpg', + unless: '/usr/bin/test -f /etc/apt/sources.list.d/user-foo-trusty.list && /usr/bin/test -f /etc/apt/trusted.gpg.d/user-foo.gpg', # rubocop:disable Metrics/LineLength user: 'root', logoutput: 'on_failure') } @@ -229,7 +229,7 @@ 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', - unless: '/usr/bin/test -f /etc/apt/sources.list.d/user-foo-trusty.list && /usr/bin/test -f /etc/apt/trusted.gpg.d/user-foo.gpg', + unless: '/usr/bin/test -f /etc/apt/sources.list.d/user-foo-trusty.list && /usr/bin/test -f /etc/apt/trusted.gpg.d/user-foo.gpg', # rubocop:disable Metrics/LineLength user: 'root', logoutput: 'on_failure') } @@ -264,7 +264,7 @@ 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', - unless: '/usr/bin/test -f /etc/apt/sources.list.d/user-foo-trusty.list && /usr/bin/test -f /etc/apt/trusted.gpg.d/user-foo.gpg', + unless: '/usr/bin/test -f /etc/apt/sources.list.d/user-foo-trusty.list && /usr/bin/test -f /etc/apt/trusted.gpg.d/user-foo.gpg', # rubocop:disable Metrics/LineLength user: 'root', logoutput: 'on_failure') } From 75f5da7040eb67b144c490ff6bb319550df4f9fe Mon Sep 17 00:00:00 2001 From: Wenzheng Jiang Date: Mon, 30 Jul 2018 12:08:37 +1000 Subject: [PATCH 3/3] Fix compatibiilty issue --- manifests/ppa.pp | 23 +++++++++++++++-------- spec/defines/ppa_spec.rb | 2 +- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/manifests/ppa.pp b/manifests/ppa.pp index a6ef8036d8..740d59643c 100644 --- a/manifests/ppa.pp +++ b/manifests/ppa.pp @@ -16,18 +16,25 @@ if versioncmp($facts['lsbdistrelease'], '15.10') >= 0 { $distid = downcase($facts['lsbdistid']) - $filename = regsubst($name, '^ppa:([^/]+)/(.+)$', "\\1-${distid}-\\2-${release}") + $dash_filename = regsubst($name, '^ppa:([^/]+)/(.+)$', "\\1-${distid}-\\2") + $underscore_filename = regsubst($name, '^ppa:([^/]+)/(.+)$', "\\1_${distid}_\\2") } else { - $filename = regsubst($name, '^ppa:([^/]+)/(.+)$', "\\1-\\2-${release}") + $dash_filename = regsubst($name, '^ppa:([^/]+)/(.+)$', "\\1-\\2") + $underscore_filename = regsubst($name, '^ppa:([^/]+)/(.+)$', "\\1_\\2") } - $filename_no_slashes = regsubst($filename, '/', '-', 'G') - $filename_no_specialchars = regsubst($filename_no_slashes, '[\.\+]', '_', 'G') - $sources_list_d_filename = "${filename_no_specialchars}.list" + $dash_filename_no_slashes = regsubst($dash_filename, '/', '-', 'G') + $dash_filename_no_specialchars = regsubst($dash_filename_no_slashes, '[\.\+]', '_', 'G') + $underscore_filename_no_slashes = regsubst($underscore_filename, '/', '-', 'G') + $underscore_filename_no_specialchars = regsubst($underscore_filename_no_slashes, '[\.\+]', '_', 'G') - $name_no_slashes = regsubst($name, '/', '-', 'G') - $name_no_specialchars = regsubst($name_no_slashes, '[\.\+]', '_', 'G') - $trusted_gpg_d_filename = regsubst($name_no_specialchars, '^ppa:(.+)', "\\1.gpg") + $sources_list_d_filename = "${dash_filename_no_specialchars}-${release}.list" + + if versioncmp($facts['lsbdistrelease'], '15.10') >= 0 { + $trusted_gpg_d_filename = "${underscore_filename_no_specialchars}.gpg" + } else { + $trusted_gpg_d_filename = "${dash_filename_no_specialchars}.gpg" + } if $ensure == 'present' { if $package_manage { diff --git a/spec/defines/ppa_spec.rb b/spec/defines/ppa_spec.rb index efbf482e8d..4c4dddb171 100644 --- a/spec/defines/ppa_spec.rb +++ b/spec/defines/ppa_spec.rb @@ -47,7 +47,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', - unless: '/usr/bin/test -f /etc/apt/sources.list.d/user-ubuntu-foo-wily.list && /usr/bin/test -f /etc/apt/trusted.gpg.d/user-foo.gpg', # rubocop:disable Metrics/LineLength + unless: '/usr/bin/test -f /etc/apt/sources.list.d/user-ubuntu-foo-wily.list && /usr/bin/test -f /etc/apt/trusted.gpg.d/user_ubuntu_foo.gpg', # rubocop:disable Metrics/LineLength user: 'root', logoutput: 'on_failure') }