Skip to content

Commit

Permalink
added support for mongo 5.x
Browse files Browse the repository at this point in the history
  • Loading branch information
Michiel Brandenburg committed Sep 30, 2021
1 parent 984ba47 commit 4f02462
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
9 changes: 9 additions & 0 deletions lib/puppet/provider/mongodb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,13 @@ def self.mongo_4?
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_user/mongodb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def create
digestPassword: false
}

if mongo_4?
if mongo_4? || mongo_5?
# SCRAM-SHA-256 requires digestPassword to be true.
command[:mechanisms] = ['SCRAM-SHA-1']
end
Expand Down
1 change: 1 addition & 0 deletions manifests/repo.pp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
default => undef
}
$key = "${mongover[0]}.${mongover[1]}" ? {
'5.0' => 'F5679A222C647C87527C2F8CB00A0BD1E2C63C11',
'4.4' => '20691EEC35216C63CAF66CE1656408E390CFB1F5',
'4.2' => 'E162F504A20CDF15827F718D4B7C549A058F8B6B',
'4.0' => '9DA31620334BD75D9DCB49F368818C72E52529D4',
Expand Down
29 changes: 29 additions & 0 deletions spec/unit/puppet/provider/mongodb_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require 'spec_helper'

require 'puppet/provider/mongodb'

provider_class = Puppet::Provider::Mongodb
describe provider_class do
before do
# Clear the cached version before each test
provider_class.remove_instance_variable(:@mongo_version) \
if provider_class.instance_variable_defined?(:@mongo_version)
end

describe 'mongo version detection' do
v = [
{ :return => '2.6.x', :result => { '26' => true, '4' => false, '5' => false } },
{ :return => '4.x.x', :result => { '26' => false, '4' => true, '5' => false } },
{ :return => '5.x.x', :result => { '26' => false, '4' => false, '5' => true } },
{ :return => 'x.x.x', :result => { '26' => false, '4' => false, '5' => false } }
]
v.each do |version|
it "version detection #{version[:return]}" do
allow(provider_class).to receive(:mongo_eval).with('db.version()').and_return(version[:return])
expect(provider_class.mongo_26?).to be version[:result]['26']
expect(provider_class.mongo_4?).to be version[:result]['4']
expect(provider_class.mongo_5?).to be version[:result]['5']
end
end
end
end

0 comments on commit 4f02462

Please sign in to comment.