Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provider cleanup part2 #706

Merged
merged 3 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 1 addition & 35 deletions lib/facter/is_master.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
stevenpost marked this conversation as resolved.
Show resolved Hide resolved
end

Facter.add('mongodb_is_master') do
Expand Down
18 changes: 0 additions & 18 deletions lib/puppet/provider/mongodb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion lib/puppet/provider/mongodb_replset/mongo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 6 additions & 8 deletions spec/unit/puppet/provider/mongodb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down