Skip to content

Commit

Permalink
Avoid potential dependency cycles when used with other modules (#463)
Browse files Browse the repository at this point in the history
* Use native pgp key support of the apt module

* apt::source notify apt_update by default

* require Class['apt::update'] as the documentation suggests: https://github.com/puppetlabs/puppetlabs-apt\#adding-new-sources-or-ppas

* Use 'exec' instead of 'ensure_packages' to break a dependencies cycle with some other modules

* Fix spec tests

* Set $key to empty dict if skipping apt key trusting
  • Loading branch information
remicalixte authored and truthbk committed Dec 27, 2018
1 parent 92d0912 commit 8a29860
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 41 deletions.
19 changes: 12 additions & 7 deletions manifests/ubuntu/agent5.pp
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,17 @@
Optional[String] $apt_keyserver = undef,
) inherits datadog_agent::params{

ensure_packages(['apt-transport-https'])
exec { 'apt-transport-https':
command => '/usr/bin/apt-get install -y -q apt-transport-https'
}

if !$skip_apt_key_trusting {
::datadog_agent::ubuntu::install_key { [$apt_key]:
server => $apt_keyserver,
before => Apt::Source['datadog'],
$key = {
'id' => $apt_key,
'server' => $apt_keyserver
}
} else {
$key = {}
}

# This is a hack - I'm not happy about it, but we should rarely
Expand Down Expand Up @@ -67,8 +71,9 @@
location => $location,
release => $release,
repos => $repos,
require => Package['apt-transport-https'],
notify => [Exec['datadog_apt-get_remove_agent6'],Exec['apt_update']],
key => $key,
require => Exec['apt-transport-https'],
notify => Exec['datadog_apt-get_remove_agent6'],
}

package { 'datadog-agent-base':
Expand All @@ -79,7 +84,7 @@
package { $datadog_agent::params::package_name:
ensure => $agent_version,
require => [Apt::Source['datadog'],
Exec['apt_update']],
Class['apt::update']],
}

if $service_provider {
Expand Down
19 changes: 12 additions & 7 deletions manifests/ubuntu/agent6.pp
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@
Optional[String] $apt_keyserver = undef,
) inherits datadog_agent::params {

ensure_packages(['apt-transport-https'])
exec { 'apt-transport-https':
command => '/usr/bin/apt-get install -y -q apt-transport-https'
}

if !$skip_apt_key_trusting {
::datadog_agent::ubuntu::install_key { [$apt_key]:
server => $apt_keyserver,
before => Apt::Source['datadog6'],
$key = {
'id' => $apt_key,
'server' => $apt_keyserver
}
} else {
$key = {}
}

apt::source { 'datadog':
Expand All @@ -33,8 +38,8 @@
location => $location,
release => $release,
repos => $repos,
require => Package['apt-transport-https'],
notify => Exec['apt_update'],
key => $key,
require => Exec['apt-transport-https'],
}

package { 'datadog-agent-base':
Expand All @@ -45,7 +50,7 @@
package { $datadog_agent::params::package_name:
ensure => $agent_version,
require => [Apt::Source['datadog6'],
Exec['apt_update']],
Class['apt::update']],
}

if $service_provider {
Expand Down
20 changes: 0 additions & 20 deletions manifests/ubuntu/install_key.pp

This file was deleted.

13 changes: 6 additions & 7 deletions spec/classes/datadog_agent_ubuntu_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@
end

# it should install the mirror
it { should_not contain_datadog_agent__ubuntu__install_key('935F5A436A5A6E8788F0765B226AE980C7A7DA52') }
it { should_not contain_apt__key('Add key: 935F5A436A5A6E8788F0765B226AE980C7A7DA52 from Apt::Source datadog') }
it do
should contain_datadog_agent__ubuntu__install_key('A2923DFF56EDA6E76E55E492D3A80E30382E94DE')\
should contain_apt__key('Add key: A2923DFF56EDA6E76E55E492D3A80E30382E94DE from Apt::Source datadog')
end
context 'overriding keyserver' do
let(:params) {{
apt_keyserver: 'hkp://pool.sks-keyservers.net:80',
}}
it do
should contain_datadog_agent__ubuntu__install_key('A2923DFF56EDA6E76E55E492D3A80E30382E94DE')\
should contain_apt__key('Add key: A2923DFF56EDA6E76E55E492D3A80E30382E94DE from Apt::Source datadog')\
.with_server('hkp://pool.sks-keyservers.net:80')
end
end
Expand All @@ -38,7 +38,7 @@

# it should install the packages
it do
should contain_package('apt-transport-https')\
should contain_exec('apt-transport-https')\
.that_comes_before('file[/etc/apt/sources.list.d/datadog.list]')
end
it do
Expand Down Expand Up @@ -91,8 +91,7 @@
end

# it should install the mirror
it { should_not contain_datadog_agent__ubuntu__install_key('935F5A436A5A6E8788F0765B226AE980C7A7DA52') }
it { should contain_datadog_agent__ubuntu__install_key('A2923DFF56EDA6E76E55E492D3A80E30382E94DE') }
it { should contain_apt__key('Add key: A2923DFF56EDA6E76E55E492D3A80E30382E94DE from Apt::Source datadog6') }

it do
should contain_file('/etc/apt/sources.list.d/datadog6.list')\
Expand All @@ -102,7 +101,7 @@

# it should install the packages
it do
should contain_package('apt-transport-https')\
should contain_exec('apt-transport-https')\
.that_comes_before('file[/etc/apt/sources.list.d/datadog6.list]')
end
it do
Expand Down

0 comments on commit 8a29860

Please sign in to comment.