Skip to content

Commit 0ef6b99

Browse files
author
Johan De Wit
committed
[TEMP] debug
1 parent cda4f6d commit 0ef6b99

File tree

2 files changed

+54
-38
lines changed

2 files changed

+54
-38
lines changed

lib/puppet/provider/mongodb_replset/mongo.rb

Lines changed: 53 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ def master_host(members)
130130
end
131131

132132
def self.replset_properties
133+
Puppet.debug('XXXXXXXXX in replset_properties')
133134
conn_string = conn_string # rubocop:disable Lint/SelfAssignment
134135
begin
135136
output = mongo_command('rs.conf()', conn_string)
@@ -144,7 +145,9 @@ def self.replset_properties
144145
end
145146
nil
146147
rescue Puppet::ExecutionFailure => e
148+
#if e.message =~ %r{command replSetGetConfig requires authentication} || e.message =~ %r{not authorized on admin to execute command} || e.message =~ %r{no replset config has been received}
147149
if e.message =~ %r{command replSetGetConfig requires authentication} || e.message =~ %r{not authorized on admin to execute command}
150+
Puppet.debug('XXXXXXXXX in replset_properties rescue part')
148151
output = mongo_command('rs.status()', conn_string)
149152
if output['members']
150153
memb = []
@@ -168,36 +171,48 @@ def get_hosts_status(members)
168171
members.select do |member|
169172
host = member['host']
170173
Puppet.debug "Checking replicaset member #{host} ..."
171-
status = rs_status(host)
172-
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'
173-
174-
if auth_enabled && status.key?('errmsg') && (status['errmsg'].include?('requires authentication') || status['errmsg'].include?('not authorized on admin') || status['errmsg'].include?('Authentication failed'))
175-
Puppet.warning "Host #{host} is available, but you are unauthorized because of authentication is enabled: #{auth_enabled}"
176-
alive.push(member)
177-
end
178-
179-
# TODO: check here how to get at this place ...
180-
if status.key?('errmsg') && status['errmsg'].include?('no replset config has been received')
181-
Puppet.debug 'Mongo v4 rs.status() RS not initialized output'
182-
alive.push(member)
183-
end
184-
185-
if status.key?('set')
186-
raise Puppet::Error, "Can't configure replicaset #{name}, host #{host} is already part of another replicaset." if status['set'] != name
187-
188-
# This node is alive and supposed to be a member of our set
189-
Puppet.debug "Host #{host} is available for replset #{status['set']}"
190-
alive.push(member)
191-
elsif status.key?('info')
192-
Puppet.debug "Host #{host} is alive but unconfigured: #{status['info']}"
193-
alive.push(member)
194-
end
195-
rescue Puppet::ExecutionFailure => e
196-
if e.message =~ %r{command replSetGetStatus requires authentication}
197-
Puppet.debug("Node #{host} is reachable but requires authentication: RS not initialized")
198-
alive.push(member)
199-
else
200-
Puppet.warning "Can't connect to replicaset member #{host} (Errormsg: #{e.message})."
174+
begin
175+
status = rs_status(host)
176+
Puppet.debug('XXXXXXXXXXXXXX should not get here since I dont have a replicaset')
177+
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'
178+
179+
# if auth_enabled && status.key?('errmsg')
180+
# Puppet.debug "In auth_enabled && status.key?('errmsg')"
181+
# if status['errmsg'].include?('requires authentication') || status['errmsg'].include?('not authorized on admin') || status['errmsg'].include?('Authentication failed')
182+
# Puppet.debug "In auth_enabled && status.key?('errmsg') need authentication"
183+
# Puppet.warning "Host #{host} is available, but you are unauthorized because of authentication is enabled: #{auth_enabled}"
184+
# alive.push(member)
185+
# elsif status['errmsg'].include?('no replset config has been received')
186+
# Puppet.debug 'Mongo rs.status() RS not initialized output'
187+
# alive.push(member)
188+
# end
189+
# end
190+
191+
if status.key?('set')
192+
raise Puppet::Error, "Can't configure replicaset #{name}, host #{host} is already part of another replicaset." if status['set'] != name
193+
194+
# This node is alive and supposed to be a member of our set
195+
Puppet.debug "Host #{host} is available for replset #{status['set']}"
196+
alive.push(member)
197+
elsif status.key?('info')
198+
Puppet.debug "Host #{host} is alive but unconfigured: #{status['info']}"
199+
alive.push(member)
200+
end
201+
rescue Puppet::ExecutionFailure => e
202+
Puppet.debug('XXXXXXXXXXXX in rescue checking connection mebers')
203+
if auth_enabled
204+
case e.message
205+
when %r{no replset config has been received}
206+
Puppet.warning('No replicaset config received, needs initialisation')
207+
when /Authentication failed/, /not authorized on admin/, /Authentication failed/
208+
Puppet.warning "Host #{host} is available, but you are unauthorized because of authentication is enabled: #{auth_enabled}"
209+
when /command replSetGetStatus requires authentication/
210+
Puppet.warning("Node #{host} is reachable but requires authentication: ReplicaSet not initialized")
211+
end
212+
alive.push(member)
213+
else
214+
Puppet.warning "Can't connect to replicaset member #{host} (Errormsg: #{e.message})."
215+
end
201216
end
202217
end
203218
alive.uniq!
@@ -410,19 +425,19 @@ def mongo_command(command, host, retries = 4)
410425
end
411426

412427
def self.mongo_command(command, host = nil, retries = 4)
413-
begin
428+
#begin
414429
output = mongo_eval("EJSON.stringify(#{command})", 'admin', retries, host)
415-
rescue Puppet::ExecutionFailure => e
416-
if e.message =~ %r{no replset config has been received} || e.message =~ %r{Authentication failed}
430+
#rescue Puppet::ExecutionFailure => e
431+
#if e.message =~ %r{no replset config has been received} || e.message =~ %r{Authentication failed}
432+
if output =~ %r{no replset config has been received} || output =~ %r{Authentication failed}
417433
output = '{}'
418-
else
419-
Puppet.debug "Got an exception: #{e}"
420-
raise
434+
# else
435+
# Puppet.debug "Got an exception: #{e}"
436+
# raise
421437
end
422-
end
438+
#end
423439

424440
# Hack to avoid non-json empty sets
425-
output = '{}' if output =~ %r{no replset config} || output =~ %r{Authentication failed}
426441
output = '{}' if output == "null\n"
427442
output = '{}' if output == "\nnull\n"
428443

lib/puppet/provider/mongodb_user/mongodb.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ def create
7878
end
7979
end
8080

81+
Puppet.debug("XXXXXXXXXX about to create user with command: #{command}")
8182
mongo_eval("db.runCommand(#{command.to_json})", @resource[:database])
8283
else
8384
Puppet.warning 'User creation is available only from master host'

0 commit comments

Comments
 (0)