diff --git a/lib/facter/is_master.rb b/lib/facter/is_master.rb index 1e406f28a..40ce49e59 100644 --- a/lib/facter/is_master.rb +++ b/lib/facter/is_master.rb @@ -32,43 +32,9 @@ def get_options_from_hash_config(config) result.join(' ') end -def get_options_from_keyvalue_config(file) - config = {} - File.readlines(file).map do |line| - k, v = line.split('=') - config[k.rstrip] = v.lstrip.chomp if k && v - end - - result = [] - - result << "--port #{config['port']}" unless config['port'].nil? - # use --ssl and --host if: - # - sslMode is "requireSSL" - # - Parameter --sslPEMKeyFile is set - # - Parameter --sslCAFile is set - result << "--ssl --host #{Facter.value(:fqdn)}" if config['ssl'] == 'requireSSL' || !config['sslcert'].nil? || !config['sslca'].nil? - result << "--sslPEMKeyFile #{config['sslcert']}" unless config['sslcert'].nil? - result << "--sslCAFile #{config['sslca']}" unless config['sslca'].nil? - # use --tls and --host if: - # - tlsMode is "requireTLS" - # - Parameter --tlsCertificateKeyFile is set - # - Parameter --tlsCAFile is set - result << "--tls --host #{Facter.value(:fqdn)}" if config['tls'] == 'requireTLS' || !config['tlscert'].nil? || !config['tlsca'].nil? - result << "--tlsCertificateKeyFile #{config['tlscert']}" unless config['tlscert'].nil? - result << "--tlsCAFile #{config['tlsca']}" unless config['tlsca'].nil? - - result << '--ipv6' unless config['ipv6'].nil? - - result.join(' ') -end - def get_options_from_config(file) config = YAML.load_file(file) - if config.is_a?(Hash) # Using a valid YAML file for mongo 2.6 - get_options_from_hash_config(config) - else # It has to be a key-value config file - get_options_from_keyvalue_config(file) - end + get_options_from_hash_config(config) end Facter.add('mongodb_is_master') do diff --git a/lib/puppet/provider/mongodb.rb b/lib/puppet/provider/mongodb.rb index d032aa26b..c5944ac6c 100644 --- a/lib/puppet/provider/mongodb.rb +++ b/lib/puppet/provider/mongodb.rb @@ -191,22 +191,4 @@ def self.mongo_version def mongo_version self.class.mongo_version end - - def self.mongo_4? - v = mongo_version - !v[%r{^4\.}].nil? - end - - def mongo_4? - self.class.mongo_4? - end - - def self.mongo_5? - v = mongo_version - !v[%r{^5\.}].nil? - end - - def mongo_5? - self.class.mongo_5? - end end diff --git a/lib/puppet/provider/mongodb_replset/mongo.rb b/lib/puppet/provider/mongodb_replset/mongo.rb index 57f01511a..7837533e2 100644 --- a/lib/puppet/provider/mongodb_replset/mongo.rb +++ b/lib/puppet/provider/mongodb_replset/mongo.rb @@ -280,7 +280,7 @@ def set_members Puppet.debug 'Replica set initialization has successfully ended' return true else - Puppet.debug "Wainting for replica initialization. Retry: #{n}" + Puppet.debug "Waiting for replica initialization. Retry: #{n}" sleep retry_sleep next end diff --git a/spec/unit/puppet/provider/mongodb_spec.rb b/spec/unit/puppet/provider/mongodb_spec.rb index 2145af3f8..0de3c1661 100644 --- a/spec/unit/puppet/provider/mongodb_spec.rb +++ b/spec/unit/puppet/provider/mongodb_spec.rb @@ -13,17 +13,15 @@ end describe 'mongo version detection' do - v = { - '4.x.x' => { '26' => false, '4' => true, '5' => false }, - '5.x.x' => { '26' => false, '4' => false, '5' => true }, - 'x.x.x' => { '26' => false, '4' => false, '5' => false } - } + v = [ + '4.x.x', + '5.x.x', + 'x.x.x' + ] - v.each do |key, results| + v.each do |key| it "version detection for [#{key}]" do allow(provider_class).to receive(:mongo_eval).with('db.version()').and_return(key) - expect(provider_class.mongo_4?).to be results['4'] - expect(provider_class.mongo_5?).to be results['5'] end end end