You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Needed changes:
- Use stderr for errors instead of stdout. The `mongo` command from
the older client package put its errors on stout and exited with
zero as exit code. Mongosh, by contrast, puts errors on stderr
instead of stdout and exits with a non-zero exit code.
This means we need to pass the underlying exception to the caller so
it can deal with it appropriately.
- Replace old functions:
- `printjson` has become `EJSON.stringify`.
- `rs.secondaryOk()` and `rs.slaveOk()` have become
`db.getMongo().setReadPref("primaryPreferred")`.
- `db` is now an object instead of the database name, we need to call
`getName()` on it to get the database name.
- Don't throw an exception from the `if (authRequired()) {` block, as
that causes the `mongosh` command to stop processing further
commands and exit with a non-zero exit code.
Puppet.debug "Checking replicaset member #{host} ..."
156
-
status = rs_status(host)
157
-
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'
Puppet.warning "Host #{host} is available, but you are unauthorized because of authentication is enabled: #{auth_enabled}"
161
-
alive.push(member)
162
-
end
163
-
164
-
if status.key?('errmsg') && status['errmsg'].include?('no replset config has been received')
165
-
Puppet.debug 'Mongo v4 rs.status() RS not initialized output'
166
-
alive.push(member)
167
-
end
168
-
169
-
if status.key?('set')
170
-
raise Puppet::Error, "Can't configure replicaset #{name}, host #{host} is already part of another replicaset." if status['set'] != name
171
-
172
-
# This node is alive and supposed to be a member of our set
173
-
Puppet.debug "Host #{host} is available for replset #{status['set']}"
174
-
alive.push(member)
175
-
elsif status.key?('info')
176
-
Puppet.debug "Host #{host} is alive but unconfigured: #{status['info']}"
177
-
alive.push(member)
156
+
begin
157
+
status = rs_status(host)
158
+
159
+
if status.key?('set')
160
+
raise Puppet::Error, "Can't configure replicaset #{name}, host #{host} is already part of another replicaset." if status['set'] != name
161
+
162
+
# This node is alive and supposed to be a member of our set
163
+
Puppet.debug "Host #{host} is available for replset #{status['set']}"
164
+
alive.push(member)
165
+
elsif status.key?('info')
166
+
Puppet.debug "Host #{host} is alive but unconfigured: #{status['info']}"
167
+
alive.push(member)
168
+
end
169
+
rescue Puppet::ExecutionFailure => e
170
+
raise Puppet::Error, "Can't configure replicaset #{name}, host #{host} is not supposed to be part of a replicaset." if e.message =~ %r{not running with --replSet}
171
+
172
+
if auth_enabled && (e.message.include?('unauthorized') || e.message.include?('not authorized') || e.message.include?('requires authentication'))
173
+
Puppet.warning "Host #{host} is available, but you are unauthorized because of authentication is enabled: #{auth_enabled}"
174
+
alive.push(member)
175
+
elsif e.message.include?('no replset config has been received')
176
+
Puppet.debug 'Mongo v4 rs.status() RS not initialized output'
177
+
alive.push(member)
178
+
else
179
+
Puppet.warning "Can't connect to replicaset member #{host}."
180
+
end
178
181
end
179
-
rescue Puppet::ExecutionFailure
180
-
Puppet.warning "Can't connect to replicaset member #{host}."
0 commit comments