Skip to content

Commit 76f5dc4

Browse files
author
Johan De Wit
committed
[Provider] Use mongosh
1 parent f1e5f02 commit 76f5dc4

File tree

2 files changed

+22
-22
lines changed

2 files changed

+22
-22
lines changed

lib/puppet/provider/mongodb.rb

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
class Puppet::Provider::Mongodb < Puppet::Provider
99
# Without initvars commands won't work.
1010
initvars
11-
commands mongo: 'mongo'
11+
commands mongosh: 'mongosh'
1212

1313
# Optional defaults file
14-
def self.mongorc_file
15-
"load('#{Facter.value(:root_home)}/.mongorc.js'); " if File.file?("#{Facter.value(:root_home)}/.mongorc.js")
14+
def self.mongoshrc_file
15+
"load('#{Facter.value(:root_home)}/.mongoshrc.js'); " if File.file?("#{Facter.value(:root_home)}/.mongoshrc.js")
1616
end
1717

18-
def mongorc_file
19-
self.class.mongorc_file
18+
def mongoshrc_file
19+
self.class.mongoshrc_file
2020
end
2121

2222
def self.mongod_conf_file
@@ -74,7 +74,7 @@ def self.tls_invalid_hostnames(config = nil)
7474
config['tlsallowInvalidHostnames']
7575
end
7676

77-
def self.mongo_cmd(db, host, cmd)
77+
def self.mongosh_cmd(db, host, cmd)
7878
config = mongo_conf
7979

8080
args = [db, '--quiet', '--host', host]
@@ -101,7 +101,7 @@ def self.mongo_cmd(db, host, cmd)
101101
end
102102

103103
args += ['--eval', cmd]
104-
mongo(args)
104+
mongosh(args)
105105
end
106106

107107
def self.conn_string
@@ -137,9 +137,9 @@ def self.conn_string
137137

138138
def self.db_ismaster
139139
cmd_ismaster = 'db.isMaster().ismaster'
140-
cmd_ismaster = mongorc_file + cmd_ismaster if mongorc_file
140+
cmd_ismaster = mongoshrc_file + cmd_ismaster if mongoshrc_file
141141
db = 'admin'
142-
res = mongo_cmd(db, conn_string, cmd_ismaster).to_s.split(%r{\n}).last.chomp
142+
res = mongosh_cmd(db, conn_string, cmd_ismaster).to_s.split(%r{\n}).last.chomp
143143
res.eql?('true')
144144
end
145145

@@ -156,14 +156,14 @@ def self.auth_enabled(config = nil)
156156
def self.mongo_eval(cmd, db = 'admin', retries = 10, host = nil)
157157
retry_count = retries
158158
retry_sleep = 3
159-
cmd = mongorc_file + cmd if mongorc_file
159+
cmd = mongoshrc_file + cmd if mongoshrc_file
160160

161161
out = nil
162162
begin
163163
out = if host
164-
mongo_cmd(db, host, cmd)
164+
mongosh_cmd(db, host, cmd)
165165
else
166-
mongo_cmd(db, conn_string, cmd)
166+
mongosh_cmd(db, conn_string, cmd)
167167
end
168168
rescue StandardError => e
169169
retry_count -= 1
@@ -192,15 +192,6 @@ def mongo_version
192192
self.class.mongo_version
193193
end
194194

195-
def self.mongo_26?
196-
v = mongo_version
197-
!v[%r{^2\.6\.}].nil?
198-
end
199-
200-
def mongo_26?
201-
self.class.mongo_26?
202-
end
203-
204195
def self.mongo_4?
205196
v = mongo_version
206197
!v[%r{^4\.}].nil?
@@ -218,4 +209,13 @@ def self.mongo_5?
218209
def mongo_5?
219210
self.class.mongo_5?
220211
end
212+
213+
def self.mongo_6?
214+
v = mongo_version
215+
!v[%r{^6\.}].nil?
216+
end
217+
218+
def mongo_6?
219+
self.class.mongo_6?
220+
end
221221
end

lib/puppet/provider/mongodb_shard/mongo.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def self.mongo_command(command, host = nil, _retries = 4)
153153
args << '--quiet'
154154
args << ['--host', host] if host
155155
args << ['--eval', "printjson(#{command})"]
156-
output = mongo(args.flatten)
156+
output = mongosh(args.flatten)
157157
rescue Puppet::ExecutionFailure => e
158158
raise unless e =~ %r{Error: couldn't connect to server} && wait <= (2**max_wait)
159159

0 commit comments

Comments
 (0)