Skip to content

Commit 009c3c9

Browse files
authored
Add support for SUSE distros (#682)
Supported versions are the same as the zypprepo dependency This also adds Kitchen tests and a SUSE test environment
1 parent 7e0506f commit 009c3c9

9 files changed

Lines changed: 193 additions & 1 deletion

File tree

.fixtures.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ fixtures:
1616
forge_modules:
1717
yumrepo_core: "puppetlabs/yumrepo_core"
1818
powershell: "puppetlabs/powershell"
19+
zypprepo: "puppet/zypprepo"
1920
symlinks:
2021
custom_datadog: "#{source_dir}/spec/custom_fixtures/custom_datadog"
2122
datadog_agent: "#{source_dir}"

environments/etc/Puppetfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ mod 'puppetlabs-ruby', '1.0.0'
77
mod 'puppetlabs-stdlib', '4.24.0'
88
mod 'puppetlabs-powershell', '2.3.0'
99
mod 'puppetlabs-yumrepo_core', '1.0.3'
10+
mod 'puppet-zypprepo', '3.1.0'
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env ruby
2+
3+
Vagrant.configure("2") do |config|
4+
config.vm.box = "generic/opensuse15"
5+
config.vm.provision "file", source: "../../environments/etc", destination: "$HOME/puppet"
6+
config.vm.synced_folder "../../", "/puppet-datadog-agent"
7+
config.vm.provision "shell", inline: <<-SHELL
8+
#install puppet 6
9+
zypper ar -G https://yum.puppet.com/puppet/sles/15/x86_64/ puppet-repo
10+
zypper install -y puppet-agent
11+
ln -s /opt/puppetlabs/puppet/bin/puppet /usr/bin/puppet
12+
13+
# install modules
14+
zypper install -y git
15+
cd /home/vagrant/puppet
16+
/opt/puppetlabs/puppet/bin/gem install r10k -v 2.6.7
17+
/opt/puppetlabs/puppet/bin/r10k puppetfile install --moduledir=/home/vagrant/puppet/modules
18+
19+
# link local module
20+
ln -s /puppet-datadog-agent /home/vagrant/puppet/modules/datadog_agent
21+
SHELL
22+
end

kitchen.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,25 @@ platforms:
6666

6767
- gem install r10k -v 2.6.7
6868
- cd /home/kitchen/puppet && r10k puppetfile install --moduledir=/tmp/modules
69+
70+
- name: opensuse/leap-15
71+
driver_config:
72+
# we use a custom image that runs systemd
73+
image: 'datadog/docker-library:chef_kitchen_systemd_opensuse_leap_15'
74+
run_command: /root/start.sh
75+
76+
driver:
77+
provision_command:
78+
- zypper ar -G https://yum.puppet.com/puppet/sles/15/x86_64/ puppet-repo
79+
- zypper install -y puppet-agent ruby=2.5
80+
- gem install bundler serverspec rspec
81+
- ln -s /usr/bin/rspec.ruby2.5 /usr/bin/rspec
82+
- ln -s /opt/puppetlabs/puppet/bin/puppet /usr/bin/puppet
83+
- mkdir /home/kitchen/puppet
84+
- printf <%= File.read('environments/etc/Puppetfile').inspect %> > /home/kitchen/puppet/Puppetfile
85+
86+
- /opt/puppetlabs/puppet/bin/gem install r10k -v 2.6.7
87+
- cd /home/kitchen/puppet && /opt/puppetlabs/puppet/bin/r10k puppetfile install --moduledir=/tmp/modules
6988

7089
verifier:
7190
name: serverspec

manifests/init.pp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,13 @@
451451
return() #Config files will remain unchanged on uninstall
452452
}
453453
}
454+
'OpenSuSE', 'SLES' : {
455+
class { 'datadog_agent::suse' :
456+
agent_major_version => $_agent_major_version,
457+
agent_repo_uri => $agent_repo_uri,
458+
agent_version => $agent_version,
459+
}
460+
}
454461
default: { fail("Class[datadog_agent]: Unsupported operatingsystem: ${::operatingsystem}") }
455462
}
456463
} else {

manifests/params.pp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
$permissions_protected_file = '0600'
4141
$agent_binary = '/opt/datadog-agent/bin/agent/agent'
4242
}
43-
'RedHat','CentOS','Fedora','Amazon','Scientific','OracleLinux' : {
43+
'RedHat','CentOS','Fedora','Amazon','Scientific','OracleLinux', 'OpenSuSE', 'SLES' : {
4444
$rubydev_package = 'ruby-devel'
4545
$legacy_conf_dir = '/etc/dd-agent/conf.d'
4646
$conf_dir = '/etc/datadog-agent/conf.d'

manifests/suse.pp

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Class: datadog_agent::suse
2+
#
3+
# This class contains the DataDog agent installation mechanism for SUSE distributions
4+
#
5+
6+
class datadog_agent::suse(
7+
Integer $agent_major_version = $datadog_agent::params::default_agent_major_version,
8+
String $agent_version = $datadog_agent::params::agent_version,
9+
String $release = $datadog_agent::params::apt_default_release,
10+
Optional[String] $agent_repo_uri = undef,
11+
) inherits datadog_agent::params {
12+
13+
$all_keys = [
14+
'https://yum.datadoghq.com/DATADOG_RPM_KEY.public',
15+
'https://yum.datadoghq.com/DATADOG_RPM_KEY_E09422B3.public',
16+
'https://yum.datadoghq.com/DATADOG_RPM_KEY_20200908.public',
17+
]
18+
19+
case $agent_major_version {
20+
5 : { fail('Agent v5 package not available in SUSE') }
21+
6 : { $gpgkeys = $all_keys }
22+
7 : { $gpgkeys = $all_keys[1,2] }
23+
default: { fail('invalid agent_major_version') }
24+
}
25+
26+
if ($agent_repo_uri != undef) {
27+
$baseurl = $agent_repo_uri
28+
} else {
29+
$baseurl = "https://yum.datadoghq.com/suse/${release}/${agent_major_version}/${::architecture}"
30+
}
31+
32+
package { 'datadog-agent-base':
33+
ensure => absent,
34+
before => Package[$datadog_agent::params::package_name],
35+
}
36+
37+
# We need to install GPG keys manually since zypper will autoreject new keys
38+
# We download each key and import it using rpm --import
39+
$gpgkeys.each |String $key_url| {
40+
$key_name = split($key_url, '/')
41+
$key_path = "/tmp/${key_name[-1]}"
42+
43+
file { $key_path:
44+
owner => root,
45+
group => root,
46+
mode => '0600',
47+
source => $key_url,
48+
}
49+
50+
exec { "install-${key_name}":
51+
command => "/bin/rpm --import ${key_path}",
52+
}
53+
}
54+
55+
zypprepo { 'datadog':
56+
baseurl => $baseurl,
57+
enabled => 1,
58+
autorefresh => 1,
59+
name => 'datadog',
60+
gpgcheck => 1,
61+
gpgkey => join($gpgkeys, " "),
62+
keeppackages => 1,
63+
}
64+
65+
package { $datadog_agent::params::package_name:
66+
ensure => $agent_version,
67+
}
68+
69+
}

metadata.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@
3535
{
3636
"name": "puppetlabs/powershell",
3737
"version_requirement": ">=2.3.0 <5.0.0"
38+
},
39+
{
40+
"name": "puppet/zypprepo",
41+
"version_requirement": ">=3.1.0 <4.0.0"
3842
}
3943
],
4044
"operatingsystem_support": [
@@ -114,6 +118,23 @@
114118
"8",
115119
"10"
116120
]
121+
},
122+
{
123+
"operatingsystem": "SLES",
124+
"operatingsystemrelease": [
125+
"11",
126+
"12",
127+
"15"
128+
]
129+
},
130+
{
131+
"operatingsystem": "OpenSUSE",
132+
"operatingsystemrelease": [
133+
"11",
134+
"12",
135+
"13",
136+
"15"
137+
]
117138
}
118139
],
119140
"requirements": [
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
require 'spec_helper'
2+
3+
describe 'datadog_agent::suse' do
4+
if RSpec::Support::OS.windows?
5+
return
6+
end
7+
8+
let(:facts) do
9+
{
10+
operatingsystem: 'OpenSuSE',
11+
architecture: 'x86_64',
12+
}
13+
end
14+
15+
context 'agent 6' do
16+
let(:params) do
17+
{
18+
agent_major_version: 6,
19+
}
20+
end
21+
22+
it do
23+
is_expected.to contain_zypprepo('datadog')
24+
.with_enabled(1)\
25+
.with_gpgcheck(1)\
26+
.with_gpgkey('https://yum.datadoghq.com/DATADOG_RPM_KEY.public https://yum.datadoghq.com/DATADOG_RPM_KEY_E09422B3.public https://yum.datadoghq.com/DATADOG_RPM_KEY_20200908.public')\
27+
.with_baseurl('https://yum.datadoghq.com/suse/stable/6/x86_64')
28+
end
29+
end
30+
31+
context 'agent 7' do
32+
let(:params) do
33+
{
34+
agent_major_version: 7,
35+
}
36+
end
37+
38+
it do
39+
is_expected.to contain_zypprepo('datadog')
40+
.with_enabled(1)\
41+
.with_gpgcheck(1)\
42+
.with_gpgkey('https://yum.datadoghq.com/DATADOG_RPM_KEY_E09422B3.public https://yum.datadoghq.com/DATADOG_RPM_KEY_20200908.public')\
43+
.with_baseurl('https://yum.datadoghq.com/suse/stable/7/x86_64')
44+
end
45+
end
46+
47+
# it should install the packages
48+
it do
49+
is_expected.to contain_package('datadog-agent')\
50+
.with_ensure('latest')
51+
end
52+
end

0 commit comments

Comments
 (0)