8
8
if hosts . length > 1 && supported_version? ( default [ :platform ] , repo_version )
9
9
describe 'mongodb_replset resource' do
10
10
after :all do
11
- # Have to drop the DB to disable replsets for further testing
12
- on hosts , %{mongosh local --verbose --eval 'db.dropDatabase()'}
13
-
14
11
pp = <<-EOS
15
12
class { 'mongodb::globals':
16
13
#{ repo_ver_param }
@@ -20,10 +17,8 @@ class { 'mongodb::globals':
20
17
package_ensure => purged,
21
18
service_ensure => stopped
22
19
}
23
- if $::osfamily == 'RedHat' {
24
- class { 'mongodb::client':
25
- ensure => purged
26
- }
20
+ -> class { 'mongodb::client':
21
+ ensure => purged
27
22
}
28
23
EOS
29
24
@@ -36,12 +31,10 @@ class { 'mongodb::globals':
36
31
#{ repo_ver_param }
37
32
}
38
33
-> class { 'mongodb::server':
39
- bind_ip => '0.0.0.0',
34
+ bind_ip => [ '0.0.0.0'] ,
40
35
replset => 'test',
41
36
}
42
- if $::osfamily == 'RedHat' {
43
- class { 'mongodb::client': }
44
- }
37
+ -> class { 'mongodb::client': }
45
38
EOS
46
39
47
40
apply_manifest_on ( hosts . reverse , pp , catch_failures : true )
@@ -59,11 +52,81 @@ class { 'mongodb::client': }
59
52
expect ( r . stdout ) . to match %r{#{ hosts [ 0 ] } :27017}
60
53
expect ( r . stdout ) . to match %r{#{ hosts [ 1 ] } :27017}
61
54
end
55
+ sleep ( 30 )
56
+ on ( hosts_as ( 'slave' ) , 'mongosh --quiet --eval "EJSON.stringify(rs.conf())"' ) do |r |
57
+ expect ( r . stdout ) . to match %r{#{ hosts [ 0 ] } :27017}
58
+ expect ( r . stdout ) . to match %r{#{ hosts [ 1 ] } :27017}
59
+ end
62
60
end
63
61
64
62
it 'inserts data on the master' do
63
+ on hosts_as ( 'master' ) , %{mongosh --verbose --eval 'db.test.insertOne({name:"test1",value:"some value"})'}
64
+ end
65
+
66
+ it 'checks the data on the master' do
67
+ on hosts_as ( 'master' ) , %{mongosh --verbose --eval 'EJSON.stringify(db.test.findOne({name:"test1"}))'} do |r |
68
+ expect ( r . stdout ) . to match %r{some value}
69
+ end
70
+ end
71
+
72
+ it 'checks the data on the slave' do
73
+ sleep ( 10 )
74
+ on hosts_as ( 'slave' ) , %{mongosh --verbose --eval 'EJSON.stringify(db.test.findOne({name:"test1"}))'} do |r |
75
+ expect ( r . stdout ) . to match %r{some value}
76
+ end
77
+ end
78
+ end
79
+
80
+ describe 'mongodb::server with replset_members' do
81
+ after :all do
82
+ pp = <<-EOS
83
+ class { 'mongodb::globals':
84
+ #{ repo_ver_param }
85
+ }
86
+ -> class { 'mongodb::server':
87
+ ensure => absent,
88
+ package_ensure => purged,
89
+ service_ensure => stopped
90
+ }
91
+ -> class { 'mongodb::client':
92
+ ensure => purged
93
+ }
94
+ EOS
95
+
96
+ apply_manifest_on ( hosts . reverse , pp , catch_failures : true )
97
+ end
98
+
99
+ it 'configures mongo on both nodes' do
100
+ pp = <<-EOS
101
+ class { 'mongodb::globals':
102
+ #{ repo_ver_param }
103
+ }
104
+ -> class { 'mongodb::server':
105
+ bind_ip => ['0.0.0.0'],
106
+ replset => 'test',
107
+ replset_members => [#{ hosts . map { |x | "'#{ x } :27017'" } . join ( ',' ) } ],
108
+ }
109
+ -> class { 'mongodb::client': }
110
+ EOS
111
+
112
+ apply_manifest_on ( hosts , pp , catch_failures : true )
113
+ apply_manifest_on ( hosts , pp , catch_changes : true )
114
+ end
115
+
116
+ it 'sets up the replset with puppet' do
117
+ on ( hosts_as ( 'master' ) , 'mongosh --quiet --eval "EJSON.stringify(rs.conf())"' ) do |r |
118
+ expect ( r . stdout ) . to match %r{#{ hosts [ 0 ] } :27017}
119
+ expect ( r . stdout ) . to match %r{#{ hosts [ 1 ] } :27017}
120
+ end
65
121
sleep ( 30 )
66
- on hosts_as ( 'master' ) , %{mongosh --verbose --eval 'db.test.save({name:"test1",value:"some value"})'}
122
+ on ( hosts_as ( 'slave' ) , 'mongosh --quiet --eval "EJSON.stringify(rs.conf())"' ) do |r |
123
+ expect ( r . stdout ) . to match %r{#{ hosts [ 0 ] } :27017}
124
+ expect ( r . stdout ) . to match %r{#{ hosts [ 1 ] } :27017}
125
+ end
126
+ end
127
+
128
+ it 'inserts data on the master' do
129
+ on hosts_as ( 'master' ) , %{mongosh --verbose --eval 'db.getMongo().setReadPref("primaryPreferred");db.test.insertOne({name:"test1",value:"some value"})'}
67
130
end
68
131
69
132
it 'checks the data on the master' do
@@ -74,17 +137,14 @@ class { 'mongodb::client': }
74
137
75
138
it 'checks the data on the slave' do
76
139
sleep ( 10 )
77
- on hosts_as ( 'slave' ) , %{mongosh --verbose --eval 'db.getMongo().setReadPref("primaryPreferred"); EJSON.stringify(db.test.findOne({name:"test1"}))'} do |r |
140
+ on hosts_as ( 'slave' ) , %{mongosh --verbose --eval 'EJSON.stringify(db.test.findOne({name:"test1"}))'} do |r |
78
141
expect ( r . stdout ) . to match %r{some value}
79
142
end
80
143
end
81
144
end
82
145
83
146
describe 'mongodb_replset resource with auth => true' do
84
147
after :all do
85
- # Have to drop the DB to disable replsets for further testing
86
- on hosts , %{mongosh local --verbose --eval 'db.dropDatabase()'}
87
-
88
148
pp = <<-EOS
89
149
class { 'mongodb::globals':
90
150
#{ repo_ver_param }
@@ -94,28 +154,36 @@ class { 'mongodb::globals':
94
154
package_ensure => purged,
95
155
service_ensure => stopped
96
156
}
97
- if $::osfamily == 'RedHat' {
98
- class { 'mongodb::client':
99
- ensure => purged
100
- }
157
+ -> class { 'mongodb::client':
158
+ ensure => purged
101
159
}
102
160
EOS
103
161
104
162
apply_manifest_on ( hosts . reverse , pp , catch_failures : true )
105
163
end
106
164
165
+ let ( :keyfile_path ) do
166
+ os_family = fact ( 'os.family' )
167
+ if os_family == 'RedHat'
168
+ '/var/lib/mongo'
169
+ else
170
+ '/var/lib/mongodb'
171
+ end
172
+ end
173
+
107
174
it 'configures mongo on both nodes' do
108
175
pp = <<~EOS
109
176
class { 'mongodb::globals':
110
177
#{ repo_ver_param }
111
- } ->
112
- class { 'mongodb::server':
178
+ }
179
+ -> class { 'mongodb::server':
113
180
admin_username => 'admin',
114
181
admin_password => 'password',
115
182
auth => true,
116
- bind_ip => '0.0.0.0',
183
+ store_creds => true,
184
+ bind_ip => ['0.0.0.0'],
117
185
replset => 'test',
118
- keyfile => '/var/lib/ mongodb/mongodb -keyfile' ,
186
+ keyfile => " #{ keyfile_path } / mongodb-keyfile" ,
119
187
key => '+dxlTrury7xtD0FRqFf3YWGnKqWAtlyauuemxuYuyz9POPUuX1Uj3chGU8MFMHa7
120
188
UxASqex7NLMALQXHL+Th4T3dyb6kMZD7KiMcJObO4M+JLiX9drcTiifsDEgGMi7G
121
189
vYn3pWSm5TTDrHJw7RNWfMHw3sHk0muGQcO+0dWv3sDJ6SiU8yOKRtYcTEA15GbP
@@ -131,11 +199,9 @@ class { 'mongodb::server':
131
199
g+Bybk5qHv1b7M8Tv9/I/BRXcpLHeIkMICMY8sVPGmP8xzL1L3i0cws8p5h0zPBa
132
200
YG/QX0BmltAni8owgymFuyJgvr/gaRX4WHbKFD+9nKpqJ3ocuVNuCDsxDqLsJEME
133
201
nc1ohyB0lNt8lHf1U00mtgDSV3fwo5LkwhRi6d+bDBTL/C6MZETMLdyCqDlTdUWG
134
- YXIsJ0gYcu9XG3mx10LbdPJvxSMg'
135
- }
136
- if $::osfamily == 'RedHat' {
137
- include mongodb::client
202
+ YXIsJ0gYcu9XG3mx10LbdPJvxSMg',
138
203
}
204
+ -> class { 'mongodb::client': }
139
205
EOS
140
206
141
207
apply_manifest_on ( hosts . reverse , pp , catch_failures : true )
@@ -145,9 +211,16 @@ class { 'mongodb::server':
145
211
it 'sets up the replset with puppet' do
146
212
pp = <<~EOS
147
213
mongodb_replset { 'test':
148
- auth_enabled => true,
149
- members => [#{ hosts . map { |x | "'#{ x } :27017'" } . join ( ',' ) } ],
150
- before => Mongodb_user['admin']
214
+ members => [#{ hosts . map { |x | "'#{ x } :27017'" } . join ( ',' ) } ],
215
+ }
216
+ -> mongodb_user { "User admin on db admin":
217
+ ensure => present,
218
+ password_hash => mongodb_password('admin', 'password'),
219
+ username => 'admin',
220
+ database => 'admin',
221
+ roles => ['userAdmin', 'readWrite', 'dbAdmin', 'dbAdminAnyDatabase', 'readAnyDatabase',
222
+ 'readWriteAnyDatabase', 'userAdminAnyDatabase', 'clusterAdmin',
223
+ 'clusterManager', 'clusterMonitor', 'hostManager', 'root', 'restore',],
151
224
}
152
225
EOS
153
226
apply_manifest_on ( hosts_as ( 'master' ) , pp , catch_failures : true )
@@ -156,11 +229,112 @@ class { 'mongodb::server':
156
229
expect ( r . stdout ) . to match %r{#{ hosts [ 0 ] } :27017}
157
230
expect ( r . stdout ) . to match %r{#{ hosts [ 1 ] } :27017}
158
231
end
232
+ sleep ( 30 )
233
+ on ( hosts_as ( 'slave' ) , 'mongosh --quiet --eval "load(\'/root/.mongoshrc.js\');EJSON.stringify(rs.conf())"' ) do |r |
234
+ expect ( r . stdout ) . to match %r{#{ hosts [ 0 ] } :27017}
235
+ expect ( r . stdout ) . to match %r{#{ hosts [ 1 ] } :27017}
236
+ end
159
237
end
160
238
161
239
it 'inserts data on the master' do
240
+ on hosts_as ( 'master' ) , %{mongosh test --verbose --eval 'load("/root/.mongoshrc.js");db.dummyData.insertOne({"created_by_puppet": 1})'}
241
+ end
242
+
243
+ it 'checks the data on the master' do
244
+ on hosts_as ( 'master' ) , %{mongosh test --verbose --eval 'load("/root/.mongoshrc.js");EJSON.stringify(db.dummyData.findOne())'} do |r |
245
+ expect ( r . stdout ) . to match %r{created_by_puppet}
246
+ end
247
+ end
248
+
249
+ it 'checks the data on the slave' do
250
+ sleep ( 10 )
251
+ on hosts_as ( 'slave' ) , %{mongosh test --verbose --eval 'load("/root/.mongoshrc.js");db.getMongo().setReadPref("primaryPreferred");EJSON.stringify(db.dummyData.findOne())'} do |r |
252
+ expect ( r . stdout ) . to match %r{created_by_puppet}
253
+ end
254
+ end
255
+ end
256
+
257
+ describe 'mongodb::server with replset_members and auth => true' do
258
+ after :all do
259
+ pp = <<-EOS
260
+ class { 'mongodb::globals':
261
+ #{ repo_ver_param }
262
+ }
263
+ -> class { 'mongodb::server':
264
+ ensure => absent,
265
+ package_ensure => purged,
266
+ service_ensure => stopped
267
+ }
268
+ -> class { 'mongodb::client':
269
+ ensure => purged
270
+ }
271
+ EOS
272
+
273
+ apply_manifest_on ( hosts . reverse , pp , catch_failures : true )
274
+ end
275
+
276
+ let ( :keyfile_path ) do
277
+ os_family = fact ( 'os.family' )
278
+ if os_family == 'RedHat'
279
+ '/var/lib/mongo'
280
+ else
281
+ '/var/lib/mongodb'
282
+ end
283
+ end
284
+
285
+ it 'configures mongo on both nodes' do
286
+ pp = <<~EOS
287
+ class { 'mongodb::globals':
288
+ #{ repo_ver_param }
289
+ }
290
+ -> class { 'mongodb::client': }
291
+ -> class { 'mongodb::server':
292
+ admin_username => 'admin',
293
+ admin_password => 'password',
294
+ auth => true,
295
+ store_creds => true,
296
+ create_admin => true,
297
+ bind_ip => ['0.0.0.0'],
298
+ replset => 'test',
299
+ replset_members => [#{ hosts . map { |x | "'#{ x } :27017'" } . join ( ',' ) } ],
300
+ keyfile => "#{ keyfile_path } /mongodb-keyfile",
301
+ key => '+dxlTrury7xtD0FRqFf3YWGnKqWAtlyauuemxuYuyz9POPUuX1Uj3chGU8MFMHa7
302
+ UxASqex7NLMALQXHL+Th4T3dyb6kMZD7KiMcJObO4M+JLiX9drcTiifsDEgGMi7G
303
+ vYn3pWSm5TTDrHJw7RNWfMHw3sHk0muGQcO+0dWv3sDJ6SiU8yOKRtYcTEA15GbP
304
+ ReDZuHFy1T1qhk5NIt6pTtPGsZKSm2wAWIOa2f2IXvpeQHhjxP8aDFb3fQaCAqOD
305
+ R7hrimqq0Nickfe8RLA89iPXyadr/YeNBB7w7rySatQBzwIbBUVGNNA5cxCkwyx9
306
+ E5of3xi7GL9xNxhQ8l0JEpofd4H0y0TOfFDIEjc7cOnYlKAHzBgog4OcFSILgUaF
307
+ kHuTMtv0pj+MMkW2HkeXETNII9XE1+JiZgHY08G7yFEJy87ttUoeKmpbI6spFz5U
308
+ 4K0amj+N6SOwXaS8uwp6kCqay0ERJLnw+7dKNKZIZdGCrrBxcZ7wmR/wLYrxvHhZ
309
+ QpeXTxgD5ebwCR0cf3Xnb5ql5G/HHKZDq8LTFHwELNh23URGPY7K7uK+IF6jSEhq
310
+ V2H3HnWV9teuuJ5he9BB/pLnyfjft6KUUqE9HbaGlX0f3YBk/0T3S2ESN4jnfRTQ
311
+ ysAKvQ6NasXkzqXktu8X4fS5QNqrFyqKBZSWxttfJBKXnT0TxamCKLRx4AgQglYo
312
+ 3KRoyfxXx6G+AjP1frDJxFAFEIgEFqRk/FFuT/y9LpU+3cXYX1Gt6wEatgmnBM3K
313
+ g+Bybk5qHv1b7M8Tv9/I/BRXcpLHeIkMICMY8sVPGmP8xzL1L3i0cws8p5h0zPBa
314
+ YG/QX0BmltAni8owgymFuyJgvr/gaRX4WHbKFD+9nKpqJ3ocuVNuCDsxDqLsJEME
315
+ nc1ohyB0lNt8lHf1U00mtgDSV3fwo5LkwhRi6d+bDBTL/C6MZETMLdyCqDlTdUWG
316
+ YXIsJ0gYcu9XG3mx10LbdPJvxSMg',
317
+ }
318
+ EOS
319
+
320
+ apply_manifest_on ( hosts , pp , catch_failures : true )
321
+ apply_manifest_on ( hosts , pp , catch_changes : true )
322
+ end
323
+
324
+ it 'sets up the replset with puppet' do
325
+ on ( hosts_as ( 'master' ) , 'mongosh --quiet --eval "load(\'/root/.mongoshrc.js\');EJSON.stringify(rs.conf())"' ) do |r |
326
+ expect ( r . stdout ) . to match %r{#{ hosts [ 0 ] } :27017}
327
+ expect ( r . stdout ) . to match %r{#{ hosts [ 1 ] } :27017}
328
+ end
162
329
sleep ( 30 )
163
- on hosts_as ( 'master' ) , %{mongosh test --verbose --eval 'load("/root/.mongoshrc.js");db.dummyData.insert({"created_by_puppet": 1})'}
330
+ on ( hosts_as ( 'slave' ) , 'mongosh --quiet --eval "load(\'/root/.mongoshrc.js\');EJSON.stringify(rs.conf())"' ) do |r |
331
+ expect ( r . stdout ) . to match %r{#{ hosts [ 0 ] } :27017}
332
+ expect ( r . stdout ) . to match %r{#{ hosts [ 1 ] } :27017}
333
+ end
334
+ end
335
+
336
+ it 'inserts data on the master' do
337
+ on hosts_as ( 'master' ) , %{mongosh test --verbose --eval 'load("/root/.mongoshrc.js");db.dummyData.insertOne({"created_by_puppet": 1})'}
164
338
end
165
339
166
340
it 'checks the data on the master' do
0 commit comments