Skip to content

Commit

Permalink
Add support for Suse Linux (#624)
Browse files Browse the repository at this point in the history
* Version bump to 2.3.2

* Version bump to 2.3.3

* Updating module version

* Adding manifests/repo/zypper.pp

* Support of Suse zypper repos

* Fixing manifests/repo.pp

* Version bump to 4.0.0.2

* Version bump to 4.0.1-rc0

* Setting version to 4.0.0

* Adding SLES 12 and 15 as a supported operating system

* Setting supported version for Enterprise Linux to 3.0

* Adding dependency to puppet/zypprepo

* Updating spec test for Suse

* Fixing spec tests for Suse

* Style changes

* Fixing package in manifests/mongos/params.pp for Suse

* Fixing config in manifests/mongos/config.pp for Suse

* Making fork on package purge for Suse

* Fixing Repo base_url for zypper

* Fixing spec/classes/repo_spec.rb for Suse

* Changing two elsifs to one

* Simplifying logic in manifests/repo.pp

* Adding puppet strings documentation to manifests/repo/zypper.pp and declaring it for private.

* Update metadata.json

Update metadata.json -  lower version boundary

Co-authored-by: Tim Meusel <[email protected]>

* Make the linter happy

Co-authored-by: Tim Meusel <[email protected]>
  • Loading branch information
fbrehm and bastelfreak authored Oct 28, 2021
1 parent 61b00f2 commit 2e6001a
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 10 deletions.
1 change: 1 addition & 0 deletions .fixtures.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ fixtures:
"stdlib": "git://github.com/puppetlabs/puppetlabs-stdlib.git"
"apt": "git://github.com/puppetlabs/puppetlabs-apt.git"
"systemd": "https://github.com/voxpupuli/puppet-systemd.git"
"zypprepo": "https://github.com/voxpupuli/puppet-zypprepo.git"
yumrepo_core:
repo: https://github.com/puppetlabs/puppetlabs-yumrepo_core.git
puppet_version: ">= 6.0.0"
2 changes: 1 addition & 1 deletion manifests/mongos/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
}

