Skip to content

Commit a6f7f05

Browse files
author
Johan De Wit
committed
remove extra debug lines
1 parent 2d78878 commit a6f7f05

File tree

4 files changed

+1
-81
lines changed

4 files changed

+1
-81
lines changed

lib/puppet/provider/mongodb.rb

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ def self.tls_invalid_hostnames(config = nil)
7575
end
7676

7777
def self.mongosh_cmd(db, host, cmd)
78-
Puppet.debug("MONGODB: in self.mongosh_cmd")
7978
config = mongo_conf
8079

8180
args = [db, '--quiet', '--host', host]
@@ -102,9 +101,7 @@ def self.mongosh_cmd(db, host, cmd)
102101
end
103102

104103
args += ['--eval', cmd]
105-
Puppet.debug("MONGODB: in self.mongosh_cmd executing with args #{args}")
106104
out = mongosh(args)
107-
Puppet.debug("MONGODB: in self.mongosh_cmd results in #{out}")
108105
out
109106
end
110107

@@ -150,17 +147,13 @@ def self.db_ismaster
150147
cmd_ismaster
151148
end
152149
begin
153-
Puppet.debug("MONGODB: In self.db_ismaster with cmd #{cmd_ismaster}")
154150
res = mongosh_cmd(db, conn_string, cmd_ismaster).to_s.split(%r{\n}).last.chomp
155151
rescue StandardError => e
156-
Puppet.debug("MONGODB: In self.db_ismaster in rescue")
157152
if self.auth_enabled && e.message =~ %r{Authentication failed}
158153
res = mongosh_cmd(db, conn_string, 'db.isMaster().ismaster').to_s.chomp
159-
Puppet.debug("MONGODB: In self.db_ismaster with res is #{res}")
160154
end
161155
end
162156

163-
Puppet.debug("MONGODB: In self.db_is_master with res is #{res}")
164157
res.eql?('true')
165158
end
166159

@@ -170,7 +163,6 @@ def db_ismaster
170163

171164
def self.auth_enabled(config = nil)
172165
config ||= mongo_conf
173-
Puppet.debug("in self.auth_enabled with config #{config}")
174166
config['auth'] && config['auth'] != 'disabled'
175167
end
176168

@@ -179,13 +171,11 @@ def self.rs_initiated?
179171
cmd_status = mongoshrc_file + cmd_status if mongoshrc_file
180172
db = 'admin'
181173
res = mongosh_cmd(db, conn_string, cmd_ismaster).to_s.split(%r{\n}).last.chomp
182-
Puppet.debug("MONGODB: In self.rs_initiated? with res is #{res}")
183174

184175
# Retry command without authentication when mongorc_file is set and authentication failed
185176
if mongorc_file && res =~ %r{Authentication failed}
186177
res = mongosh_cmd(db, conn_string, "rs.status('localhost').set").to_s.chomp
187178
end
188-
Puppet.debug("MONGODB: In self.rs_initiated? without auth res is #{res}")
189179

190180
res == @resource[:name]
191181
end
@@ -196,22 +186,19 @@ def rs_initiated?
196186

197187
# Mongo Command Wrapper
198188
def self.mongo_eval(cmd, db = 'admin', retries = 10, host = nil)
199-
Puppet.debug("MONGODB: in self.mongo_eval with cmd is #{cmd}")
200189
retry_count = retries
201190
retry_sleep = 3
202191
no_auth_cmd = cmd
203192
cmd = mongoshrc_file + cmd if mongoshrc_file
204193

205194
out = nil
206195
begin
207-
Puppet.debug("MONGODB: in self.mongo_eval in BEGIN")
208196
out = if host
209197
mongosh_cmd(db, host, cmd)
210198
else
211199
mongosh_cmd(db, conn_string, cmd)
212200
end
213201
rescue StandardError => e
214-
Puppet.debug("MONGODB: in self.mongo_eval rescue with error is #{e}")
215202
# When using the rc file, we get this eror because in most cases the admin user is not created yet
216203
# Can/must we move this out of the resue block ?
217204
if self.auth_enabled && e.message =~ %r{Authentication failed}
@@ -220,7 +207,6 @@ def self.mongo_eval(cmd, db = 'admin', retries = 10, host = nil)
220207
else
221208
mongosh_cmd(db, conn_string, no_auth_cmd)
222209
end
223-
Puppet.debug("MONGODB: in self.mongo_eval rescue inside if with out is #{out}")
224210
else
225211
retry_count -= 1
226212
if retry_count.positive?

lib/puppet/provider/mongodb_database/mongodb.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,14 @@ def self.prefetch(resources)
3131
end
3232

3333
def auth_enabled
34-
Puppet.debug('MONGODB_DATABASE: in auth_enabled')
3534
self.class.auth_enabled
3635
end
3736

