Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for SUSE Linux distributions #682

Merged
merged 1 commit into from
Feb 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .fixtures.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ fixtures:
forge_modules:
yumrepo_core: "puppetlabs/yumrepo_core"
powershell: "puppetlabs/powershell"
zypprepo: "puppet/zypprepo"
symlinks:
custom_datadog: "#{source_dir}/spec/custom_fixtures/custom_datadog"
datadog_agent: "#{source_dir}"
1 change: 1 addition & 0 deletions environments/etc/Puppetfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ mod 'puppetlabs-ruby', '1.0.0'
mod 'puppetlabs-stdlib', '4.24.0'
mod 'puppetlabs-powershell', '2.3.0'
mod 'puppetlabs-yumrepo_core', '1.0.3'
mod 'puppet-zypprepo', '3.1.0'
22 changes: 22 additions & 0 deletions environments/opensuse15/Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env ruby

Vagrant.configure("2") do |config|
config.vm.box = "generic/opensuse15"
config.vm.provision "file", source: "../../environments/etc", destination: "$HOME/puppet"
config.vm.synced_folder "../../", "/puppet-datadog-agent"
config.vm.provision "shell", inline: <<-SHELL
#install puppet 6
zypper ar -G https://yum.puppet.com/puppet/sles/15/x86_64/ puppet-repo
zypper install -y puppet-agent
ln -s /opt/puppetlabs/puppet/bin/puppet /usr/bin/puppet

# install modules
zypper install -y git
cd /home/vagrant/puppet
/opt/puppetlabs/puppet/bin/gem install r10k -v 2.6.7
/opt/puppetlabs/puppet/bin/r10k puppetfile install --moduledir=/home/vagrant/puppet/modules

# link local module
ln -s /puppet-datadog-agent /home/vagrant/puppet/modules/datadog_agent
SHELL
end
19 changes: 19 additions & 0 deletions kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,25 @@ platforms:

- gem install r10k -v 2.6.7
- cd /home/kitchen/puppet && r10k puppetfile install --moduledir=/tmp/modules

- name: opensuse/leap-15
driver_config:
# we use a custom image that runs systemd
image: 'datadog/docker-library:chef_kitchen_systemd_opensuse_leap_15'
run_command: /root/start.sh

driver:
provision_command:
- zypper ar -G https://yum.puppet.com/puppet/sles/15/x86_64/ puppet-repo
- zypper install -y puppet-agent ruby=2.5
- gem install bundler serverspec rspec
- ln -s /usr/bin/rspec.ruby2.5 /usr/bin/rspec
- ln -s /opt/puppetlabs/puppet/bin/puppet /usr/bin/puppet
- mkdir /home/kitchen/puppet
- printf <%= File.read('environments/etc/Puppetfile').inspect %> > /home/kitchen/puppet/Puppetfile

- /opt/puppetlabs/puppet/bin/gem install r10k -v 2.6.7
- cd /home/kitchen/puppet && /opt/puppetlabs/puppet/bin/r10k puppetfile install --moduledir=/tmp/modules

