Skip to content

Commit aa1a7ed

Browse files
hdepekohlZloeSaboroot-expert
authoredAug 20, 2021
Fix MongoDB installation on RedHat family (voxpupuli#606)
Co-authored-by: Ewoud Kohl van Wijngaarden <[email protected]> Co-authored-by: Evgeny Soynov <[email protected]> Co-authored-by: Christos Papageorgiou <[email protected]>
1 parent 89bf36f commit aa1a7ed

35 files changed

+297
-888
lines changed
 

‎.fixtures.yml

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ fixtures:
22
repositories:
33
"stdlib": "git://github.com/puppetlabs/puppetlabs-stdlib.git"
44
"apt": "git://github.com/puppetlabs/puppetlabs-apt.git"
5+
"systemd": "https://github.com/voxpupuli/puppet-systemd.git"
56
yumrepo_core:
67
repo: https://github.com/puppetlabs/puppetlabs-yumrepo_core.git
78
puppet_version: ">= 6.0.0"

‎.github/CONTRIBUTING.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ By participating in this project you agree to abide by its terms.
3333

3434
Please be prepared to repeat some of these steps as our contributors review your code.
3535

36+
Also consider sending in your profile code that calls this component module as an acceptance test or provide it via an issue. This helps reviewers a lot to test your use case and prevents future regressions!
37+
3638
## Writing proper commits - short version
3739

3840
* Make commits of logical units.
@@ -230,14 +232,14 @@ simple tests against it after applying the module. You can run this
230232
with:
231233

232234
```sh
233-
bundle exec rake acceptance
235+
bundle exec rake beaker
234236
```
235237

236238
This will run the tests on the module's default nodeset. You can override the
237239
nodeset used, e.g.,
238240

239241
```sh
240-
BEAKER_set=centos-7-x64 bundle exec rake acceptance
242+
BEAKER_set=centos-7-x64 bundle exec rake beaker
241243
```
242244

243245
There are default rake tasks for the various acceptance test modules, e.g.,
@@ -264,10 +266,9 @@ The following strings are known to work:
264266

265267
* ubuntu1604
266268
* ubuntu1804
267-
* debian8
269+
* ubuntu2004
268270
* debian9
269271
* debian10
270-
* centos6
271272
* centos7
272273
* centos8
273274

‎.github/workflows/ci.yml

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: CI
2+
3+
on: pull_request
4+
5+
jobs:
6+
setup_matrix:
7+
name: 'Setup Test Matrix'
8+
runs-on: ubuntu-latest
9+
outputs:
10+
beaker_setfiles: ${{ steps.get-outputs.outputs.beaker_setfiles }}
11+
puppet_major_versions: ${{ steps.get-outputs.outputs.puppet_major_versions }}
12+
puppet_unit_test_matrix: ${{ steps.get-outputs.outputs.puppet_unit_test_matrix }}
13+
env:
14+
BUNDLE_WITHOUT: development:test:release
15+
steps:
16+
- uses: actions/checkout@v2
17+
- name: Setup ruby
18+
uses: ruby/setup-ruby@v1
19+
with:
20+
ruby-version: '2.7'
21+
bundler-cache: true
22+
- name: Run rake validate
23+
run: bundle exec rake validate
24+
- name: Setup Test Matrix
25+
id: get-outputs
26+
run: bundle exec metadata2gha --use-fqdn --pidfile-workaround CentOS,Ubuntu
27+
28+
unit:
29+
needs: setup_matrix
30+
runs-on: ubuntu-latest
31+
strategy:
32+
fail-fast: false
33+
matrix:
34+
include: ${{fromJson(needs.setup_matrix.outputs.puppet_unit_test_matrix)}}
35+
env:
36+
BUNDLE_WITHOUT: development:system_tests:release
37+
PUPPET_VERSION: "~> ${{ matrix.puppet }}.0"
38+
name: Puppet ${{ matrix.puppet }} (Ruby ${{ matrix.ruby }})
39+
steps:
40+
- uses: actions/checkout@v2
41+
- name: Setup ruby
42+
uses: ruby/setup-ruby@v1
43+
with:
44+
ruby-version: ${{ matrix.ruby }}
45+
bundler-cache: true
46+
- name: Run tests
47+
run: bundle exec rake
48+
49+
acceptance:
50+
needs: setup_matrix
51+
runs-on: ubuntu-latest
52+
env:
53+
BUNDLE_WITHOUT: development:test:release
54+
strategy:
55+
fail-fast: false
56+
matrix:
57+
setfile: ${{fromJson(needs.setup_matrix.outputs.beaker_setfiles)}}
58+
puppet: ${{fromJson(needs.setup_matrix.outputs.puppet_major_versions)}}
59+
name: ${{ matrix.puppet.name }} - ${{ matrix.setfile.name }}
60+
steps:
61+
- name: Enable IPv6 on docker
62+
run: |
63+
echo '{"ipv6":true,"fixed-cidr-v6":"2001:db8:1::/64"}' | sudo tee /etc/docker/daemon.json
64+
sudo service docker restart
65+
- uses: actions/checkout@v2
66+
- name: Setup ruby
67+
uses: ruby/setup-ruby@v1
68+
with:
69+
ruby-version: '2.7'
70+
bundler-cache: true
71+
- name: Run tests
72+
run: bundle exec rake beaker
73+
env:
74+
BEAKER_PUPPET_COLLECTION: ${{ matrix.puppet.collection }}
75+
BEAKER_setfile: ${{ matrix.setfile.value }}

‎.github/workflows/release.yml

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- '*'
7+
8+
env:
9+
BUNDLE_WITHOUT: development:test:system_tests
10+
11+
jobs:
12+
deploy:
13+
name: 'deploy to forge'
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout repository
17+
uses: actions/checkout@v2
18+
- name: Setup Ruby
19+
uses: ruby/setup-ruby@v1
20+
with:
21+
ruby-version: '2.7'
22+
bundler-cache: true
23+
- name: Build and Deploy
24+
env:
25+
# Configure secrets here:
26+
# https://docs.github.com/en/free-pro-team@latest/actions/reference/encrypted-secrets
27+
BLACKSMITH_FORGE_USERNAME: '${{ secrets.PUPPET_FORGE_USERNAME }}'
28+
BLACKSMITH_FORGE_API_KEY: '${{ secrets.PUPPET_FORGE_API_KEY }}'
29+
run: bundle exec rake module:push

‎.msync.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
modulesync_config_version: '3.0.0'
1+
---
2+
modulesync_config_version: '4.0.0'

‎.overcommit.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,4 @@ PrePush:
6161
- 'validate'
6262
- 'test'
6363
- 'rubocop'
64-
command: [ 'bundle', 'exec', 'rake' ]
64+
command: ['bundle', 'exec', 'rake']

‎.pmtignore

+15-2
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,34 @@
11
docs/
22
pkg/
3+
Gemfile
34
Gemfile.lock
45
Gemfile.local
56
vendor/
67
.vendor/
7-
spec/fixtures/manifests/
8-
spec/fixtures/modules/
8+
spec/
9+
Rakefile
910
.vagrant/
1011
.bundle/
1112
.ruby-version
1213
coverage/
1314
log/
1415
.idea/
1516
.dependencies/
17+
.github/
1618
.librarian/
1719
Puppetfile.lock
1820
*.iml
21+
.editorconfig
22+
.fixtures.yml
23+
.gitignore
24+
.msync.yml
25+
.overcommit.yml
26+
.pmtignore
27+
.rspec
28+
.rspec_parallel
29+
.rubocop.yml
30+
.sync.yml
1931
.*.sw?
2032
.yardoc/
33+
.yardopts
2134
Dockerfile

‎.rubocop.yml

+3-549
Large diffs are not rendered by default.

‎.sync.yml

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
# the mongodb tests currently do not work on MongoDB 3.x or newer
21
---
3-
.travis.yml:
4-
secure: "TcZjuTP5ooDXZNRnG1M+wqmT/Lqcg8CwZfLljGlDSjDEN2siUhflHf9A81q5XL17oN4BkQtPmLvu7d/7xijUOiqDWXG9PC/Xr3QsTTmjtEo5l2Ne7jO+HrXO0Ron6LjEy47PeUWVQs7JcLRQL1SpxlNkt/Xe7oSoL10PmP2GYJc="
5-
docker_sets:
6-
- set: centos7-64
72
appveyor.yml:
83
delete: true
4+
.github/workflows/ci.yml:
5+
pidfile_workaround: CentOS,Ubuntu

‎.travis.yml

-56
This file was deleted.

‎Gemfile

+7-22
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,19 @@
11
source ENV['GEM_SOURCE'] || "https://rubygems.org"
22

3-
def location_for(place, fake_version = nil)
4-
if place =~ /^(git[:@][^#]*)#(.*)/
5-
[fake_version, { :git => $1, :branch => $2, :require => false }].compact
6-
elsif place =~ /^file:\/\/(.*)/
7-
['>= 0', { :path => File.expand_path($1), :require => false }]
8-
else
9-
[place, { :require => false }]
10-
end
11-
end
12-
133
group :test do
14-
gem 'voxpupuli-test', '~> 2.0', :require => false
4+
gem 'voxpupuli-test', '~> 2.1', :require => false
155
gem 'coveralls', :require => false
166
gem 'simplecov-console', :require => false
177
end
188

199
group :development do
20-
gem 'travis', :require => false
21-
gem 'travis-lint', :require => false
2210
gem 'guard-rake', :require => false
2311
gem 'overcommit', '>= 0.39.1', :require => false
2412
end
2513

2614
group :system_tests do
27-
gem 'voxpupuli-acceptance', :require => false
15+
gem 'puppet_metadata', '~> 0.3.0', :require => false
16+
gem 'voxpupuli-acceptance', :require => false
2817
end
2918

3019
group :release do
@@ -34,15 +23,11 @@ group :release do
3423
gem 'puppet-strings', '>= 2.2', :require => false
3524
end
3625

26+
gem 'puppetlabs_spec_helper', '~> 2.0', :require => false
27+
gem 'rake', :require => false
28+
gem 'facter', ENV['FACTER_GEM_VERSION'], :require => false, :groups => [:test]
3729

38-
39-
if facterversion = ENV['FACTER_GEM_VERSION']
40-
gem 'facter', facterversion.to_s, :require => false, :groups => [:test]
41-
else
42-
gem 'facter', :require => false, :groups => [:test]
43-
end
44-
45-
ENV['PUPPET_VERSION'].nil? ? puppetversion = '~> 6.0' : puppetversion = ENV['PUPPET_VERSION'].to_s
30+
puppetversion = ENV['PUPPET_VERSION'] || '~> 6.0'
4631
gem 'puppet', puppetversion, :require => false, :groups => [:test]
4732

4833
# vim: syntax=ruby

‎Rakefile

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
require 'voxpupuli/test/rake'
1+
# Attempt to load voxupuli-test (which pulls in puppetlabs_spec_helper),
2+
# otherwise attempt to load it directly.
3+
begin
4+
require 'voxpupuli/test/rake'
5+
rescue LoadError
6+
require 'puppetlabs_spec_helper/rake_tasks'
7+
end
28

39
# load optional tasks for releases
410
# only available if gem group releases is installed
@@ -26,6 +32,7 @@ end
2632

2733
begin
2834
require 'github_changelog_generator/task'
35+
require 'puppet_blacksmith'
2936
GitHubChangelogGenerator::RakeTask.new :changelog do |config|
3037
version = (Blacksmith::Modulefile.new).version
3138
config.future_release = "v#{version}" if version =~ /^\d+\.\d+.\d+$/

‎lib/puppet/provider/mongodb.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def self.db_ismaster
111111
cmd_ismaster = 'db.isMaster().ismaster'
112112
cmd_ismaster = mongorc_file + cmd_ismaster if mongorc_file
113113
db = 'admin'
114-
res = mongo_cmd(db, conn_string, cmd_ismaster).to_s.chomp
114+
res = mongo_cmd(db, conn_string, cmd_ismaster).to_s.split(%r{\n}).last.chomp
115115
res.eql?('true')
116116
end
117117

‎lib/puppet/provider/mongodb_user/mongodb.rb

+9-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,15 @@ def self.instances
88
require 'json'
99

1010
if db_ismaster
11-
users = JSON.parse mongo_eval('printjson(db.system.users.find().toArray())')
11+
script = 'printjson(db.system.users.find().toArray())'
12+
# A hack to prevent prefetching failures until admin user is created
13+
script = "try {#{script}} catch (e) { if (e.message.match(/not authorized on admin/)) { 'not authorized on admin' } else {throw e}}" if auth_enabled
14+
15+
out = mongo_eval(script)
16+
17+
return [] if auth_enabled && out.include?('not authorized on admin')
18+
19+
users = JSON.parse out
1220

1321
users.map do |user|
1422
new(name: user['_id'],

‎manifests/client/params.pp

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
} else {
99
$package_name = $facts['os']['family'] ? {
1010
'Debian' => 'mongodb-clients',
11+
'Redhat' => "mongodb-${mongodb::globals::edition}-shell",
1112
default => 'mongodb',
1213
}
1314
}

‎manifests/globals.pp

+22-9
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,30 @@
3838
}
3939

4040
# Setup of the repo only makes sense globally, so we are doing it here.
41-
if $manage_package_repo {
42-
if $use_enterprise_repo == true and $version == undef {
43-
fail('You must set mongodb::globals::version when mongodb::globals::use_enterprise_repo is true')
41+
case $facts['os']['family'] {
42+
'RedHat', 'Linux', 'Suse': {
43+
class { 'mongodb::repo':
44+
ensure => present,
45+
version => pick($version, '3.6'),
46+
use_enterprise_repo => $use_enterprise_repo,
47+
repo_location => $repo_location,
48+
proxy => $repo_proxy,
49+
}
4450
}
51+
default: {
52+
if $manage_package_repo {
53+
if $use_enterprise_repo == true and $version == undef {
54+
fail('You must set mongodb::globals::version when mongodb::globals::use_enterprise_repo is true')
55+
}
4556

46-
class { 'mongodb::repo':
47-
ensure => present,
48-
version => $version,
49-
use_enterprise_repo => $use_enterprise_repo,
50-
repo_location => $repo_location,
51-
proxy => $repo_proxy,
57+
class { 'mongodb::repo':
58+
ensure => present,
59+
version => $version,
60+
use_enterprise_repo => $use_enterprise_repo,
61+
repo_location => $repo_location,
62+
proxy => $repo_proxy,
63+
}
64+
}
5265
}
5366
}
5467
}

‎manifests/mongos.pp

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
Boolean $service_manage = $mongodb::mongos::params::service_manage,
99
Optional[String] $service_provider = $mongodb::mongos::params::service_provider,
1010
Optional[String] $service_name = $mongodb::mongos::params::service_name,
11+
Optional[String[1]] $service_template = $mongodb::mongos::params::service_template,
1112
Boolean $service_enable = $mongodb::mongos::params::service_enable,
1213
Stdlib::Ensure::Service $service_ensure = $mongodb::mongos::params::service_ensure,
1314
Optional[String] $service_status = $mongodb::mongos::params::service_status,

‎manifests/mongos/params.pp

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
$package_ensure = pick($version, 'present')
88
if $manage_package {
99
$package_name = "mongodb-${mongodb::globals::edition}-mongos"
10+
} elsif $facts['os']['family'] == 'RedHat' {
11+
$package_name = "mongodb-${mongodb::globals::edition}-mongos"
1012
} else {
1113
$package_name = 'mongodb-server'
1214
}
@@ -35,6 +37,7 @@
3537
$unixsocketprefix = undef
3638
$logpath = undef
3739
$fork = undef
40+
$service_template = undef
3841
} else {
3942
# RedHat/CentOS doesn't come with a prepacked mongodb
4043
# so we assume that you are using EPEL repository.
@@ -43,6 +46,7 @@
4346
$unixsocketprefix = '/var/run/mongodb'
4447
$logpath = '/var/log/mongodb/mongos.log'
4548
$fork = true
49+
$service_template = 'mongodb/mongos/RedHat/mongos.service-dropin.epp'
4650
}
4751
}
4852
'Debian': {
@@ -51,6 +55,7 @@
5155
$unixsocketprefix = undef
5256
$logpath = undef
5357
$fork = undef
58+
$service_template = undef
5459
}
5560
default: {
5661
fail("Osfamily ${facts['os']['family']} is not supported")

‎manifests/mongos/service.pp

+8
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
$service_provider = $mongodb::mongos::service_provider,
1010
$bind_ip = $mongodb::mongos::bind_ip,
1111
$port = $mongodb::mongos::port,
12+
$service_template = $mongodb::mongos::service_template,
1213
) {
1314
if $package_ensure in ['absent', 'purged'] {
1415
$real_service_ensure = 'stopped'
@@ -25,6 +26,13 @@
2526
}
2627

2728
if $service_manage {
29+
if $facts['os']['family'] == 'RedHat' {
30+
systemd::unit_file { 'mongos.service':
31+
content => epp($service_template),
32+
enable => $real_service_enable,
33+
} ~> Service['mongos']
34+
}
35+
2836
service { 'mongos':
2937
ensure => $real_service_ensure,
3038
name => $service_name,

‎manifests/params.pp

+3-11
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,9 @@
4040
# Amazon Linux's OS Family is 'Linux', operating system 'Amazon'.
4141
case $facts['os']['family'] {
4242
'RedHat', 'Linux', 'Suse': {
43-
if $manage_package {
44-
$user = pick($mongodb::globals::user, 'mongod')
45-
$group = pick($mongodb::globals::group, 'mongod')
46-
$server_package_name = pick($mongodb::globals::server_package_name, "mongodb-${mongodb::globals::edition}-server")
47-
} else {
48-
# RedHat/CentOS doesn't come with a prepacked mongodb
49-
# so we assume that you are using EPEL repository.
50-
$user = pick($mongodb::globals::user, 'mongodb')
51-
$group = pick($mongodb::globals::group, 'mongodb')
52-
$server_package_name = pick($mongodb::globals::server_package_name, 'mongodb-server')
53-
}
43+
$user = pick($mongodb::globals::user, 'mongod')
44+
$group = pick($mongodb::globals::group, 'mongod')
45+
$server_package_name = pick($mongodb::globals::server_package_name, "mongodb-${mongodb::globals::edition}-server")
5446

5547
$service_name = pick($mongodb::globals::service_name, 'mongod')
5648
$logpath = '/var/log/mongodb/mongod.log'

‎manifests/server/install.pp

+6-4
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@
2626
}
2727
}
2828

29-
package { 'mongodb_server':
30-
ensure => $my_package_ensure,
31-
name => $package_name,
32-
tag => 'mongodb_package',
29+
unless defined(Package[$package_name]) {
30+
package { 'mongodb_server':
31+
ensure => $my_package_ensure,
32+
name => $package_name,
33+
tag => 'mongodb_package',
34+
}
3335
}
3436
}

‎metadata.json

+4
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@
4848
{
4949
"name": "puppetlabs/stdlib",
5050
"version_requirement": ">= 4.25.0 < 7.0.0"
51+
},
52+
{
53+
"name": "puppet/systemd",
54+
"version_requirement": ">= 2.5.1 < 4.0.0"
5155
}
5256
]
5357
}

‎spec/acceptance/mongos_spec.rb

+18-12
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,35 @@
11
require 'spec_helper_acceptance'
22

33
describe 'mongodb::mongos class' do
4-
config_file = if fact('osfamily') == 'RedHat'
5-
'/etc/mongos.conf'
6-
else
7-
'/etc/mongodb-shard.conf'
8-
end
4+
case fact('osfamily')
5+
when 'Debian'
6+
package_name = 'mongodb-server'
7+
config_file = '/etc/mongodb-shard.conf'
8+
else
9+
package_name = 'mongodb-org-server'
10+
config_file = '/etc/mongos.conf'
11+
end
912

1013
describe 'installation' do
1114
it 'works with no errors' do
1215
pp = <<-EOS
1316
class { 'mongodb::server':
1417
configsvr => true,
18+
replset => 'test',
19+
replset_members => ['127.0.0.1:27019'],
20+
port => 27019,
1521
}
1622
-> class { 'mongodb::client': }
1723
-> class { 'mongodb::mongos':
18-
configdb => ['127.0.0.1:27019'],
24+
configdb => ['test/127.0.0.1:27019'],
1925
}
2026
EOS
2127

2228
apply_manifest(pp, catch_failures: true)
2329
apply_manifest(pp, catch_changes: true)
2430
end
2531

26-
describe package('mongodb-server') do
32+
describe package(package_name) do
2733
it { is_expected.to be_installed }
2834
end
2935

@@ -52,7 +58,10 @@ class { 'mongodb::server':
5258
describe 'uninstalling' do
5359
it 'uninstalls mongodb' do
5460
pp = <<-EOS
55-
class { 'mongodb::server':
61+
class { 'mongodb::mongos':
62+
package_ensure => 'purged',
63+
}
64+
-> class { 'mongodb::server':
5665
ensure => absent,
5766
package_ensure => absent,
5867
service_ensure => stopped,
@@ -61,15 +70,12 @@ class { 'mongodb::server':
6170
-> class { 'mongodb::client':
6271
ensure => absent,
6372
}
64-
-> class { 'mongodb::mongos':
65-
package_ensure => 'purged',
66-
}
6773
EOS
6874
apply_manifest(pp, catch_failures: true)
6975
apply_manifest(pp, catch_changes: true)
7076
end
7177

72-
describe package('mongodb-server') do
78+
describe package(package_name) do
7379
it { is_expected.not_to be_installed }
7480
end
7581

‎spec/acceptance/nodesets/archlinux-2-x64.yml

-13
This file was deleted.

‎spec/acceptance/nodesets/ec2/amazonlinux-2016091.yml

-31
This file was deleted.

‎spec/acceptance/nodesets/ec2/image_templates.yaml

-34
This file was deleted.

‎spec/acceptance/nodesets/ec2/rhel-73-x64.yml

-29
This file was deleted.

‎spec/acceptance/nodesets/ec2/sles-12sp2-x64.yml

-29
This file was deleted.

‎spec/acceptance/nodesets/ec2/ubuntu-1604-x64.yml

-29
This file was deleted.

‎spec/acceptance/nodesets/ec2/windows-2016-base-x64.yml

-29
This file was deleted.

‎spec/acceptance/server_spec.rb

+19-6
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
when 'Debian'
66
config_file = '/etc/mongodb.conf'
77
service_name = 'mongodb'
8+
package_name = 'mongodb-server'
89
else
910
config_file = '/etc/mongod.conf'
1011
service_name = 'mongod'
12+
package_name = 'mongodb-org-server'
1113
end
1214

1315
describe 'installation' do
@@ -21,7 +23,7 @@ class { 'mongodb::server': }
2123
apply_manifest(pp, catch_changes: true)
2224
end
2325

24-
describe package('mongodb-server') do
26+
describe package(package_name) do
2527
it { is_expected.to be_installed }
2628
end
2729

@@ -56,7 +58,7 @@ class { 'mongodb::server':
5658
apply_manifest(pp, catch_changes: true)
5759
end
5860

59-
describe package('mongodb-server') do
61+
describe package(package_name) do
6062
it { is_expected.to be_installed }
6163
end
6264

@@ -83,19 +85,30 @@ class { 'mongodb::server':
8385
pp = <<-EOS
8486
class { 'mongodb::server':
8587
auth => true,
86-
create_admin => true,
88+
create_admin => false,
89+
handle_creds => true,
8790
store_creds => true,
8891
admin_username => 'admin',
89-
admin_password => 'password'
92+
admin_password => 'password',
93+
restart => true,
94+
set_parameter => ['enableLocalhostAuthBypass: true']
9095
}
9196
class { 'mongodb::client': }
97+
98+
mongodb_user { "User admin on db admin":
99+
ensure => present,
100+
password_hash => mongodb_password('admin', 'password'),
101+
username => 'admin',
102+
database => 'admin',
103+
roles => ['dbAdmin', 'userAdminAnyDatabase'],
104+
}
92105
EOS
93106

94107
apply_manifest(pp, catch_failures: true)
95108
apply_manifest(pp, catch_changes: true)
96109
end
97110

98-
describe package('mongodb-server') do
111+
describe package(package_name) do
99112
it { is_expected.to be_installed }
100113
end
101114

@@ -149,7 +162,7 @@ class { 'mongodb::server':
149162
apply_manifest(pp, catch_changes: true)
150163
end
151164

152-
describe package('mongodb-server') do
165+
describe package(package_name) do
153166
it { is_expected.not_to be_installed }
154167
end
155168

‎spec/classes/mongos_spec.rb

+8-7
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,21 @@
55
context "on #{os}" do
66
let(:facts) { facts }
77

8-
let(:config_file) do
9-
if facts[:osfamily] == 'RedHat'
10-
'/etc/mongos.conf'
11-
else
12-
'/etc/mongodb-shard.conf'
13-
end
8+
case facts[:os]['family']
9+
when 'Debian'
10+
package_name = 'mongodb-server'
11+
config_file = '/etc/mongodb-shard.conf'
12+
else
13+
package_name = 'mongodb-org-mongos'
14+
config_file = '/etc/mongos.conf'
1415
end
1516

1617
context 'with defaults' do
1718
it { is_expected.to compile.with_all_deps }
1819

1920
# install
2021
it { is_expected.to contain_class('mongodb::mongos::install') }
21-
it { is_expected.to contain_package('mongodb_mongos').with_ensure('present').with_name('mongodb-server').with_tag('mongodb_package') }
22+
it { is_expected.to contain_package('mongodb_mongos').with_ensure('present').with_name(package_name).with_tag('mongodb_package') }
2223

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

‎spec/classes/server_spec.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@
3737
describe 'with defaults' do
3838
it_behaves_like 'server classes'
3939

40-
it { is_expected.to contain_package('mongodb_server').with_ensure('present').with_name('mongodb-server').with_tag('mongodb_package') }
40+
if facts[:os]['family'] == 'RedHat'
41+
it { is_expected.to contain_package('mongodb_server').with_ensure('present').with_name('mongodb-org-server').with_tag('mongodb_package') }
42+
else
43+
it { is_expected.to contain_package('mongodb_server').with_ensure('present').with_name('mongodb-server').with_tag('mongodb_package') }
44+
end
4145

4246
it do
4347
is_expected.to contain_file(config_file).

‎spec/spec_helper.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
require 'voxpupuli/test/spec_helper'
1010

1111
if File.exist?(File.join(__dir__, 'default_module_facts.yml'))
12-
facts = YAML.load(File.read(File.join(__dir__, 'default_module_facts.yml')))
12+
facts = YAML.safe_load(File.read(File.join(__dir__, 'default_module_facts.yml')))
1313
if facts
1414
facts.each do |name, value|
1515
add_custom_fact name.to_sym, value
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# THIS FILE IS MANAGED BY PUPPET
2+
[Unit]
3+
Description=MongoDB Database Server
4+
Documentation=https://docs.mongodb.org/manual
5+
After=network.target
6+
7+
[Service]
8+
User=mongod
9+
Group=mongod
10+
Environment="OPTIONS=-f /etc/mongos.conf"
11+
TimeoutStartSec=400
12+
ExecStart=/usr/bin/mongos $OPTIONS
13+
ExecStartPre=/usr/bin/mkdir -p /var/run/mongodb
14+
ExecStartPre=/usr/bin/chown mongod:mongod /var/run/mongodb
15+
ExecStartPre=/usr/bin/chmod 0755 /var/run/mongodb
16+
PermissionsStartOnly=true
17+
PIDFile=/var/run/mongodb/mongos.pid
18+
Type=forking
19+
# file size
20+
LimitFSIZE=infinity
21+
# cpu time
22+
LimitCPU=infinity
23+
# virtual memory size
24+
LimitAS=infinity
25+
# open files
26+
LimitNOFILE=64000
27+
# processes/threads
28+
LimitNPROC=64000
29+
# locked memory
30+
LimitMEMLOCK=infinity
31+
# total threads (user+kernel)
32+
TasksMax=infinity
33+
TasksAccounting=false
34+
# Recommended limits for for mongod as specified in
35+
# http://docs.mongodb.org/manual/reference/ulimit/#recommended-settings
36+
37+
[Install]
38+
WantedBy=multi-user.target

0 commit comments

Comments
 (0)
Please sign in to comment.