3837
def create
3938
if db_ismaster
4039
begin
41-
Puppet.debug("MONGODB_DATABASE: In create")
4240
out = mongo_eval('db.dummyData.insertOne({"created_by_puppet": 1})', @resource[:name])
4341
rescue StandardError => e
44-
Puppet.debug("MONGODB_DATABSE: In create in rescue")
4542
if auth_enabled && e.message =~ %r{not authorized on admin to execute commanda} && @resource[:name] == 'admin'
4643
Puppet.warning 'Skipping database creation for admin, need admin user first when security is enabled'
4744
@property_hash[:ensure] = :present

lib/puppet/provider/mongodb_replset/mongo.rb

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,19 @@
1818
mk_resource_methods
1919

2020
def initialize(resource = {})
21-
Puppet.debug("REPLSET: initialise")
2221
super(resource)
2322
@property_flush = {}
2423
end
2524

2625
def settings=(settings)
27-
Puppet.debug("REPLSET: settings= with #{settings}")
2826
@property_flush[:settings] = settings
2927
end
3028

3129
def members=(hosts)
32-
Puppet.debug("REPLSET: members= with #{hosts}")
3330
@property_flush[:members] = hosts
3431
end
3532

3633
def self.instances
37-
Puppet.debug("REPLSET: instances")
3834
instance = replset_properties
3935
if instance
4036
# There can only be one replset per node
@@ -45,45 +41,38 @@ def self.instances
4541
end
4642

4743
def self.prefetch(resources)
48-
Puppet.debug("REPLSET: prefetch")
4944
instances.each do |prov|
5045
resource = resources[prov.name]
5146
resource.provider = prov if resource
5247
end
5348
end
5449

5550
def exists?
56-
Puppet.debug("REPLSET: exists?")
5751
@property_hash[:ensure] == :present
5852
end
5953

6054
def create
61-
Puppet.debug("REPLSET: create")
6255
@property_flush[:ensure] = :present
6356
@property_flush[:members] = resource.should(:members)
6457
@property_flush[:settings] = resource.should(:settings)
6558
end
6659

6760
def destroy
68-
Puppet.debug("REPLSET: destroy")
6961
@property_flush[:ensure] = :absent
7062
end
7163

7264
def flush
73-
Puppet.debug("REPLSET: flush")
7465
set_members
7566
@property_hash = self.class.replset_properties
7667
end
7768

7869
private
7970

8071
def db_ismaster(host)
81-
Puppet.debug("REPLSET: flush")
8272
mongo_command('db.isMaster()', host)
8373
end
8474

8575
def rs_initiate(conf, master)
86-
Puppet.debug("REPLSET: in rs_initiate with conf is #{conf} and master is #{master} and auth_enabled is #{auth_enabled}")
8776
if auth_enabled && auth_enabled != 'disabled'
8877
mongo_command("rs.initiate(#{conf})", initialize_host)
8978
else
@@ -92,58 +81,47 @@ def rs_initiate(conf, master)
9281
end
9382

9483
def rs_status(host)
95-
Puppet.debug("REPLSET: in rs_status with host is #{host}")
9684
mongo_command('rs.status()', host)
9785
end
9886

9987
def rs_config(host)
100-
Puppet.debug("REPLSET: in rs_config with host is #{host}")
10188
mongo_command('rs.config()', host)
10289
end
10390

10491
def rs_add(host_conf, master)
105-
Puppet.debug("REPLSET: in rs_add with host_conf is #{host_conf} and master is #{master}")
10692
mongo_command("rs.add(#{host_conf.to_json})", master)
10793
end
10894

10995
def rs_remove(host_conf, master)
110-
Puppet.debug("REPLSET: in rs_remove with host_conf is #{host_conf} and master is #{master}")
11196
host = host_conf['host']
11297
mongo_command("rs.remove('#{host}')", master)
11398
end
11499

115100
def rs_reconfig_member(host_conf, master)
116-
Puppet.debug("REPLSET: in rs_reconfig_member with host_conf is #{host_conf} and master is #{master}")
117101
mongo_command("rsReconfigMember(#{host_conf.to_json})", master)
118102
end
119103

120104
def rs_reconfig_settings(settings, master)
121-
Puppet.debug("REPLSET: in rs_reconfig_settings with settings is #{settings} and master is #{master}")
122105
mongo_command("rsReconfigSettings(#{settings.to_json})", master)
123106
end
124107

125108
def rs_arbiter
126-
Puppet.debug("REPLSET: rs_arbiter")
127109
@resource[:arbiter]
128110
end
129111

130112
def rs_add_arbiter(host, master)
131-
Puppet.debug("REPLSET: rs_add_arbiter")
132113
mongo_command("rs.addArb('#{host}')", master)
133114
end
134115

135116
def auth_enabled
136-
Puppet.debug('REPLSET: in auth_enabled')
137117
self.class.auth_enabled
138118
end
139119

140120
def initialize_host
141-
Puppet.debug("REPLSET: initialize_host")
142121
@resource[:initialize_host]
143122
end
144123