verifier:
name: serverspec
Expand Down
7 changes: 7 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,13 @@
return() #Config files will remain unchanged on uninstall
}
}
'OpenSuSE', 'SLES' : {
class { 'datadog_agent::suse' :
agent_major_version => $_agent_major_version,
agent_repo_uri => $agent_repo_uri,
agent_version => $agent_version,
}
}
default: { fail("Class[datadog_agent]: Unsupported operatingsystem: ${::operatingsystem}") }
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
$permissions_protected_file = '0600'
$agent_binary = '/opt/datadog-agent/bin/agent/agent'
}
'RedHat','CentOS','Fedora','Amazon','Scientific','OracleLinux' : {
'RedHat','CentOS','Fedora','Amazon','Scientific','OracleLinux', 'OpenSuSE', 'SLES' : {
$rubydev_package = 'ruby-devel'
$legacy_conf_dir = '/etc/dd-agent/conf.d'
$conf_dir = '/etc/datadog-agent/conf.d'
Expand Down
69 changes: 69 additions & 0 deletions manifests/suse.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Class: datadog_agent::suse
#
# This class contains the DataDog agent installation mechanism for SUSE distributions
#

class datadog_agent::suse(
Integer $agent_major_version = $datadog_agent::params::default_agent_major_version,
String $agent_version = $datadog_agent::params::agent_version,
String $release = $datadog_agent::params::apt_default_release,
Optional[String] $agent_repo_uri = undef,
) inherits datadog_agent::params {

$all_keys = [
'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',
]

case $agent_major_version {
5 : { fail('Agent v5 package not available in SUSE') }
6 : { $gpgkeys = $all_keys }
7 : { $gpgkeys = $all_keys[1,2] }
default: { fail('invalid agent_major_version') }
}

if ($agent_repo_uri != undef) {
$baseurl = $agent_repo_uri
} else {
$baseurl = "https://yum.datadoghq.com/suse/${release}/${agent_major_version}/${::architecture}"
}

package { 'datadog-agent-base':
ensure => absent,
before => Package[$datadog_agent::params::package_name],
}

# We need to install GPG keys manually since zypper will autoreject new keys
# We download each key and import it using rpm --import
$gpgkeys.each |String $key_url| {
$key_name = split($key_url, '/')
$key_path = "/tmp/${key_name[-1]}"

file { $key_path:
owner => root,
group => root,
mode => '0600',
source => $key_url,
}

exec { "install-${key_name}":
command => "/bin/rpm --import ${key_path}",
}
}

zypprepo { 'datadog':
baseurl => $baseurl,
enabled => 1,
autorefresh => 1,
name => 'datadog',
gpgcheck => 1,
gpgkey => join($gpgkeys, " "),
keeppackages => 1,
}

package { $datadog_agent::params::package_name:
ensure => $agent_version,
}

}
21 changes: 21 additions & 0 deletions metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
{
"name": "puppetlabs/powershell",
"version_requirement": ">=2.3.0 <5.0.0"
},
{
"name": "puppet/zypprepo",
"version_requirement": ">=3.1.0 <4.0.0"
}
],
"operatingsystem_support": [
Expand Down Expand Up @@ -114,6 +118,23 @@
"8",
"10"
]
},
{
"operatingsystem": "SLES",
"operatingsystemrelease": [
"11",
"12",
"15"
]
},
{
"operatingsystem": "OpenSUSE",
"operatingsystemrelease": [
"11",
"12",
"13",
"15"
]
}
],
"requirements": [
Expand Down
52 changes: 52 additions & 0 deletions spec/classes/datadog_agent_suse_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
require 'spec_helper'

describe 'datadog_agent::suse' do
if RSpec::Support::OS.windows?
return
end

let(:facts) do
{
operatingsystem: 'OpenSuSE',
architecture: 'x86_64',
}
end

context 'agent 6' do
let(:params) do
{
agent_major_version: 6,
}
end

it do
is_expected.to contain_zypprepo('datadog')
.with_enabled(1)\
.with_gpgcheck(1)\
.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')\
.with_baseurl('https://yum.datadoghq.com/suse/stable/6/x86_64')
end
end

context 'agent 7' do
let(:params) do
{
agent_major_version: 7,
}
end

it do
is_expected.to contain_zypprepo('datadog')
.with_enabled(1)\
.with_gpgcheck(1)\
.with_gpgkey('https://yum.datadoghq.com/DATADOG_RPM_KEY_E09422B3.public https://yum.datadoghq.com/DATADOG_RPM_KEY_20200908.public')\
.with_baseurl('https://yum.datadoghq.com/suse/stable/7/x86_64')
end
end

# it should install the packages
it do
is_expected.to contain_package('datadog-agent')\
.with_ensure('latest')
end
end