Skip to content

Commit 5a561c9

Browse files
author
Johan De Wit
committed
[Mongosh rc] Adjust for mongosh
1 parent 51397b6 commit 5a561c9

File tree

5 files changed

+12
-17
lines changed

5 files changed

+12
-17
lines changed

manifests/params.pp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
]
2020
$handle_creds = true
2121
$store_creds = false
22-
$rcfile = "${facts['root_home']}/.mongorc.js"
22+
$rcfile = "${facts['root_home']}/.mongoshrc.js"
2323
$dbpath_fix = false
2424

2525
$manage_package = pick($mongodb::globals::manage_package, $mongodb::globals::manage_package_repo, false)

manifests/server/config.pp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@
176176
if $handle_creds {
177177
file { $rcfile:
178178
ensure => file,
179-
content => template('mongodb/mongorc.js.erb'),
179+
content => template('mongodb/mongoshrc.js.erb'),
180180
owner => 'root',
181181
group => 'root',
182182
mode => '0600',

spec/acceptance/replset_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,26 +177,26 @@ class { 'mongodb::server':
177177
EOS
178178
apply_manifest_on(hosts_as('master'), pp, catch_failures: true)
179179
apply_manifest_on(hosts_as('master'), pp, catch_changes: true)
180-
on(hosts_as('master'), 'mongo --quiet --eval "load(\'/root/.mongorc.js\');printjson(rs.conf())"') do |r|
180+
on(hosts_as('master'), 'mongo --quiet --eval "load(\'/root/.mongoshrc.js\');printjson(rs.conf())"') do |r|
181181
expect(r.stdout).to match %r{#{hosts[0]}:27017}
182182
expect(r.stdout).to match %r{#{hosts[1]}:27017}
183183
end
184184
end
185185

186186
it 'inserts data on the master' do
187187
sleep(30)
188-
on hosts_as('master'), %{mongo test --verbose --eval 'load("/root/.mongorc.js");db.dummyData.insert({"created_by_puppet": 1})'}
188+
on hosts_as('master'), %{mongo test --verbose --eval 'load("/root/.mongoshrc.js");db.dummyData.insert({"created_by_puppet": 1})'}
189189
end
190190

191191
it 'checks the data on the master' do
192-
on hosts_as('master'), %{mongo test --verbose --eval 'load("/root/.mongorc.js");printjson(db.dummyData.findOne())'} do |r|
192+
on hosts_as('master'), %{mongo test --verbose --eval 'load("/root/.mongoshrc.js");printjson(db.dummyData.findOne())'} do |r|
193193
expect(r.stdout).to match %r{created_by_puppet}
194194
end
195195
end
196196

197197
it 'checks the data on the slave' do
198198
sleep(10)
199-
on hosts_as('slave'), %{mongo test --verbose --eval 'load("/root/.mongorc.js");try { rs.secondaryOk() } catch (err) { rs.slaveOk() };printjson(db.dummyData.findOne())'} do |r|
199+
on hosts_as('slave'), %{mongo test --verbose --eval 'load("/root/.mongoshrc.js");try { rs.secondaryOk() } catch (err) { rs.slaveOk() };printjson(db.dummyData.findOne())'} do |r|
200200
expect(r.stdout).to match %r{created_by_puppet}
201201
end
202202
end

spec/classes/server_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
it { is_expected.to contain_file(config_file).with_content(%r{^ fork: true$}) }
7272
end
7373

74-
it { is_expected.to contain_file('/root/.mongorc.js').with_ensure('file').without_content(%r{db\.auth}) }
74+
it { is_expected.to contain_file('/root/.mongoshrc.js').with_ensure('file').without_content(%r{db\.auth}) }
7575
it { is_expected.not_to contain_exec('fix dbpath permissions') }
7676
end
7777

@@ -165,7 +165,7 @@
165165
end
166166

167167
it { is_expected.to contain_file(config_file).with_content(%r{^security\.authorization: enabled$}) }
168-
it { is_expected.to contain_file('/root/.mongorc.js') }
168+
it { is_expected.to contain_file('/root/.mongoshrc.js') }
169169
end
170170

171171
describe 'when specifying set_parameter array value' do
@@ -262,7 +262,7 @@
262262
end
263263

264264
it {
265-
is_expected.to contain_file('/root/.mongorc.js').
265+
is_expected.to contain_file('/root/.mongoshrc.js').
266266
with_ensure('file').
267267
with_owner('root').
268268
with_group('root').
@@ -278,7 +278,7 @@
278278
}
279279
end
280280

281-
it { is_expected.to contain_file('/root/.mongorc.js').with_ensure('file').without_content(%r{db\.auth}) }
281+
it { is_expected.to contain_file('/root/.mongoshrc.js').with_ensure('file').without_content(%r{db\.auth}) }
282282
end
283283
end
284284

templates/mongorc.js.erb renamed to templates/mongoshrc.js.erb

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,7 @@ function authRequired() {
2828
if (authRequired()) {
2929
<%- if @replset -%>
3030
// rs.slaveOk has been deprecated, use secondaryOk if available
31-
try {
32-
rs.secondaryOk()
33-
}
34-
catch (err) {
35-
rs.slaveOk()
36-
}
31+
db.getMongo().setReadPref('primaryPreferred')
3732
<%- end -%>
3833
try {
3934
var prev_db = db
@@ -43,7 +38,7 @@ if (authRequired()) {
4338
}
4439
catch (err) {
4540
// This isn't catching authentication errors as I'd expect...
46-
abort('Unknown error')
41+
throw(err)
4742
}
4843
}
4944
<% end -%>

0 commit comments

Comments
 (0)