145124
def master_host(members)
146-
Puppet.debug("REPLSET: in master_host with members is #{members}")
147125
members.each do |member|
148126
status = db_ismaster(member['host'])
149127
return status['primary'] if status.key?('primary')
@@ -152,30 +130,24 @@ def master_host(members)
152130
end
153131

154132
def self.replset_properties
155-
Puppet.debug("REPLSET: self.replset_properties")
156133
conn_string = conn_string # rubocop:disable Lint/SelfAssignment
157134
begin
158135
output = mongo_command('rs.conf()', conn_string)
159136
rescue Puppet::ExecutionFailure => e
160-
Puppet.debug("REPLSET in self.replset_properties rescue with errors #{e.message}")
161137
if e.message =~ %r{command replSetGetConfig requires authentication} || e.message =~ %r{not authorized on admin to execute command}
162-
Puppet.debug("REPLSET in self.replset_properties rescue new try with rs.status()")
163138
output = mongo_command('rs.status()', conn_string)
164-
Puppet.debug("REPLSET in self.replset_properties rescue new try #{output}")
165139
if output['members']
166140
memb = []
167141
output['members'].each do |m|
168142
memb << { 'host' => m['name'] }
169143
end
170-
ret = {
144+
{
171145
name: output['set'],
172146
ensure: :present,
173147
members: memb,
174148
#settings: @resource[:settings],
175149
provider: :mongo
176150
}
177-
Puppet.debug("REPLSET in self.replset_properties rescue result is #{ret}")
178-
return ret
179151
end
180152
else
181153
nil
@@ -194,13 +166,11 @@ def self.replset_properties
194166
end
195167

196168
def get_hosts_status(members)
197-
Puppet.debug("REPLSET: get_hosts_status with #{members}")
198169
alive = []
199170
members.select do |member|
200171
host = member['host']
201172
Puppet.debug "Checking replicaset member #{host} ..."
202173
status = rs_status(host)
203-
Puppet.debug("REPLSET: get_hosts_status with status #{status}")
204174
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'
205175

206176
if auth_enabled && status.key?('errmsg') && (status['errmsg'].include?('requires authentication') || status['errmsg'].include?('not authorized on admin') || status['errmsg'].include?('Authentication failed'))
@@ -238,7 +208,6 @@ def get_hosts_status(members)
238208
end
239209

240210
def get_members_changes(current_members_conf, new_members_conf)
241-
Puppet.debug("REPLSET: get_ members_changes with #{current_members_conf} and #{new_members_conf}")
242211
# no changes in members config
243212
return [[], [], []] if new_members_conf.nil?
244213

@@ -270,16 +239,13 @@ def get_members_changes(current_members_conf, new_members_conf)
270239
end
271240

272241
def get_replset_settings_changes(current_settings, new_settings)
273-
Puppet.debug("REPLSET: get_replset_settings_change swith #{current_settings} and #{new_settings}")
274242
new_settings.each do |k, v|
275243
current_settings[k] = v
276244
end
277245
current_settings
278246
end
279247

280248
def set_members
281-
Puppet.debug("REPLSET: set_members")
282-
283249
if @property_flush[:ensure] == :absent
284250
# TODO: I don't know how to remove a node from a replset; unimplemented
285251
# Puppet.debug "Removing all members from replset #{self.name}"
@@ -298,7 +264,6 @@ def set_members
298264
# authentication should be working.
299265
#
300266
Puppet.debug 'Checking for dead and alive members'
301-
Puppet.debug("REPLSET: set_members @property_flush[:members] is #{@property_flush[:members]} and resource[:members] is #{resource[:members]}")
302267
if !@property_flush[:members].nil? && !@property_flush[:members].empty?
303268
# Find the alive members so we don't try to add dead members to the replset using new config
304269
alive_hosts, dead_hosts = get_hosts_status(@property_flush[:members])
@@ -448,11 +413,9 @@ def mongo_command(command, host, retries = 4)
448413
end
449414

450415
def self.mongo_command(command, host = nil, retries = 4)
451-
Puppet.debug("REPLSET: self.mongo_command #{command} and host #{host}")
452416
begin
453417
output = mongo_eval("EJSON.stringify(#{command})", 'admin', retries, host)
454418
rescue Puppet::ExecutionFailure => e
455-
Puppet.debug("REPLSET: rescue self.mongo_command error #{e.message} and #{output}")
456419
if e.message =~ %r{no replset config has been received} || e.message =~ %r{Authentication failed}
457420
output = '{}'
458421
else
@@ -465,7 +428,6 @@ def self.mongo_command(command, host = nil, retries = 4)
465428
output = '{}' if output =~ %r{no replset config} || output =~ %r{Authentication failed}
466429
output = '{}' if output == "null\n"
467430
output = '{}' if output == "\nnull\n"
468-
Puppet.debug("REPLSET: self.mongo_command result #{output}")
469431

470432
# Parse the JSON output and return
471433
JSON.parse(output)

0 commit comments

Comments
 (0)