From 2e6001aa7d8354d61322ef597ce4128e4d16378b Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Thu, 28 Oct 2021 11:59:04 +0200 Subject: [PATCH] Add support for Suse Linux (#624) * 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 * Make the linter happy Co-authored-by: Tim Meusel --- .fixtures.yml | 1 + manifests/mongos/config.pp | 2 +- manifests/mongos/install.pp | 8 +++++++- manifests/mongos/params.pp | 2 +- manifests/repo.pp | 17 ++++++++++++++++- manifests/repo/zypper.pp | 31 +++++++++++++++++++++++++++++++ metadata.json | 11 +++++++++++ spec/classes/mongos_spec.rb | 14 +++++++++----- spec/classes/repo_spec.rb | 8 ++++++++ spec/classes/server_spec.rb | 2 +- 10 files changed, 86 insertions(+), 10 deletions(-) create mode 100644 manifests/repo/zypper.pp diff --git a/.fixtures.yml b/.fixtures.yml index f6b9ffe91..9937c6de4 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -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" diff --git a/manifests/mongos/config.pp b/manifests/mongos/config.pp index 7392ddde0..cff260155 100644 --- a/manifests/mongos/config.pp +++ b/manifests/mongos/config.pp @@ -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', diff --git a/manifests/mongos/install.pp b/manifests/mongos/install.pp index f45a8a82f..ac480db2f 100644 --- a/manifests/mongos/install.pp +++ b/manifests/mongos/install.pp @@ -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', } diff --git a/manifests/mongos/params.pp b/manifests/mongos/params.pp index ba6da3f27..7be61d997 100644 --- a/manifests/mongos/params.pp +++ b/manifests/mongos/params.pp @@ -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' diff --git a/manifests/repo.pp b/manifests/repo.pp index eb60f5ae7..c6f52049d 100644 --- a/manifests/repo.pp +++ b/manifests/repo.pp @@ -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 @@ -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") } } } diff --git a/manifests/repo/zypper.pp b/manifests/repo/zypper.pp new file mode 100644 index 000000000..bb463fcbc --- /dev/null +++ b/manifests/repo/zypper.pp @@ -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 +# +# @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, + } + } +} diff --git a/metadata.json b/metadata.json index c15df7332..135e005ad 100644 --- a/metadata.json +++ b/metadata.json @@ -33,6 +33,13 @@ "18.04", "20.04" ] + }, + { + "operatingsystem": "SLES", + "operatingsystemrelease": [ + "12", + "15" + ] } ], "requirements": [ @@ -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" } ] } diff --git a/spec/classes/mongos_spec.rb b/spec/classes/mongos_spec.rb index 35ef7498c..3102fb4d9 100644 --- a/spec/classes/mongos_spec.rb +++ b/spec/classes/mongos_spec.rb @@ -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 @@ -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') } @@ -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') } diff --git a/spec/classes/repo_spec.rb b/spec/classes/repo_spec.rb index baab14b6d..fdbec0f2b 100644 --- a/spec/classes/repo_spec.rb +++ b/spec/classes/repo_spec.rb @@ -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] @@ -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 diff --git a/spec/classes/server_spec.rb b/spec/classes/server_spec.rb index d6ffdbf9a..97de34673 100644 --- a/spec/classes/server_spec.rb +++ b/spec/classes/server_spec.rb @@ -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') }