if $service_manage {
if $facts['os']['family'] == 'RedHat' {
if $facts['os']['family'] == 'RedHat' or $facts['os']['family'] == 'Suse' {
file { '/etc/sysconfig/mongos' :
ensure => $ensure,
owner => 'root',
Expand Down
8 changes: 7 additions & 1 deletion manifests/mongos/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@
$package_ensure = $mongodb::mongos::package_ensure,
$package_name = $mongodb::mongos::package_name,
) {
if $facts['os']['family'] == 'Suse' and $package_ensure == 'purged' {
$_package_ensure = 'absent'
} else {
$_package_ensure = $package_ensure
}

unless defined(Package[$package_name]) {
package { 'mongodb_mongos':
ensure => $package_ensure,
ensure => $_package_ensure,
name => $package_name,
tag => 'mongodb_package',
}
Expand Down
2 changes: 1 addition & 1 deletion manifests/mongos/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
$package_ensure = pick($version, 'present')
if $manage_package {
$package_name = "mongodb-${mongodb::globals::edition}-mongos"
} elsif $facts['os']['family'] == 'RedHat' {
} elsif $facts['os']['family'] in ['RedHat', 'Suse'] {
$package_name = "mongodb-${mongodb::globals::edition}-mongos"
} else {
$package_name = 'mongodb-server'
Expand Down
17 changes: 16 additions & 1 deletion manifests/repo.pp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,21 @@
contain mongodb::repo::yum
}

'Suse': {
if $repo_location {
$location = $repo_location
$description = 'MongoDB Custom Repository'
} elsif $version == undef or versioncmp($version, '3.2.0') < 0 {
fail('Package repositories for versions older than 3.2 are unsupported')
} else {
$mongover = split($version, '[.]')
$location = "https://repo.mongodb.org/zypper/suse/\$releasever_major/mongodb-org/${mongover[0]}.${mongover[1]}/\$basearch/"
$description = 'MongoDB Repository'
}

contain mongodb::repo::zypper
}

'Debian': {
if $repo_location != undef {
$location = $repo_location
Expand Down Expand Up @@ -74,7 +89,7 @@

default: {
if($ensure == 'present' or $ensure == true) {
fail("Unsupported managed repository for osfamily: ${facts['os']['family']}, operatingsystem: ${facts['os']['name']}, module ${module_name} currently only supports managing repos for osfamily RedHat, Debian and Ubuntu")
fail("Unsupported managed repository for osfamily: ${facts['os']['family']}, operatingsystem: ${facts['os']['name']}, module ${module_name} currently only supports managing repos for osfamily RedHat, Suse, Debian and Ubuntu")
}
}
}
Expand Down
31 changes: 31 additions & 0 deletions manifests/repo/zypper.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# PRIVATE CLASS: do not use directly
#
# @summary This is a repo class for zypper
#
# This is a private class and cannot be used from outside this module.
#
# @author Frank Brehm <[email protected]>
#
# @api private
#
class mongodb::repo::zypper inherits mongodb::repo {
# We try to follow/reproduce the instruction
# http://docs.mongodb.org/manual/tutorial/install-mongodb-on-red-hat-centos-or-fedora-linux/

assert_private()

if $mongodb::repo::ensure == 'present' or $mongodb::repo::ensure == true {
zypprepo { 'mongodb':
descr => $mongodb::repo::description,
baseurl => $mongodb::repo::location,
gpgcheck => '0',
enabled => '1',
}
Zypprepo['mongodb'] -> Package<| tag == 'mongodb_package' |>
}
else {
zypprepo { 'mongodb':
ensure => absent,
}
}
}
11 changes: 11 additions & 0 deletions metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@
"18.04",
"20.04"
]
},
{
"operatingsystem": "SLES",
"operatingsystemrelease": [
"12",
"15"
]
}
],
"requirements": [
Expand All @@ -53,6 +60,10 @@
{
"name": "puppet/systemd",
"version_requirement": ">= 2.5.1 < 4.0.0"
},
{
"name": "puppet/zypprepo",
"version_requirement": ">= 4.0.1 < 6.0.0"
}
]
}
14 changes: 9 additions & 5 deletions spec/classes/mongos_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
it { is_expected.to contain_class('mongodb::mongos::config') }

case facts[:osfamily]
when 'RedHat'
when 'RedHat', 'Suse'
expected_content = <<-CONFIG
configdb = 127.0.0.1:27019
fork = true
Expand All @@ -54,7 +54,7 @@
# service
it { is_expected.to contain_class('mongodb::mongos::service') }

if facts[:osfamily] == 'RedHat'
if facts[:osfamily] == 'RedHat' || facts[:osfamily] == 'Suse'
it { is_expected.to contain_file('/etc/sysconfig/mongos') }
else
it { is_expected.not_to contain_file('/etc/sysconfig/mongos') }
Expand Down Expand Up @@ -119,19 +119,23 @@

# install
it { is_expected.to contain_class('mongodb::mongos::install') }
it { is_expected.to contain_package('mongodb_mongos').with_ensure('purged') }
if facts[:osfamily] == 'Suse'
it { is_expected.to contain_package('mongodb_mongos').with_ensure('absent') }
else
it { is_expected.to contain_package('mongodb_mongos').with_ensure('purged') }
end

# config
it { is_expected.to contain_class('mongodb::mongos::config') }

case facts[:osfamily]
when 'RedHat'
when 'RedHat', 'Suse'
it { is_expected.to contain_file('/etc/mongos.conf').with_ensure('absent') }
when 'Debian'
it { is_expected.to contain_file('/etc/mongodb-shard.conf').with_ensure('absent') }
end

if facts[:osfamily] == 'RedHat'
if facts[:osfamily] == 'RedHat' || facts[:osfamily] == 'Suse'
it { is_expected.to contain_file('/etc/sysconfig/mongos').with_ensure('absent') }
else
it { is_expected.not_to contain_file('/etc/sysconfig/mongos') }
Expand Down
8 changes: 8 additions & 0 deletions spec/classes/repo_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
is_expected.to contain_yumrepo('mongodb').
with_baseurl('https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.6/$basearch/')
end
when 'Suse'
it { is_expected.to contain_class('mongodb::repo::zypper') }
it do
is_expected.to contain_zypprepo('mongodb').
with_baseurl('https://repo.mongodb.org/zypper/suse/$releasever_major/mongodb-org/3.6/$basearch/')
end
when 'Debian'
it { is_expected.to contain_class('mongodb::repo::apt') }
case facts[:operatingsystem]
Expand Down Expand Up @@ -66,6 +72,8 @@
with_proxy_username('proxyuser1').
with_proxy_password('proxypassword1')
end
when 'Suse'
it { is_expected.to contain_class('mongodb::repo::zypper') }
when 'Debian'
it { is_expected.to contain_class('mongodb::repo::apt') }
else
Expand Down
2 changes: 1 addition & 1 deletion spec/classes/server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
describe 'with defaults' do
it_behaves_like 'server classes'

if facts[:os]['family'] == 'RedHat'
if facts[:os]['family'] == 'RedHat' || facts[:os]['family'] == 'Suse'
it { is_expected.to contain_package('mongodb_server').with_ensure('present').with_name('mongodb-org-server').with_tag('mongodb_package') }
elsif facts[:os]['release']['major'] =~ %r{(10)}
it { is_expected.to contain_package('mongodb_server').with_ensure('4.4.8').with_name('mongodb-org-server').with_tag('mongodb_package') }
Expand Down

0 comments on commit 2e6001a

Please sign in to comment.