From 5821ae2e32c32e64cb2e0fcb135562a24b34749c Mon Sep 17 00:00:00 2001 From: Steve Traylen Date: Wed, 24 May 2023 21:55:14 +0200 Subject: [PATCH 01/13] Drop EoL Debian 9 --- metadata.json | 1 - 1 file changed, 1 deletion(-) diff --git a/metadata.json b/metadata.json index a476262cd..72f4e5fef 100644 --- a/metadata.json +++ b/metadata.json @@ -23,7 +23,6 @@ { "operatingsystem": "Debian", "operatingsystemrelease": [ - "9", "10" ] }, From ee50f19eb3a12eeb228ca0cbb53d9a4d63ac14d8 Mon Sep 17 00:00:00 2001 From: Steve Traylen Date: Wed, 24 May 2023 21:59:08 +0200 Subject: [PATCH 02/13] Drop EoL Puppet 6 --- metadata.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metadata.json b/metadata.json index a476262cd..0bf8d34f5 100644 --- a/metadata.json +++ b/metadata.json @@ -45,7 +45,7 @@ "requirements": [ { "name": "puppet", - "version_requirement": ">= 6.1.0 < 8.0.0" + "version_requirement": ">= 7.0.0 < 8.0.0" } ], "dependencies": [ From 4400315769d2f7e8598c457ab9775597397e70d7 Mon Sep 17 00:00:00 2001 From: cocker-cc Date: Wed, 24 May 2023 01:42:06 +0200 Subject: [PATCH 03/13] Fix: Replace deprecated Datatypes --- REFERENCE.md | 2 +- manifests/server.pp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/REFERENCE.md b/REFERENCE.md index c1478f200..d25a6b4be 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -1469,7 +1469,7 @@ Default value: `$mongodb::params::logpath` ##### `bind_ip` -Data type: `Array[Stdlib::Compat::Ip_address]` +Data type: `Array[Stdlib::IP::Address]` diff --git a/manifests/server.pp b/manifests/server.pp index 3dd036878..3d094998a 100644 --- a/manifests/server.pp +++ b/manifests/server.pp @@ -33,7 +33,7 @@ Variant[Boolean, String] $package_ensure = $mongodb::params::package_ensure, String $package_name = $mongodb::params::server_package_name, Variant[Boolean, Stdlib::Absolutepath] $logpath = $mongodb::params::logpath, - Array[Stdlib::Compat::Ip_address] $bind_ip = $mongodb::params::bind_ip, + Array[Stdlib::IP::Address] $bind_ip = $mongodb::params::bind_ip, Optional[Boolean] $ipv6 = undef, Boolean $logappend = true, Optional[String] $system_logrotate = undef, From 5161f08b080dc51e60e6392af4acbb992114c2fa Mon Sep 17 00:00:00 2001 From: Tim Date: Wed, 15 Dec 2021 20:36:00 +0100 Subject: [PATCH 04/13] modulesync 5.1.0 --- .msync.yml | 2 +- .puppet-lint.rc | 3 +++ Gemfile | 4 ++-- Rakefile | 2 +- spec/spec_helper.rb | 10 +++++----- 5 files changed, 12 insertions(+), 9 deletions(-) create mode 100644 .puppet-lint.rc diff --git a/.msync.yml b/.msync.yml index 43966c2f5..a83abd9b6 100644 --- a/.msync.yml +++ b/.msync.yml @@ -2,4 +2,4 @@ # Managed by modulesync - DO NOT EDIT # https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ -modulesync_config_version: '4.2.0' +modulesync_config_version: '5.1.0' diff --git a/.puppet-lint.rc b/.puppet-lint.rc new file mode 100644 index 000000000..dd8272c7b --- /dev/null +++ b/.puppet-lint.rc @@ -0,0 +1,3 @@ +--fail-on-warnings +--no-parameter_documentation-check +--no-parameter_types-check diff --git a/Gemfile b/Gemfile index a39114ce3..b6dcf456a 100644 --- a/Gemfile +++ b/Gemfile @@ -4,7 +4,7 @@ source ENV['GEM_SOURCE'] || "https://rubygems.org" group :test do - gem 'voxpupuli-test', '~> 2.5', :require => false + gem 'voxpupuli-test', '~> 5.0', :require => false gem 'coveralls', :require => false gem 'simplecov-console', :require => false gem 'puppet_metadata', '~> 1.0', :require => false @@ -21,7 +21,7 @@ end group :release do gem 'github_changelog_generator', '>= 1.16.1', :require => false if RUBY_VERSION >= '2.5' - gem 'voxpupuli-release', '>= 1.0.2', :require => false + gem 'voxpupuli-release', '>= 1.2.0', :require => false gem 'puppet-strings', '>= 2.2', :require => false end diff --git a/Rakefile b/Rakefile index 80b799d63..f92f05164 100644 --- a/Rakefile +++ b/Rakefile @@ -1,7 +1,7 @@ # Managed by modulesync - DO NOT EDIT # https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ -# Attempt to load voxupuli-test (which pulls in puppetlabs_spec_helper), +# Attempt to load voxpupuli-test (which pulls in puppetlabs_spec_helper), # otherwise attempt to load it directly. begin require 'voxpupuli/test/rake' diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index fb5f0cbea..4d617f393 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,17 +1,17 @@ +# frozen_string_literal: true + # Managed by modulesync - DO NOT EDIT # https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ # puppetlabs_spec_helper will set up coverage if the env variable is set. # We want to do this if lib exists and it hasn't been explicitly set. -ENV['COVERAGE'] ||= 'yes' if Dir.exist?(File.expand_path('../../lib', __FILE__)) +ENV['COVERAGE'] ||= 'yes' if Dir.exist?(File.expand_path('../lib', __dir__)) require 'voxpupuli/test/spec_helper' if File.exist?(File.join(__dir__, 'default_module_facts.yml')) facts = YAML.safe_load(File.read(File.join(__dir__, 'default_module_facts.yml'))) - if facts - facts.each do |name, value| - add_custom_fact name.to_sym, value - end + facts&.each do |name, value| + add_custom_fact name.to_sym, value end end From 781417fb2a1838cba15b36ba2b283264c62a3d89 Mon Sep 17 00:00:00 2001 From: Tim Meusel Date: Fri, 12 May 2023 12:45:35 +0200 Subject: [PATCH 05/13] modulesync 6.0.0 --- .github/CONTRIBUTING.md | 7 ++- .github/SECURITY.md | 3 -- .github/workflows/release.yml | 32 +++++--------- .gitignore | 36 ++++++++-------- .msync.yml | 2 +- .pmtignore | 64 ++++++++++++++-------------- Gemfile | 16 +++---- Rakefile | 36 ++-------------- spec/acceptance/nodesets/default.yml | 10 ----- spec/spec_helper.rb | 2 + 10 files changed, 78 insertions(+), 130 deletions(-) delete mode 100644 .github/SECURITY.md delete mode 100644 spec/acceptance/nodesets/default.yml diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 048d2b55d..8b466cfb9 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -124,7 +124,7 @@ If you have Ruby 2.x or want a specific version of Puppet, you must set an environment variable such as: ```sh -export PUPPET_VERSION="~> 5.5.6" +export PUPPET_GEM_VERSION="~> 6.1.0" ``` You can install all needed gems for spec tests into the modules directory by @@ -232,17 +232,16 @@ simple tests against it after applying the module. You can run this with: ```sh -BEAKER_setfile=debian10-x64 bundle exec rake beaker +BEAKER_setfile=debian11-64 bundle exec rake beaker ``` You can replace the string `debian10` with any common operating system. The following strings are known to work: -* ubuntu1604 * ubuntu1804 * ubuntu2004 -* debian9 * debian10 +* debian11 * centos7 * centos8 diff --git a/.github/SECURITY.md b/.github/SECURITY.md deleted file mode 100644 index cacadf220..000000000 --- a/.github/SECURITY.md +++ /dev/null @@ -1,3 +0,0 @@ -# Vox Pupuli Security Policy - -Our vulnerabilities reporting process is at https://voxpupuli.org/security/ diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 664ba6946..15f172134 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -9,26 +9,14 @@ on: tags: - '*' -env: - BUNDLE_WITHOUT: development:test:system_tests - jobs: - deploy: - name: 'deploy to forge' - runs-on: ubuntu-latest - if: github.repository_owner == 'voxpupuli' - steps: - - name: Checkout repository - uses: actions/checkout@v2 - - name: Setup Ruby - uses: ruby/setup-ruby@v1 - with: - ruby-version: '2.7' - bundler-cache: true - - name: Build and Deploy - env: - # Configure secrets here: - # https://docs.github.com/en/free-pro-team@latest/actions/reference/encrypted-secrets - BLACKSMITH_FORGE_USERNAME: '${{ secrets.PUPPET_FORGE_USERNAME }}' - BLACKSMITH_FORGE_API_KEY: '${{ secrets.PUPPET_FORGE_API_KEY }}' - run: bundle exec rake module:push + release: + name: Release + uses: voxpupuli/gha-puppet/.github/workflows/release.yml@v1 + with: + allowed_owner: 'voxpupuli' + secrets: + # Configure secrets here: + # https://docs.github.com/en/actions/security-guides/encrypted-secrets + username: ${{ secrets.PUPPET_FORGE_USERNAME }} + api_key: ${{ secrets.PUPPET_FORGE_API_KEY }} diff --git a/.gitignore b/.gitignore index 9b95224ce..84fd904ca 100644 --- a/.gitignore +++ b/.gitignore @@ -1,23 +1,23 @@ # Managed by modulesync - DO NOT EDIT # https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ -pkg/ -Gemfile.lock -Gemfile.local -vendor/ -.vendor/ -spec/fixtures/manifests/ -spec/fixtures/modules/ -.vagrant/ -.bundle/ -.ruby-version -coverage/ -log/ -.idea/ -.dependencies/ -.librarian/ -Puppetfile.lock +/pkg/ +/Gemfile.lock +/Gemfile.local +/vendor/ +/.vendor/ +/spec/fixtures/manifests/ +/spec/fixtures/modules/ +/.vagrant/ +/.bundle/ +/.ruby-version +/coverage/ +/log/ +/.idea/ +/.dependencies/ +/.librarian/ +/Puppetfile.lock *.iml .*.sw? -.yardoc/ -Guardfile +/.yardoc/ +/Guardfile diff --git a/.msync.yml b/.msync.yml index a83abd9b6..b929160c9 100644 --- a/.msync.yml +++ b/.msync.yml @@ -2,4 +2,4 @@ # Managed by modulesync - DO NOT EDIT # https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ -modulesync_config_version: '5.1.0' +modulesync_config_version: '6.0.0' diff --git a/.pmtignore b/.pmtignore index 65f505149..58a040887 100644 --- a/.pmtignore +++ b/.pmtignore @@ -1,37 +1,37 @@ # Managed by modulesync - DO NOT EDIT # https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ -docs/ -pkg/ -Gemfile -Gemfile.lock -Gemfile.local -vendor/ -.vendor/ -spec/ -Rakefile -.vagrant/ -.bundle/ -.ruby-version -coverage/ -log/ -.idea/ -.dependencies/ -.github/ -.librarian/ -Puppetfile.lock +/docs/ +/pkg/ +/Gemfile +/Gemfile.lock +/Gemfile.local +/vendor/ +/.vendor/ +/spec/ +/Rakefile +/.vagrant/ +/.bundle/ +/.ruby-version +/coverage/ +/log/ +/.idea/ +/.dependencies/ +/.github/ +/.librarian/ +/Puppetfile.lock *.iml -.editorconfig -.fixtures.yml -.gitignore -.msync.yml -.overcommit.yml -.pmtignore -.rspec -.rspec_parallel -.rubocop.yml -.sync.yml +/.editorconfig +/.fixtures.yml +/.gitignore +/.msync.yml +/.overcommit.yml +/.pmtignore +/.rspec +/.rspec_parallel +/.rubocop.yml +/.sync.yml .*.sw? -.yardoc/ -.yardopts -Dockerfile +/.yardoc/ +/.yardopts +/Dockerfile diff --git a/Gemfile b/Gemfile index b6dcf456a..98a04cfb9 100644 --- a/Gemfile +++ b/Gemfile @@ -1,13 +1,13 @@ # Managed by modulesync - DO NOT EDIT # https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ -source ENV['GEM_SOURCE'] || "https://rubygems.org" +source ENV['GEM_SOURCE'] || 'https://rubygems.org' group :test do - gem 'voxpupuli-test', '~> 5.0', :require => false + gem 'voxpupuli-test', '~> 6.0', :require => false gem 'coveralls', :require => false gem 'simplecov-console', :require => false - gem 'puppet_metadata', '~> 1.0', :require => false + gem 'puppet_metadata', '~> 3.0', :require => false end group :development do @@ -16,19 +16,19 @@ group :development do end group :system_tests do - gem 'voxpupuli-acceptance', '~> 1.0', :require => false + gem 'voxpupuli-acceptance', '~> 2.0', :require => false end group :release do - gem 'github_changelog_generator', '>= 1.16.1', :require => false if RUBY_VERSION >= '2.5' - gem 'voxpupuli-release', '>= 1.2.0', :require => false - gem 'puppet-strings', '>= 2.2', :require => false + gem 'github_changelog_generator', '>= 1.16.1', :require => false + gem 'voxpupuli-release', '~> 3.0', :require => false + gem 'faraday-retry', '~> 2.1', :require => false end gem 'rake', :require => false gem 'facter', ENV['FACTER_GEM_VERSION'], :require => false, :groups => [:test] -puppetversion = ENV['PUPPET_VERSION'] || '>= 6.0' +puppetversion = ENV['PUPPET_GEM_VERSION'] || '~> 7.24' gem 'puppet', puppetversion, :require => false, :groups => [:test] # vim: syntax=ruby diff --git a/Rakefile b/Rakefile index f92f05164..6b3e053ab 100644 --- a/Rakefile +++ b/Rakefile @@ -24,6 +24,10 @@ end begin require 'voxpupuli/release/rake_tasks' rescue LoadError + # voxpupuli-release not present +else + GCGConfig.user = 'voxpupuli' + GCGConfig.project = 'puppet-mongodb' end desc "Run main 'test' task and report merged results to coveralls" @@ -37,36 +41,4 @@ task test_with_coveralls: [:test] do end end -desc 'Generate REFERENCE.md' -task :reference, [:debug, :backtrace] do |t, args| - patterns = '' - Rake::Task['strings:generate:reference'].invoke(patterns, args[:debug], args[:backtrace]) -end - -begin - require 'github_changelog_generator/task' - require 'puppet_blacksmith' - GitHubChangelogGenerator::RakeTask.new :changelog do |config| - metadata = Blacksmith::Modulefile.new - config.future_release = "v#{metadata.version}" if metadata.version =~ /^\d+\.\d+.\d+$/ - config.header = "# Changelog\n\nAll notable changes to this project will be documented in this file.\nEach new release typically also includes the latest modulesync defaults.\nThese should not affect the functionality of the module." - config.exclude_labels = %w{duplicate question invalid wontfix wont-fix modulesync skip-changelog} - config.user = 'voxpupuli' - config.project = metadata.metadata['name'] - end - - # Workaround for https://github.com/github-changelog-generator/github-changelog-generator/issues/715 - require 'rbconfig' - if RbConfig::CONFIG['host_os'] =~ /linux/ - task :changelog do - puts 'Fixing line endings...' - changelog_file = File.join(__dir__, 'CHANGELOG.md') - changelog_txt = File.read(changelog_file) - new_contents = changelog_txt.gsub(%r{\r\n}, "\n") - File.open(changelog_file, "w") {|file| file.puts new_contents } - end - end - -rescue LoadError -end # vim: syntax=ruby diff --git a/spec/acceptance/nodesets/default.yml b/spec/acceptance/nodesets/default.yml deleted file mode 100644 index dba339c46..000000000 --- a/spec/acceptance/nodesets/default.yml +++ /dev/null @@ -1,10 +0,0 @@ -HOSTS: - ubuntu-1404-x64: - roles: - - agent - - default - platform: ubuntu-14.04-amd64 - hypervisor: vagrant - box: puppetlabs/ubuntu-14.04-64-nocm -CONFIG: - type: foss diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 4d617f393..6515b7bf7 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -9,6 +9,8 @@ require 'voxpupuli/test/spec_helper' +add_mocked_facts! + if File.exist?(File.join(__dir__, 'default_module_facts.yml')) facts = YAML.safe_load(File.read(File.join(__dir__, 'default_module_facts.yml'))) facts&.each do |name, value| From 674bf35caad3a4fe7e86450f5bbd4aee52a45b33 Mon Sep 17 00:00:00 2001 From: Steve Traylen Date: Thu, 25 May 2023 07:54:43 +0200 Subject: [PATCH 06/13] rubocop autocorrect results --- lib/facter/is_master.rb | 2 + lib/facter/mongodb_version.rb | 4 +- lib/puppet/functions/mongodb_password.rb | 2 + lib/puppet/provider/mongodb.rb | 10 +- .../mongodb_conn_validator/tcp_port.rb | 2 + .../provider/mongodb_database/mongodb.rb | 6 +- lib/puppet/provider/mongodb_replset/mongo.rb | 123 +++++++-------- lib/puppet/provider/mongodb_shard/mongo.rb | 25 +-- lib/puppet/provider/mongodb_user/mongodb.rb | 16 +- lib/puppet/type/mongodb_conn_validator.rb | 2 + lib/puppet/type/mongodb_database.rb | 2 + lib/puppet/type/mongodb_replset.rb | 4 + lib/puppet/type/mongodb_shard.rb | 2 + lib/puppet/type/mongodb_user.rb | 14 +- lib/puppet/util/mongodb_md5er.rb | 2 + lib/puppet/util/mongodb_output.rb | 6 +- lib/puppet/util/mongodb_scram.rb | 12 +- lib/puppet/util/mongodb_validator.rb | 21 ++- spec/acceptance/database_spec.rb | 4 + spec/acceptance/mongos_spec.rb | 2 + spec/acceptance/replset_spec.rb | 148 +++++++++--------- spec/acceptance/server_spec.rb | 2 + spec/acceptance/sharding_spec.rb | 5 +- spec/acceptance/user_spec.rb | 2 + spec/classes/client_spec.rb | 4 + spec/classes/globals_spec.rb | 2 + spec/classes/mongos_spec.rb | 22 +-- spec/classes/repo_spec.rb | 6 + spec/classes/server_spec.rb | 11 +- spec/defines/db_spec.rb | 2 + spec/functions/mongodb_password_spec.rb | 2 + spec/opsmanager_spec.rb | 2 + spec/spec_helper_acceptance.rb | 2 + spec/types/mongodb_database_spec.rb | 2 + spec/unit/mongodb_version_spec.rb | 3 + .../provider/mongodb_database/mongodb_spec.rb | 2 + .../provider/mongodb_replset/mongodb_spec.rb | 129 +++++++-------- .../provider/mongodb_shard/mongodb_spec.rb | 2 + spec/unit/puppet/provider/mongodb_spec.rb | 2 + .../provider/mongodb_user/mongodb_spec.rb | 2 + spec/unit/puppet/type/mongodb_replset_spec.rb | 2 + spec/unit/puppet/type/mongodb_shard_spec.rb | 2 + spec/unit/puppet/type/mongodb_user_spec.rb | 2 + spec/unit/puppet/util/mongodb_output_spec.rb | 1 + 44 files changed, 352 insertions(+), 268 deletions(-) diff --git a/lib/facter/is_master.rb b/lib/facter/is_master.rb index 9414f44ee..1e406f28a 100644 --- a/lib/facter/is_master.rb +++ b/lib/facter/is_master.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'json' require 'yaml' diff --git a/lib/facter/mongodb_version.rb b/lib/facter/mongodb_version.rb index 84b9d26d3..97fb1937b 100644 --- a/lib/facter/mongodb_version.rb +++ b/lib/facter/mongodb_version.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + Facter.add(:mongodb_version) do setcode do if Facter::Core::Execution.which('mongo') mongodb_version = Facter::Core::Execution.execute('mongo --version 2>&1') - %r{MongoDB shell version:?\s+v?([\w\.]+)}.match(mongodb_version)[1] + %r{MongoDB shell version:?\s+v?([\w.]+)}.match(mongodb_version)[1] end end end diff --git a/lib/puppet/functions/mongodb_password.rb b/lib/puppet/functions/mongodb_password.rb index 1f195b94a..f6d45ede8 100644 --- a/lib/puppet/functions/mongodb_password.rb +++ b/lib/puppet/functions/mongodb_password.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative File.join('..', 'util', 'mongodb_md5er') # Get the mongodb password hash from the clear text password. diff --git a/lib/puppet/provider/mongodb.rb b/lib/puppet/provider/mongodb.rb index 91b16f36a..4e9554426 100644 --- a/lib/puppet/provider/mongodb.rb +++ b/lib/puppet/provider/mongodb.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..')) require 'puppet/util/mongodb_output' @@ -163,18 +165,16 @@ def self.mongo_eval(cmd, db = 'admin', retries = 10, host = nil) else mongo_cmd(db, conn_string, cmd) end - rescue => e + rescue StandardError => e retry_count -= 1 - if retry_count > 0 + if retry_count.positive? Puppet.debug "Request failed: '#{e.message}' Retry: '#{retries - retry_count}'" sleep retry_sleep retry end end - unless out - raise Puppet::ExecutionFailure, "Could not evaluate MongoDB shell command: #{cmd}" - end + raise Puppet::ExecutionFailure, "Could not evaluate MongoDB shell command: #{cmd}" unless out Puppet::Util::MongodbOutput.sanitize(out) end diff --git a/lib/puppet/provider/mongodb_conn_validator/tcp_port.rb b/lib/puppet/provider/mongodb_conn_validator/tcp_port.rb index 16085a9a8..61111609f 100644 --- a/lib/puppet/provider/mongodb_conn_validator/tcp_port.rb +++ b/lib/puppet/provider/mongodb_conn_validator/tcp_port.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', '..')) require 'puppet/util/mongodb_validator' diff --git a/lib/puppet/provider/mongodb_database/mongodb.rb b/lib/puppet/provider/mongodb_database/mongodb.rb index b306b9395..46a7719f0 100644 --- a/lib/puppet/provider/mongodb_database/mongodb.rb +++ b/lib/puppet/provider/mongodb_database/mongodb.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require File.expand_path(File.join(File.dirname(__FILE__), '..', 'mongodb')) Puppet::Type.type(:mongodb_database).provide(:mongodb, parent: Puppet::Provider::Mongodb) do desc 'Manages MongoDB database.' @@ -8,7 +10,7 @@ def self.instances require 'json' pre_cmd = 'try { rs.secondaryOk() } catch (err) { rs.slaveOk() }' - dbs = JSON.parse mongo_eval(pre_cmd + ';printjson(db.getMongo().getDBs())') + dbs = JSON.parse mongo_eval("#{pre_cmd};printjson(db.getMongo().getDBs())") dbs['databases'].map do |db| new(name: db['name'], @@ -19,7 +21,7 @@ def self.instances # Assign prefetched dbs based on name. def self.prefetch(resources) dbs = instances - resources.keys.each do |name| + resources.each_key do |name| provider = dbs.find { |db| db.name == name } resources[name].provider = provider if provider end diff --git a/lib/puppet/provider/mongodb_replset/mongo.rb b/lib/puppet/provider/mongodb_replset/mongo.rb index 5f995c73b..57f01511a 100644 --- a/lib/puppet/provider/mongodb_replset/mongo.rb +++ b/lib/puppet/provider/mongodb_replset/mongo.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # # Author: Francois Charlier # @@ -6,12 +8,12 @@ Puppet::Type.type(:mongodb_replset).provide(:mongo, parent: Puppet::Provider::Mongodb) do desc 'Manage hosts members for a replicaset.' - confine true: begin - require 'json' - true - rescue LoadError - false - end + confine true: begin + require 'json' + true + rescue LoadError + false + end mk_resource_methods @@ -149,39 +151,33 @@ def self.replset_properties def get_hosts_status(members) alive = [] members.select do |member| - begin - host = member['host'] - Puppet.debug "Checking replicaset member #{host} ..." - status = rs_status(host) - if status.key?('errmsg') && status['errmsg'] == 'not running with --replSet' - raise Puppet::Error, "Can't configure replicaset #{name}, host #{host} is not supposed to be part of a replicaset." - end - - if auth_enabled && status.key?('errmsg') && (status['errmsg'].include?('unauthorized') || status['errmsg'].include?('not authorized') || status['errmsg'].include?('requires authentication')) - Puppet.warning "Host #{host} is available, but you are unauthorized because of authentication is enabled: #{auth_enabled}" - alive.push(member) - end + host = member['host'] + Puppet.debug "Checking replicaset member #{host} ..." + status = rs_status(host) + raise Puppet::Error, "Can't configure replicaset #{name}, host #{host} is not supposed to be part of a replicaset." if status.key?('errmsg') && status['errmsg'] == 'not running with --replSet' + + if auth_enabled && status.key?('errmsg') && (status['errmsg'].include?('unauthorized') || status['errmsg'].include?('not authorized') || status['errmsg'].include?('requires authentication')) + Puppet.warning "Host #{host} is available, but you are unauthorized because of authentication is enabled: #{auth_enabled}" + alive.push(member) + end - if status.key?('errmsg') && status['errmsg'].include?('no replset config has been received') - Puppet.debug 'Mongo v4 rs.status() RS not initialized output' - alive.push(member) - end + if status.key?('errmsg') && status['errmsg'].include?('no replset config has been received') + Puppet.debug 'Mongo v4 rs.status() RS not initialized output' + alive.push(member) + end - if status.key?('set') - if status['set'] != name - raise Puppet::Error, "Can't configure replicaset #{name}, host #{host} is already part of another replicaset." - end + if status.key?('set') + raise Puppet::Error, "Can't configure replicaset #{name}, host #{host} is already part of another replicaset." if status['set'] != name - # This node is alive and supposed to be a member of our set - Puppet.debug "Host #{host} is available for replset #{status['set']}" - alive.push(member) - elsif status.key?('info') - Puppet.debug "Host #{host} is alive but unconfigured: #{status['info']}" - alive.push(member) - end - rescue Puppet::ExecutionFailure - Puppet.warning "Can't connect to replicaset member #{host}." + # This node is alive and supposed to be a member of our set + Puppet.debug "Host #{host} is available for replset #{status['set']}" + alive.push(member) + elsif status.key?('info') + Puppet.debug "Host #{host} is alive but unconfigured: #{status['info']}" + alive.push(member) end + rescue Puppet::ExecutionFailure + Puppet.warning "Can't connect to replicaset member #{host}." end alive.uniq! dead = members - alive @@ -199,8 +195,10 @@ def get_members_changes(current_members_conf, new_members_conf) new_members_conf.each do |nm| next unless remove_members.each_with_index do |om, index| next unless nm['host'] == om['host'] + nm.each do |k, v| next unless v != om[k] + # new config for existing node update_members.push(nm) break @@ -209,6 +207,7 @@ def get_members_changes(current_members_conf, new_members_conf) remove_members.delete_at(index) break end + # new node for cluster add_members.push(nm) end @@ -264,30 +263,26 @@ def set_members replset_conf = { _id: name, members: members_conf, - settings: (!@property_flush[:settings].nil? ? @property_flush[:settings] : {}) + settings: (@property_flush[:settings].nil? ? {} : @property_flush[:settings]) }.to_json Puppet.debug "Starting replset config is #{replset_conf.to_json}" # Set replset members with the first host as the master output = rs_initiate(replset_conf, alive_hosts[0]['host']) - if output['ok'].zero? - raise Puppet::Error, "rs.initiate() failed for replicaset #{name}: #{output['errmsg']}" - end + raise Puppet::Error, "rs.initiate() failed for replicaset #{name}: #{output['errmsg']}" if output['ok'].zero? # Check that the replicaset has finished initialization retry_limit = 10 retry_sleep = 3 retry_limit.times do |n| - begin - if db_ismaster(alive_hosts[0]['host'])['ismaster'] - Puppet.debug 'Replica set initialization has successfully ended' - return true - else - Puppet.debug "Wainting for replica initialization. Retry: #{n}" - sleep retry_sleep - next - end + if db_ismaster(alive_hosts[0]['host'])['ismaster'] + Puppet.debug 'Replica set initialization has successfully ended' + return true + else + Puppet.debug "Wainting for replica initialization. Retry: #{n}" + sleep retry_sleep + next end end raise Puppet::Error, "rs.initiate() failed for replicaset #{name}: host #{alive_hosts[0]['host']} didn't become master" @@ -308,13 +303,13 @@ def set_members output = {} retry_limit.times do |n| output = rs_add(member, master) - if !output['ok'].zero? - Puppet.debug 'Host successfully added to replicaset' - break - else + if output['ok'].zero? Puppet.debug "Retry adding host to replicaset. Retry: #{n}" sleep retry_sleep master = master_host(alive_hosts) + else + Puppet.debug 'Host successfully added to replicaset' + break end end raise Puppet::Error, "rs.add() failed to add host to replicaset #{name}: #{output['errmsg']}" if output['ok'].zero? @@ -328,13 +323,13 @@ def set_members output = {} retry_limit.times do |n| output = rs_remove(member, master) - if !output['ok'].zero? - Puppet.debug 'Host successfully removed from replicaset' - break - else + if output['ok'].zero? Puppet.debug "Retry removing host from replicaset. Retry: #{n}" sleep retry_sleep master = master_host(alive_hosts) + else + Puppet.debug 'Host successfully removed from replicaset' + break end end raise Puppet::Error, "rs.remove() failed to remove host from replicaset #{name}: #{output['errmsg']}" if output['ok'].zero? @@ -348,13 +343,13 @@ def set_members output = {} retry_limit.times do |n| output = rs_reconfig_member(member, master) - if !output['ok'].zero? - Puppet.debug 'Host successfully updated in replicaset' - break - else + if output['ok'].zero? Puppet.debug "Retry updating host in replicaset. Retry: #{n}" sleep retry_sleep master = master_host(alive_hosts) + else + Puppet.debug 'Host successfully updated in replicaset' + break end end raise Puppet::Error, "rs.reconfig() failed to update host in replicaset #{name}: #{output['errmsg']}" if output['ok'].zero? @@ -368,13 +363,13 @@ def set_members output = {} retry_limit.times do |n| output = rs_reconfig_settings(settings, master) - if !output['ok'].zero? - Puppet.debug 'Settings successfully updated in replicaset' - break - else + if output['ok'].zero? Puppet.debug "Retry updating settings in replicaset. Retry: #{n}" sleep retry_sleep master = master_host(alive_hosts) + else + Puppet.debug 'Settings successfully updated in replicaset' + break end end raise Puppet::Error, "rs.reconfig() failed to update settings in replicaset #{name}: #{output['errmsg']}" if output['ok'].zero? diff --git a/lib/puppet/provider/mongodb_shard/mongo.rb b/lib/puppet/provider/mongodb_shard/mongo.rb index 15d7e155e..283d6cce2 100644 --- a/lib/puppet/provider/mongodb_shard/mongo.rb +++ b/lib/puppet/provider/mongodb_shard/mongo.rb @@ -1,13 +1,15 @@ +# frozen_string_literal: true + require File.expand_path(File.join(File.dirname(__FILE__), '..', 'mongodb')) Puppet::Type.type(:mongodb_shard).provide(:mongo, parent: Puppet::Provider::Mongodb) do desc 'Manage mongodb sharding.' - confine true: begin - require 'json' - true - rescue LoadError - false - end + confine true: begin + require 'json' + true + rescue LoadError + false + end mk_resource_methods @@ -68,6 +70,7 @@ def set_member Puppet.debug "Adding the shard #{name}" output = sh_addshard(@property_flush[:member]) raise Puppet::Error, "sh.addShard() failed for shard #{name}: #{output['errmsg']}" if output['ok'].zero? + output = sh_enablesharding(name) raise Puppet::Error, "sh.enableSharding() failed for shard #{name}: #{output['errmsg']}" if output['ok'].zero? @@ -89,6 +92,7 @@ def self.shard_collection_details(obj, shard_name) collection_array = [] obj.each do |database| next unless database['_id'].eql?(shard_name) && !database['shards'].nil? + collection_array = database['shards'].map do |collection| { collection.keys.first => collection.values.first['shardkey'] } end @@ -101,6 +105,7 @@ def self.shard_properties(shard) output = mongo_command('sh.status()') output['shards'].each do |s| next unless s['_id'] == shard + properties = { name: s['_id'], ensure: :present, @@ -114,7 +119,9 @@ def self.shard_properties(shard) def self.shards_properties output = mongo_command('sh.status()') - properties = if !output['shards'].empty? + properties = if output['shards'].empty? + [] + else output['shards'].map do |shard| { name: shard['_id'], @@ -124,8 +131,6 @@ def self.shards_properties provider: :mongo } end - else - [] end Puppet.debug("MongoDB shard properties: #{properties.inspect}") properties @@ -158,7 +163,7 @@ def self.mongo_command(command, host = nil, _retries = 4) retry end - # NOTE (spredzy) : sh.status() + # NOTE: (spredzy) : sh.status() # does not return a json stream # we jsonify it so it is easier # to parse and deal with it diff --git a/lib/puppet/provider/mongodb_user/mongodb.rb b/lib/puppet/provider/mongodb_user/mongodb.rb index 07762fd57..3b21a2ee0 100644 --- a/lib/puppet/provider/mongodb_user/mongodb.rb +++ b/lib/puppet/provider/mongodb_user/mongodb.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require File.expand_path(File.join(File.dirname(__FILE__), '..', 'mongodb')) Puppet::Type.type(:mongodb_user).provide(:mongodb, parent: Puppet::Provider::Mongodb) do desc 'Manage users for a MongoDB database.' @@ -29,7 +31,7 @@ def self.instances end else Puppet.warning 'User info is available only from master host' - return [] + [] end end @@ -47,9 +49,7 @@ def self.prefetch(resources) def create if db_ismaster password_hash = @resource[:password_hash] - if !password_hash && @resource[:password] - password_hash = Puppet::Util::MongodbMd5er.md5(@resource[:username], @resource[:password]) - end + password_hash = Puppet::Util::MongodbMd5er.md5(@resource[:username], @resource[:password]) if !password_hash && @resource[:password] command = { createUser: @resource[:username], @@ -131,14 +131,10 @@ def password=(value) def roles=(roles) if db_ismaster grant = to_roles(roles, @resource[:database]) - to_roles(@property_hash[:roles], @resource[:database]) - unless grant.empty? - mongo_eval("db.getSiblingDB(#{@resource[:database].to_json}).grantRolesToUser(#{@resource[:username].to_json}, #{role_hashes(grant, @resource[:database]).to_json})") - end + mongo_eval("db.getSiblingDB(#{@resource[:database].to_json}).grantRolesToUser(#{@resource[:username].to_json}, #{role_hashes(grant, @resource[:database]).to_json})") unless grant.empty? revoke = to_roles(@property_hash[:roles], @resource[:database]) - to_roles(roles, @resource[:database]) - unless revoke.empty? - mongo_eval("db.getSiblingDB(#{@resource[:database].to_json}).revokeRolesFromUser(#{@resource[:username].to_json}, #{role_hashes(revoke, @resource[:database]).to_json})") - end + mongo_eval("db.getSiblingDB(#{@resource[:database].to_json}).revokeRolesFromUser(#{@resource[:username].to_json}, #{role_hashes(revoke, @resource[:database]).to_json})") unless revoke.empty? else Puppet.warning 'User roles operations are available only from master host' end diff --git a/lib/puppet/type/mongodb_conn_validator.rb b/lib/puppet/type/mongodb_conn_validator.rb index d21f2fe2c..5f9095610 100644 --- a/lib/puppet/type/mongodb_conn_validator.rb +++ b/lib/puppet/type/mongodb_conn_validator.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Puppet::Type.newtype(:mongodb_conn_validator) do @doc = "Verify that a connection can be successfully established between a node and the mongodb server. Its primary use is as a precondition to diff --git a/lib/puppet/type/mongodb_database.rb b/lib/puppet/type/mongodb_database.rb index f4ce99ac8..55b6a9cf4 100644 --- a/lib/puppet/type/mongodb_database.rb +++ b/lib/puppet/type/mongodb_database.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Puppet::Type.newtype(:mongodb_database) do @doc = 'Manage MongoDB databases.' diff --git a/lib/puppet/type/mongodb_replset.rb b/lib/puppet/type/mongodb_replset.rb index 728577b07..aa600b564 100644 --- a/lib/puppet/type/mongodb_replset.rb +++ b/lib/puppet/type/mongodb_replset.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # # Author: Francois Charlier # @@ -55,6 +57,7 @@ def insync?(is) should.each do |sm| next unless current.each_with_index do |cm, index| next unless sm['host'] == cm['host'] + sm.each do |k, v| if v != cm[k] # new config for existing node so not insync @@ -65,6 +68,7 @@ def insync?(is) current.delete_at(index) break end + # new node for cluster so not insync sync = false end diff --git a/lib/puppet/type/mongodb_shard.rb b/lib/puppet/type/mongodb_shard.rb index d1002686d..c1cba0e11 100644 --- a/lib/puppet/type/mongodb_shard.rb +++ b/lib/puppet/type/mongodb_shard.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # # Author: Emilien Macchi # diff --git a/lib/puppet/type/mongodb_user.rb b/lib/puppet/type/mongodb_user.rb index 03af4cea4..592075407 100644 --- a/lib/puppet/type/mongodb_user.rb +++ b/lib/puppet/type/mongodb_user.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require File.expand_path(File.join(File.dirname(__FILE__), '..', 'util', 'mongodb_md5er')) require File.expand_path(File.join(File.dirname(__FILE__), '..', 'util', 'mongodb_scram')) Puppet::Type.newtype(:mongodb_user) do @@ -55,9 +57,7 @@ def to_s?(value) newproperty(:password_hash) do desc 'The password hash of the user. Use mongodb_password() for creating hash. Only available on MongoDB 3.0 and later. SCRAM-SHA-256 authentication mechanism is not supported.' defaultto do - if @resource[:password].nil? - raise Puppet::Error, "Property 'password_hash' must be set. Use mongodb_password() for creating hash." if provider.database == :absent - end + raise Puppet::Error, "Property 'password_hash' must be set. Use mongodb_password() for creating hash." if @resource[:password].nil? && (provider.database == :absent) end newvalue(%r{^\w+$}) @@ -67,9 +67,7 @@ def insync?(is) if is == :absent && @resource.provider.scram_credentials scram = @resource.provider.scram_credentials scram_util = Puppet::Util::MongodbScram.new(should, scram['salt'], scram['iterationCount']) - if scram['storedKey'] == scram_util.stored_key && scram['serverKey'] == scram_util.server_key - is = should - end + is = should if scram['storedKey'] == scram_util.stored_key && scram['serverKey'] == scram_util.server_key end should == is end @@ -131,8 +129,6 @@ def insync?(_is) elsif !self[:password_hash].nil? && self[:auth_mechanism] == :scram_sha_256 err("'password_hash' is not supported with SCRAM-SHA-256 authentication mechanism") end - if should(:scram_credentials) - raise("The parameter 'scram_credentials' is read-only and cannot be changed") - end + raise("The parameter 'scram_credentials' is read-only and cannot be changed") if should(:scram_credentials) end end diff --git a/lib/puppet/util/mongodb_md5er.rb b/lib/puppet/util/mongodb_md5er.rb index 48730a193..5f641ea82 100644 --- a/lib/puppet/util/mongodb_md5er.rb +++ b/lib/puppet/util/mongodb_md5er.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'digest/md5' module Puppet diff --git a/lib/puppet/util/mongodb_output.rb b/lib/puppet/util/mongodb_output.rb index da5ddbb68..b6f26cbf2 100644 --- a/lib/puppet/util/mongodb_output.rb +++ b/lib/puppet/util/mongodb_output.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Puppet module Util module MongodbOutput @@ -6,8 +8,8 @@ def self.sanitize(data) data.gsub!(%r{\w+\((\d+).+?\)}, '\1') # Remove extra parameters from 'Timestamp(1462971623, 1)' Objects data.gsub!(%r{\w+\((.+?)\)}, '\1') - data.gsub!(%r{^Error\:.+}, '') - data.gsub!(%r{^.*warning\:.+}, '') # remove warnings if sslAllowInvalidHostnames is true + data.gsub!(%r{^Error:.+}, '') + data.gsub!(%r{^.*warning:.+}, '') # remove warnings if sslAllowInvalidHostnames is true data.gsub!(%r{^.*The server certificate does not match the host name.+}, '') # remove warnings if sslAllowInvalidHostnames is true mongo 3.x data end diff --git a/lib/puppet/util/mongodb_scram.rb b/lib/puppet/util/mongodb_scram.rb index 694b8d7bd..ebcd06c56 100644 --- a/lib/puppet/util/mongodb_scram.rb +++ b/lib/puppet/util/mongodb_scram.rb @@ -1,15 +1,15 @@ +# frozen_string_literal: true + require 'securerandom' require 'base64' module Puppet module Util class MongodbScram - CLIENT_KEY = 'Client Key'.freeze - SERVER_KEY = 'Server Key'.freeze + CLIENT_KEY = 'Client Key' + SERVER_KEY = 'Server Key' - attr_reader :password_hash - attr_reader :salt - attr_reader :iterations + attr_reader :password_hash, :salt, :iterations def initialize(password_hash, salt, iterations) @password_hash = password_hash @@ -18,7 +18,7 @@ def initialize(password_hash, salt, iterations) end def digest - @digest ||= OpenSSL::Digest::SHA1.new.freeze + @digest ||= OpenSSL::Digest.new('SHA1').freeze end def hash(string) diff --git a/lib/puppet/util/mongodb_validator.rb b/lib/puppet/util/mongodb_validator.rb index 35caf83f1..3c8e7a3a8 100644 --- a/lib/puppet/util/mongodb_validator.rb +++ b/lib/puppet/util/mongodb_validator.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'socket' require 'timeout' require 'ipaddr' @@ -6,11 +8,10 @@ module Puppet module Util class MongodbValidator - attr_reader :mongodb_server - attr_reader :mongodb_port + attr_reader :mongodb_server, :mongodb_port def initialize(mongodb_resource_name, mongodb_server, mongodb_port) - # NOTE (spredzy) : By relying on the uri module + # NOTE: (spredzy) : By relying on the uri module # we rely on its well tested interface to parse # both IPv4 and IPv6 based URL with a port specified. # Unfortunately URI needs a scheme, hence the http @@ -18,7 +19,7 @@ def initialize(mongodb_resource_name, mongodb_server, mongodb_port) uri = URI("http://#{mongodb_resource_name}") @mongodb_server = IPAddr.new(uri.host).to_s @mongodb_port = uri.port - rescue + rescue StandardError @mongodb_server = mongodb_server.to_s @mongodb_port = mongodb_port end @@ -30,13 +31,11 @@ def initialize(mongodb_resource_name, mongodb_server, mongodb_port) # @return true if the connection is successful, false otherwise. def attempt_connection Timeout.timeout(Puppet[:http_connect_timeout]) do - begin - TCPSocket.new(@mongodb_server, @mongodb_port).close - true - rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH => e - Puppet.debug "Unable to connect to mongodb server (#{@mongodb_server}:#{@mongodb_port}): #{e.message}" - false - end + TCPSocket.new(@mongodb_server, @mongodb_port).close + true + rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH => e + Puppet.debug "Unable to connect to mongodb server (#{@mongodb_server}:#{@mongodb_port}): #{e.message}" + false end rescue Timeout::Error false diff --git a/spec/acceptance/database_spec.rb b/spec/acceptance/database_spec.rb index 269a8f8a4..100c21892 100644 --- a/spec/acceptance/database_spec.rb +++ b/spec/acceptance/database_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper_acceptance' describe 'mongodb_database' do @@ -19,6 +21,7 @@ class { 'mongodb::server': } apply_manifest(pp, catch_failures: true) apply_manifest(pp, catch_changes: true) end + it 'creates the databases' do shell("mongo testdb1 --eval 'printjson(db.getMongo().getDBs())'") shell("mongo testdb2 --eval 'printjson(db.getMongo().getDBs())'") @@ -45,6 +48,7 @@ class { 'mongodb::server': apply_manifest(pp, catch_failures: true) apply_manifest(pp, catch_changes: true) end + it 'creates the database' do shell("mongo testdb1 --port 27018 --eval 'printjson(db.getMongo().getDBs())'") shell("mongo testdb2 --port 27018 --eval 'printjson(db.getMongo().getDBs())'") diff --git a/spec/acceptance/mongos_spec.rb b/spec/acceptance/mongos_spec.rb index cb17200dc..eefcafd83 100644 --- a/spec/acceptance/mongos_spec.rb +++ b/spec/acceptance/mongos_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper_acceptance' describe 'mongodb::mongos class' do diff --git a/spec/acceptance/replset_spec.rb b/spec/acceptance/replset_spec.rb index f47b218f4..97f9c9bc9 100644 --- a/spec/acceptance/replset_spec.rb +++ b/spec/acceptance/replset_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper_acceptance' if hosts.length > 1 @@ -38,6 +40,7 @@ class { 'mongodb::client': } apply_manifest_on(hosts.reverse, pp, catch_failures: true) apply_manifest_on(hosts.reverse, pp, catch_changes: true) end + it 'sets up the replset with puppet' do pp = <<-EOS mongodb_replset { 'test': @@ -50,7 +53,6 @@ class { 'mongodb::client': } expect(r.stdout).to match %r{#{hosts[1]}:27017} end end - # rubocop:enable RSpec/MultipleExpectations it 'inserts data on the master' do sleep(30) @@ -94,83 +96,84 @@ class { 'mongodb::client': end it 'configures mongo on both nodes' do - pp = <<-EOS - class { 'mongodb::globals': - version => '2.6.9-1', - manage_package_repo => true - } -> - class { 'mongodb::server': - admin_username => 'admin', - admin_password => 'password', - auth => true, - bind_ip => '0.0.0.0', - replset => 'test', - keyfile => '/var/lib/mongodb/mongodb-keyfile', - key => '+dxlTrury7xtD0FRqFf3YWGnKqWAtlyauuemxuYuyz9POPUuX1Uj3chGU8MFMHa7 -UxASqex7NLMALQXHL+Th4T3dyb6kMZD7KiMcJObO4M+JLiX9drcTiifsDEgGMi7G -vYn3pWSm5TTDrHJw7RNWfMHw3sHk0muGQcO+0dWv3sDJ6SiU8yOKRtYcTEA15GbP -ReDZuHFy1T1qhk5NIt6pTtPGsZKSm2wAWIOa2f2IXvpeQHhjxP8aDFb3fQaCAqOD -R7hrimqq0Nickfe8RLA89iPXyadr/YeNBB7w7rySatQBzwIbBUVGNNA5cxCkwyx9 -E5of3xi7GL9xNxhQ8l0JEpofd4H0y0TOfFDIEjc7cOnYlKAHzBgog4OcFSILgUaF -kHuTMtv0pj+MMkW2HkeXETNII9XE1+JiZgHY08G7yFEJy87ttUoeKmpbI6spFz5U -4K0amj+N6SOwXaS8uwp6kCqay0ERJLnw+7dKNKZIZdGCrrBxcZ7wmR/wLYrxvHhZ -QpeXTxgD5ebwCR0cf3Xnb5ql5G/HHKZDq8LTFHwELNh23URGPY7K7uK+IF6jSEhq -V2H3HnWV9teuuJ5he9BB/pLnyfjft6KUUqE9HbaGlX0f3YBk/0T3S2ESN4jnfRTQ -ysAKvQ6NasXkzqXktu8X4fS5QNqrFyqKBZSWxttfJBKXnT0TxamCKLRx4AgQglYo -3KRoyfxXx6G+AjP1frDJxFAFEIgEFqRk/FFuT/y9LpU+3cXYX1Gt6wEatgmnBM3K -g+Bybk5qHv1b7M8Tv9/I/BRXcpLHeIkMICMY8sVPGmP8xzL1L3i0cws8p5h0zPBa -YG/QX0BmltAni8owgymFuyJgvr/gaRX4WHbKFD+9nKpqJ3ocuVNuCDsxDqLsJEME -nc1ohyB0lNt8lHf1U00mtgDSV3fwo5LkwhRi6d+bDBTL/C6MZETMLdyCqDlTdUWG -YXIsJ0gYcu9XG3mx10LbdPJvxSMg' - - } - if $::osfamily == 'RedHat' { - include mongodb::client - } + pp = <<~EOS + class { 'mongodb::globals': + version => '2.6.9-1', + manage_package_repo => true + } -> + class { 'mongodb::server': + admin_username => 'admin', + admin_password => 'password', + auth => true, + bind_ip => '0.0.0.0', + replset => 'test', + keyfile => '/var/lib/mongodb/mongodb-keyfile', + key => '+dxlTrury7xtD0FRqFf3YWGnKqWAtlyauuemxuYuyz9POPUuX1Uj3chGU8MFMHa7 + UxASqex7NLMALQXHL+Th4T3dyb6kMZD7KiMcJObO4M+JLiX9drcTiifsDEgGMi7G + vYn3pWSm5TTDrHJw7RNWfMHw3sHk0muGQcO+0dWv3sDJ6SiU8yOKRtYcTEA15GbP + ReDZuHFy1T1qhk5NIt6pTtPGsZKSm2wAWIOa2f2IXvpeQHhjxP8aDFb3fQaCAqOD + R7hrimqq0Nickfe8RLA89iPXyadr/YeNBB7w7rySatQBzwIbBUVGNNA5cxCkwyx9 + E5of3xi7GL9xNxhQ8l0JEpofd4H0y0TOfFDIEjc7cOnYlKAHzBgog4OcFSILgUaF + kHuTMtv0pj+MMkW2HkeXETNII9XE1+JiZgHY08G7yFEJy87ttUoeKmpbI6spFz5U + 4K0amj+N6SOwXaS8uwp6kCqay0ERJLnw+7dKNKZIZdGCrrBxcZ7wmR/wLYrxvHhZ + QpeXTxgD5ebwCR0cf3Xnb5ql5G/HHKZDq8LTFHwELNh23URGPY7K7uK+IF6jSEhq + V2H3HnWV9teuuJ5he9BB/pLnyfjft6KUUqE9HbaGlX0f3YBk/0T3S2ESN4jnfRTQ + ysAKvQ6NasXkzqXktu8X4fS5QNqrFyqKBZSWxttfJBKXnT0TxamCKLRx4AgQglYo + 3KRoyfxXx6G+AjP1frDJxFAFEIgEFqRk/FFuT/y9LpU+3cXYX1Gt6wEatgmnBM3K + g+Bybk5qHv1b7M8Tv9/I/BRXcpLHeIkMICMY8sVPGmP8xzL1L3i0cws8p5h0zPBa + YG/QX0BmltAni8owgymFuyJgvr/gaRX4WHbKFD+9nKpqJ3ocuVNuCDsxDqLsJEME + nc1ohyB0lNt8lHf1U00mtgDSV3fwo5LkwhRi6d+bDBTL/C6MZETMLdyCqDlTdUWG + YXIsJ0gYcu9XG3mx10LbdPJvxSMg' + + } + if $::osfamily == 'RedHat' { + include mongodb::client + } EOS apply_manifest_on(hosts.reverse, pp, catch_failures: true) apply_manifest_on(hosts.reverse, pp, catch_changes: true) end + it 'sets up the replset with puppet' do - pp = <<-EOS - class { 'mongodb::globals': - version => '2.6.9-1', - manage_package_repo => true - } -> - class { 'mongodb::server': - create_admin => true, - admin_username => 'admin', - admin_password => 'password', - auth => true, - bind_ip => '0.0.0.0', - replset => 'test', - keyfile => '/var/lib/mongodb/mongodb-keyfile', - key => '+dxlTrury7xtD0FRqFf3YWGnKqWAtlyauuemxuYuyz9POPUuX1Uj3chGU8MFMHa7 -UxASqex7NLMALQXHL+Th4T3dyb6kMZD7KiMcJObO4M+JLiX9drcTiifsDEgGMi7G -vYn3pWSm5TTDrHJw7RNWfMHw3sHk0muGQcO+0dWv3sDJ6SiU8yOKRtYcTEA15GbP -ReDZuHFy1T1qhk5NIt6pTtPGsZKSm2wAWIOa2f2IXvpeQHhjxP8aDFb3fQaCAqOD -R7hrimqq0Nickfe8RLA89iPXyadr/YeNBB7w7rySatQBzwIbBUVGNNA5cxCkwyx9 -E5of3xi7GL9xNxhQ8l0JEpofd4H0y0TOfFDIEjc7cOnYlKAHzBgog4OcFSILgUaF -kHuTMtv0pj+MMkW2HkeXETNII9XE1+JiZgHY08G7yFEJy87ttUoeKmpbI6spFz5U -4K0amj+N6SOwXaS8uwp6kCqay0ERJLnw+7dKNKZIZdGCrrBxcZ7wmR/wLYrxvHhZ -QpeXTxgD5ebwCR0cf3Xnb5ql5G/HHKZDq8LTFHwELNh23URGPY7K7uK+IF6jSEhq -V2H3HnWV9teuuJ5he9BB/pLnyfjft6KUUqE9HbaGlX0f3YBk/0T3S2ESN4jnfRTQ -ysAKvQ6NasXkzqXktu8X4fS5QNqrFyqKBZSWxttfJBKXnT0TxamCKLRx4AgQglYo -3KRoyfxXx6G+AjP1frDJxFAFEIgEFqRk/FFuT/y9LpU+3cXYX1Gt6wEatgmnBM3K -g+Bybk5qHv1b7M8Tv9/I/BRXcpLHeIkMICMY8sVPGmP8xzL1L3i0cws8p5h0zPBa -YG/QX0BmltAni8owgymFuyJgvr/gaRX4WHbKFD+9nKpqJ3ocuVNuCDsxDqLsJEME -nc1ohyB0lNt8lHf1U00mtgDSV3fwo5LkwhRi6d+bDBTL/C6MZETMLdyCqDlTdUWG -YXIsJ0gYcu9XG3mx10LbdPJvxSMg' - } - if $::osfamily == 'RedHat' { - include mongodb::client - } - mongodb_replset { 'test': - auth_enabled => true, - members => [#{hosts.map { |x| "'#{x}:27017'" }.join(',')}], - before => Mongodb_user['admin'] - } + pp = <<~EOS + class { 'mongodb::globals': + version => '2.6.9-1', + manage_package_repo => true + } -> + class { 'mongodb::server': + create_admin => true, + admin_username => 'admin', + admin_password => 'password', + auth => true, + bind_ip => '0.0.0.0', + replset => 'test', + keyfile => '/var/lib/mongodb/mongodb-keyfile', + key => '+dxlTrury7xtD0FRqFf3YWGnKqWAtlyauuemxuYuyz9POPUuX1Uj3chGU8MFMHa7 + UxASqex7NLMALQXHL+Th4T3dyb6kMZD7KiMcJObO4M+JLiX9drcTiifsDEgGMi7G + vYn3pWSm5TTDrHJw7RNWfMHw3sHk0muGQcO+0dWv3sDJ6SiU8yOKRtYcTEA15GbP + ReDZuHFy1T1qhk5NIt6pTtPGsZKSm2wAWIOa2f2IXvpeQHhjxP8aDFb3fQaCAqOD + R7hrimqq0Nickfe8RLA89iPXyadr/YeNBB7w7rySatQBzwIbBUVGNNA5cxCkwyx9 + E5of3xi7GL9xNxhQ8l0JEpofd4H0y0TOfFDIEjc7cOnYlKAHzBgog4OcFSILgUaF + kHuTMtv0pj+MMkW2HkeXETNII9XE1+JiZgHY08G7yFEJy87ttUoeKmpbI6spFz5U + 4K0amj+N6SOwXaS8uwp6kCqay0ERJLnw+7dKNKZIZdGCrrBxcZ7wmR/wLYrxvHhZ + QpeXTxgD5ebwCR0cf3Xnb5ql5G/HHKZDq8LTFHwELNh23URGPY7K7uK+IF6jSEhq + V2H3HnWV9teuuJ5he9BB/pLnyfjft6KUUqE9HbaGlX0f3YBk/0T3S2ESN4jnfRTQ + ysAKvQ6NasXkzqXktu8X4fS5QNqrFyqKBZSWxttfJBKXnT0TxamCKLRx4AgQglYo + 3KRoyfxXx6G+AjP1frDJxFAFEIgEFqRk/FFuT/y9LpU+3cXYX1Gt6wEatgmnBM3K + g+Bybk5qHv1b7M8Tv9/I/BRXcpLHeIkMICMY8sVPGmP8xzL1L3i0cws8p5h0zPBa + YG/QX0BmltAni8owgymFuyJgvr/gaRX4WHbKFD+9nKpqJ3ocuVNuCDsxDqLsJEME + nc1ohyB0lNt8lHf1U00mtgDSV3fwo5LkwhRi6d+bDBTL/C6MZETMLdyCqDlTdUWG + YXIsJ0gYcu9XG3mx10LbdPJvxSMg' + } + if $::osfamily == 'RedHat' { + include mongodb::client + } + mongodb_replset { 'test': + auth_enabled => true, + members => [#{hosts.map { |x| "'#{x}:27017'" }.join(',')}], + before => Mongodb_user['admin'] + } EOS apply_manifest_on(hosts_as('master'), pp, catch_failures: true) apply_manifest_on(hosts_as('master'), pp, catch_changes: true) @@ -179,7 +182,6 @@ class { 'mongodb::server': expect(r.stdout).to match %r{#{hosts[1]}:27017} end end - # rubocop:enable RSpec/MultipleExpectations it 'inserts data on the master' do sleep(30) diff --git a/spec/acceptance/server_spec.rb b/spec/acceptance/server_spec.rb index 4c8f69bf2..560282853 100644 --- a/spec/acceptance/server_spec.rb +++ b/spec/acceptance/server_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper_acceptance' describe 'mongodb::server class' do diff --git a/spec/acceptance/sharding_spec.rb b/spec/acceptance/sharding_spec.rb index 4d9caa402..d659c1eb6 100644 --- a/spec/acceptance/sharding_spec.rb +++ b/spec/acceptance/sharding_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper_acceptance' if hosts.length > 1 @@ -21,6 +23,7 @@ class { 'mongodb::client': } apply_manifest_on(hosts_as('shard'), pp, catch_failures: true) apply_manifest_on(hosts_as('shard'), pp, catch_changes: true) end + it 'configures the router server' do pp = <<-EOS class { 'mongodb::globals': } @@ -44,7 +47,7 @@ class { 'mongodb::client': } apply_manifest_on(hosts_as('router'), pp, catch_failures: true) on(hosts_as('router'), 'mongo --quiet --eval "printjson(sh.status())"') do |r| - expect(r.stdout).to match %r{foo\/shard:27018} + expect(r.stdout).to match %r{foo/shard:27018} expect(r.stdout).to match %r{foo\.toto} end end diff --git a/spec/acceptance/user_spec.rb b/spec/acceptance/user_spec.rb index 356e7fbcf..ee119561f 100644 --- a/spec/acceptance/user_spec.rb +++ b/spec/acceptance/user_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper_acceptance' describe 'mongodb_database' do diff --git a/spec/classes/client_spec.rb b/spec/classes/client_spec.rb index 48f49defe..b97a517d6 100644 --- a/spec/classes/client_spec.rb +++ b/spec/classes/client_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'mongodb::client' do @@ -7,6 +9,7 @@ context 'with defaults' do it { is_expected.to compile.with_all_deps } + if facts[:os]['release']['major'] =~ %r{(10)} it { is_expected.to create_package('mongodb_client').with_ensure('4.4.8') } else @@ -20,6 +23,7 @@ end it { is_expected.to compile.with_all_deps } + if facts[:os]['release']['major'] =~ %r{(10)} it { is_expected.to create_package('mongodb_client').with_ensure('4.4.8').with_name('mongodb-org-shell').with_tag('mongodb_package') } else diff --git a/spec/classes/globals_spec.rb b/spec/classes/globals_spec.rb index 23e45f229..2b5ffed6b 100644 --- a/spec/classes/globals_spec.rb +++ b/spec/classes/globals_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'mongodb::globals' do diff --git a/spec/classes/mongos_spec.rb b/spec/classes/mongos_spec.rb index 3102fb4d9..bbccc8c85 100644 --- a/spec/classes/mongos_spec.rb +++ b/spec/classes/mongos_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'mongodb::mongos' do @@ -23,6 +25,7 @@ # install it { is_expected.to contain_class('mongodb::mongos::install') } + if facts[:os]['release']['major'] =~ %r{(10)} it { is_expected.to contain_package('mongodb_mongos').with_ensure('4.4.8').with_name(package_name).with_tag('mongodb_package') } else @@ -34,18 +37,18 @@ case facts[:osfamily] when 'RedHat', 'Suse' - expected_content = <<-CONFIG -configdb = 127.0.0.1:27019 -fork = true -pidfilepath = /var/run/mongodb/mongos.pid -logpath = /var/log/mongodb/mongos.log -unixSocketPrefix = /var/run/mongodb + expected_content = <<~CONFIG + configdb = 127.0.0.1:27019 + fork = true + pidfilepath = /var/run/mongodb/mongos.pid + logpath = /var/log/mongodb/mongos.log + unixSocketPrefix = /var/run/mongodb CONFIG it { is_expected.to contain_file('/etc/mongos.conf').with_content(expected_content) } when 'Debian' - expected_content = <<-CONFIG -configdb = 127.0.0.1:27019 + expected_content = <<~CONFIG + configdb = 127.0.0.1:27019 CONFIG it { is_expected.to contain_file('/etc/mongodb-shard.conf').with_content(expected_content) } @@ -76,7 +79,7 @@ } end - it { is_expected.to contain_file(config_file).with_content(%r{^bind_ip = 127\.0\.0\.1\,10\.1\.1\.13$}) } + it { is_expected.to contain_file(config_file).with_content(%r{^bind_ip = 127\.0\.0\.1,10\.1\.1\.13$}) } end context 'package_name => mongo-foo' do @@ -119,6 +122,7 @@ # install it { is_expected.to contain_class('mongodb::mongos::install') } + if facts[:osfamily] == 'Suse' it { is_expected.to contain_package('mongodb_mongos').with_ensure('absent') } else diff --git a/spec/classes/repo_spec.rb b/spec/classes/repo_spec.rb index fdbec0f2b..796014ac3 100644 --- a/spec/classes/repo_spec.rb +++ b/spec/classes/repo_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'mongodb::repo' do @@ -21,18 +23,21 @@ case facts[:osfamily] when 'RedHat' it { is_expected.to contain_class('mongodb::repo::yum') } + it do 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] when 'Debian' it do @@ -65,6 +70,7 @@ case facts[:osfamily] when 'RedHat' it { is_expected.to contain_class('mongodb::repo::yum') } + it do is_expected.to contain_yumrepo('mongodb'). with_enabled('1'). diff --git a/spec/classes/server_spec.rb b/spec/classes/server_spec.rb index 018a934eb..61cced4c1 100644 --- a/spec/classes/server_spec.rb +++ b/spec/classes/server_spec.rb @@ -1,16 +1,21 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'mongodb::server' do shared_examples 'server classes' do it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_class('mongodb::server::install'). that_comes_before('Class[mongodb::server::config]') } + it { is_expected.to contain_class('mongodb::server::config'). that_notifies('Class[mongodb::server::service]') } + it { is_expected.to contain_class('mongodb::server::service') } end @@ -99,6 +104,7 @@ readWriteAnyDatabase userAdminAnyDatabase clusterAdmin clusterManager clusterMonitor hostManager root restore]) end + it { is_expected.to contain_mongodb_database('admin').that_requires('Service[mongodb]') } end @@ -136,7 +142,7 @@ it do is_expected.to contain_file(config_file). - with_content(%r{^net\.bindIp: 127\.0\.0\.1\,fd00:beef:dead:55::143$}). + with_content(%r{^net\.bindIp: 127\.0\.0\.1,fd00:beef:dead:55::143$}). with_content(%r{^net\.ipv6: true$}) end end @@ -148,7 +154,7 @@ } end - it { is_expected.to contain_file(config_file).with_content(%r{^net\.bindIp: 127\.0\.0\.1\,10\.1\.1\.13$}) } + it { is_expected.to contain_file(config_file).with_content(%r{^net\.bindIp: 127\.0\.0\.1,10\.1\.1\.13$}) } end describe 'when specifying auth to true' do @@ -522,6 +528,7 @@ it { is_expected.to contain_file(config_file).with_content(%r{^net\.http\.enabled: false$}) } end + describe 'sets net.http.enabled to true when false' do let(:params) do { nohttpinterface: false } diff --git a/spec/defines/db_spec.rb b/spec/defines/db_spec.rb index 408f33d6c..fa4d32a1a 100644 --- a/spec/defines/db_spec.rb +++ b/spec/defines/db_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'mongodb::db' do diff --git a/spec/functions/mongodb_password_spec.rb b/spec/functions/mongodb_password_spec.rb index cab2a8e7b..729bac2fa 100644 --- a/spec/functions/mongodb_password_spec.rb +++ b/spec/functions/mongodb_password_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'mongodb_password' do diff --git a/spec/opsmanager_spec.rb b/spec/opsmanager_spec.rb index b94caebf6..4bb78aceb 100644 --- a/spec/opsmanager_spec.rb +++ b/spec/opsmanager_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'mongodb::opsmanager' do diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index 7db1a9959..7acf63019 100644 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'voxpupuli/acceptance/spec_helper_acceptance' configure_beaker do |host| diff --git a/spec/types/mongodb_database_spec.rb b/spec/types/mongodb_database_spec.rb index 1a6fc5273..c18cee768 100644 --- a/spec/types/mongodb_database_spec.rb +++ b/spec/types/mongodb_database_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'mongodb_database' do diff --git a/spec/unit/mongodb_version_spec.rb b/spec/unit/mongodb_version_spec.rb index 063b4c664..a7ede5d3d 100644 --- a/spec/unit/mongodb_version_spec.rb +++ b/spec/unit/mongodb_version_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Facter::Util::Fact do @@ -11,6 +13,7 @@ allow(Facter::Core::Execution).to receive(:which).with('mongo').and_return(true) allow(Facter::Core::Execution).to receive(:execute).with('mongo --version 2>&1').and_return('MongoDB shell version: 3.2.1') end + it { expect(Facter.fact(:mongodb_version).value).to eq('3.2.1') } diff --git a/spec/unit/puppet/provider/mongodb_database/mongodb_spec.rb b/spec/unit/puppet/provider/mongodb_database/mongodb_spec.rb index 332c78263..c783d6898 100644 --- a/spec/unit/puppet/provider/mongodb_database/mongodb_spec.rb +++ b/spec/unit/puppet/provider/mongodb_database/mongodb_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' require 'tempfile' diff --git a/spec/unit/puppet/provider/mongodb_replset/mongodb_spec.rb b/spec/unit/puppet/provider/mongodb_replset/mongodb_spec.rb index 83a10b09f..1a7872845 100644 --- a/spec/unit/puppet/provider/mongodb_replset/mongodb_spec.rb +++ b/spec/unit/puppet/provider/mongodb_replset/mongodb_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # # Authors: Emilien Macchi # Francois Charlier @@ -27,14 +29,14 @@ tmp = Tempfile.new('test') mongodconffile = tmp.path allow(provider.class).to receive(:mongod_conf_file).and_return(mongodconffile) - allow(provider.class).to receive(:mongo).and_return(< # diff --git a/spec/unit/puppet/type/mongodb_shard_spec.rb b/spec/unit/puppet/type/mongodb_shard_spec.rb index ffc41278f..9f760c946 100644 --- a/spec/unit/puppet/type/mongodb_shard_spec.rb +++ b/spec/unit/puppet/type/mongodb_shard_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'puppet' require 'puppet/type/mongodb_shard' diff --git a/spec/unit/puppet/type/mongodb_user_spec.rb b/spec/unit/puppet/type/mongodb_user_spec.rb index 1f57ea39e..e552590ed 100644 --- a/spec/unit/puppet/type/mongodb_user_spec.rb +++ b/spec/unit/puppet/type/mongodb_user_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'puppet' require 'puppet/type/mongodb_user' diff --git a/spec/unit/puppet/util/mongodb_output_spec.rb b/spec/unit/puppet/util/mongodb_output_spec.rb index 4eb222c48..37b5d737f 100644 --- a/spec/unit/puppet/util/mongodb_output_spec.rb +++ b/spec/unit/puppet/util/mongodb_output_spec.rb @@ -58,6 +58,7 @@ sanitized_json = described_class.sanitize(bson_data) expect { JSON.parse(sanitized_json) }.not_to raise_error end + it 'replaces data types' do sanitized_json = described_class.sanitize(bson_data) expect(JSON.parse(sanitized_json)).to include(JSON.parse(json_data)) From 5d74e6ae13ccb3ce2d93ba0dbeb25bbd309703d1 Mon Sep 17 00:00:00 2001 From: Steve Traylen Date: Thu, 25 May 2023 07:55:49 +0200 Subject: [PATCH 07/13] rubocop Style/FrozenStringLiteralComment --- spec/unit/puppet/util/mongodb_output_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/unit/puppet/util/mongodb_output_spec.rb b/spec/unit/puppet/util/mongodb_output_spec.rb index 37b5d737f..fb3a1219d 100644 --- a/spec/unit/puppet/util/mongodb_output_spec.rb +++ b/spec/unit/puppet/util/mongodb_output_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require 'spec_helper' # rubocop:todo Style/FrozenStringLiteralComment Frozen strings break the regex below require 'puppet/util/mongodb_output' require 'json' From 996c368353e793c3569caf44a7107b8f9b43d2b3 Mon Sep 17 00:00:00 2001 From: Steve Traylen Date: Thu, 25 May 2023 07:58:17 +0200 Subject: [PATCH 08/13] rubocop RSpec/VariableName --- spec/classes/server_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/classes/server_spec.rb b/spec/classes/server_spec.rb index 61cced4c1..e71e86eda 100644 --- a/spec/classes/server_spec.rb +++ b/spec/classes/server_spec.rb @@ -540,7 +540,7 @@ context 'when setting up replicasets' do describe 'should setup using replset_config' do - let(:rsConf) do + let(:rsConf) do # rubocop:disable RSpec/VariableName { 'rsTest' => { 'members' => [ @@ -564,7 +564,7 @@ end describe 'should setup using replset_members' do - let(:rsConf) do + let(:rsConf) do # rubocop:disable RSpec/VariableName { 'rsTest' => { 'ensure' => 'present', From 78f39f03ad8ba6b76d55f9c6357de9cba7276303 Mon Sep 17 00:00:00 2001 From: Steve Traylen Date: Thu, 25 May 2023 07:59:53 +0200 Subject: [PATCH 09/13] rubocop Lint/EmptyBlock --- spec/unit/puppet/provider/mongodb_shard/mongodb_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/unit/puppet/provider/mongodb_shard/mongodb_spec.rb b/spec/unit/puppet/provider/mongodb_shard/mongodb_spec.rb index 6c992fad7..fb9b6d617 100644 --- a/spec/unit/puppet/provider/mongodb_shard/mongodb_spec.rb +++ b/spec/unit/puppet/provider/mongodb_shard/mongodb_spec.rb @@ -67,7 +67,7 @@ end describe 'destroy' do - it 'removes a shard' do + it 'removes a shard' do # rubocop:disable Lint/EmptyBlock end end From b33599e017330776b51d29723ff0d56217e40e82 Mon Sep 17 00:00:00 2001 From: Steve Traylen Date: Thu, 25 May 2023 08:02:57 +0200 Subject: [PATCH 10/13] rubocop:disable RSpec/RepeatedExampleGroupBody --- spec/acceptance/mongos_spec.rb | 8 ++++---- spec/acceptance/server_spec.rb | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/spec/acceptance/mongos_spec.rb b/spec/acceptance/mongos_spec.rb index eefcafd83..e136155bf 100644 --- a/spec/acceptance/mongos_spec.rb +++ b/spec/acceptance/mongos_spec.rb @@ -48,11 +48,11 @@ class { 'mongodb::server': it { is_expected.to be_running } end - describe port(27_017) do + describe port(27_017) do # rubocop:disable RSpec/RepeatedExampleGroupBody it { is_expected.to be_listening } end - describe port(27_019) do + describe port(27_019) do # rubocop:disable RSpec/RepeatedExampleGroupBody it { is_expected.to be_listening } end @@ -90,11 +90,11 @@ class { 'mongodb::mongos': it { is_expected.not_to be_running } end - describe port(27_017) do + describe port(27_017) do # rubocop:disable RSpec/RepeatedExampleGroupBody it { is_expected.not_to be_listening } end - describe port(27_019) do + describe port(27_019) do # rubocop:disable RSpec/RepeatedExampleGroupBody it { is_expected.not_to be_listening } end end diff --git a/spec/acceptance/server_spec.rb b/spec/acceptance/server_spec.rb index 560282853..e889254d2 100644 --- a/spec/acceptance/server_spec.rb +++ b/spec/acceptance/server_spec.rb @@ -185,11 +185,11 @@ class { 'mongodb::server': it { is_expected.not_to be_running } end - describe port(27_017) do + describe port(27_017) do # rubocop:disable RSpec/RepeatedExampleGroupBody it { is_expected.not_to be_listening } end - describe port(27_018) do + describe port(27_018) do # rubocop:disable RSpec/RepeatedExampleGroupBody it { is_expected.not_to be_listening } end end From 578f4ad7db97d133d6cbc0e3c9d03c2f91a686ab Mon Sep 17 00:00:00 2001 From: Steve Traylen Date: Thu, 25 May 2023 08:06:32 +0200 Subject: [PATCH 11/13] rubocop:disable Naming/VariableNumber --- lib/puppet/provider/mongodb_user/mongodb.rb | 4 ++-- lib/puppet/type/mongodb_user.rb | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/puppet/provider/mongodb_user/mongodb.rb b/lib/puppet/provider/mongodb_user/mongodb.rb index 3b21a2ee0..27d3a5841 100644 --- a/lib/puppet/provider/mongodb_user/mongodb.rb +++ b/lib/puppet/provider/mongodb_user/mongodb.rb @@ -60,7 +60,7 @@ def create } if mongo_4? || mongo_5? - if @resource[:auth_mechanism] == :scram_sha_256 + if @resource[:auth_mechanism] == :scram_sha_256 # rubocop:disable Naming/VariableNumber command[:mechanisms] = ['SCRAM-SHA-256'] command[:pwd] = @resource[:password] command[:digestPassword] = true @@ -121,7 +121,7 @@ def password=(value) } if mongo_4? || mongo_5? - command[:mechanisms] = @resource[:auth_mechanism] == :scram_sha_256 ? ['SCRAM-SHA-256'] : ['SCRAM-SHA-1'] + command[:mechanisms] = @resource[:auth_mechanism] == :scram_sha_256 ? ['SCRAM-SHA-256'] : ['SCRAM-SHA-1'] # rubocop:disable Naming/VariableNumber end mongo_eval("db.runCommand(#{command.to_json})", @resource[:database]) diff --git a/lib/puppet/type/mongodb_user.rb b/lib/puppet/type/mongodb_user.rb index 592075407..c585e7002 100644 --- a/lib/puppet/type/mongodb_user.rb +++ b/lib/puppet/type/mongodb_user.rb @@ -88,7 +88,7 @@ def to_s?(_value = @is) end def insync?(_is) - return !@resource[:update_password] if @resource[:auth_mechanism] == :scram_sha_256 + return !@resource[:update_password] if @resource[:auth_mechanism] == :scram_sha_256 # rubocop:disable Naming/VariableNumber should_to_s == to_s? end @@ -96,8 +96,8 @@ def insync?(_is) newparam(:auth_mechanism) do desc 'Authentication mechanism. Password verification is not supported with SCRAM-SHA-256.' - defaultto :scram_sha_1 - newvalues(:scram_sha_256, :scram_sha_1) + defaultto :scram_sha_1 # rubocop:disable Naming/VariableNumber + newvalues(:scram_sha_256, :scram_sha_1) # rubocop:disable Naming/VariableNumber end newparam(:update_password, boolean: true) do @@ -126,7 +126,7 @@ def insync?(_is) err("Either 'password_hash' or 'password' should be provided") elsif !self[:password_hash].nil? && !self[:password].nil? err("Only one of 'password_hash' or 'password' should be provided") - elsif !self[:password_hash].nil? && self[:auth_mechanism] == :scram_sha_256 + elsif !self[:password_hash].nil? && self[:auth_mechanism] == :scram_sha_256 # rubocop:disable Naming/VariableNumber err("'password_hash' is not supported with SCRAM-SHA-256 authentication mechanism") end raise("The parameter 'scram_credentials' is read-only and cannot be changed") if should(:scram_credentials) From a009be17396ae48459991a607d0fb80b2b7c2ee6 Mon Sep 17 00:00:00 2001 From: Steve Traylen Date: Thu, 25 May 2023 08:07:17 +0200 Subject: [PATCH 12/13] rubocop:disable Lint/DuplicateBranch --- lib/puppet/provider/mongodb.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/puppet/provider/mongodb.rb b/lib/puppet/provider/mongodb.rb index 4e9554426..2921514a9 100644 --- a/lib/puppet/provider/mongodb.rb +++ b/lib/puppet/provider/mongodb.rb @@ -112,7 +112,7 @@ def self.conn_string ip_real = case first_ip_in_list when '0.0.0.0' Facter.value(:fqdn) - when %r{\[?::0\]?} + when %r{\[?::0\]?} # rubocop:disable Lint/DuplicateBranch Facter.value(:fqdn) else first_ip_in_list From 67f9eb6916aa0be63cdfb68ee5b04e82f64f7d04 Mon Sep 17 00:00:00 2001 From: Steve Traylen Date: Thu, 25 May 2023 08:08:03 +0200 Subject: [PATCH 13/13] rubocop:disable Lint/SelfAssignment --- lib/puppet/provider/mongodb_replset/mongo.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/puppet/provider/mongodb_replset/mongo.rb b/lib/puppet/provider/mongodb_replset/mongo.rb index 57f01511a..a12484bc5 100644 --- a/lib/puppet/provider/mongodb_replset/mongo.rb +++ b/lib/puppet/provider/mongodb_replset/mongo.rb @@ -130,7 +130,7 @@ def master_host(members) end def self.replset_properties - conn_string = conn_string + conn_string = conn_string # rubocop:disable Lint/SelfAssignment begin output = mongo_command('rs.conf()', conn_string) rescue Puppet::ExecutionFailure