@@ -120,9 +120,13 @@ def test_mongod_pebble_ready(self, connect_exporter, fix_data_dir, defer, pull_l
120
120
# Ensure that _connect_mongodb_exporter was called
121
121
connect_exporter .assert_called_once ()
122
122
123
+ @patch ("charm.MongoDBCharm.get_current_termination_period" )
124
+ @patch ("charm.MongoDBCharm.update_termination_grace_period" )
123
125
@patch ("ops.framework.EventBase.defer" )
124
126
@patch ("charm.MongoDBCharm._push_keyfile_to_workload" )
125
- def test_pebble_ready_cannot_retrieve_container (self , push_keyfile_to_workload , defer ):
127
+ def test_pebble_ready_cannot_retrieve_container (
128
+ self , push_keyfile_to_workload , defer , * unused
129
+ ):
126
130
"""Test verifies behavior when retrieving container results in ModelError in pebble ready.
127
131
128
132
Verifies that when a failure to get a container occurs, that that failure is raised and
@@ -142,9 +146,11 @@ def test_pebble_ready_cannot_retrieve_container(self, push_keyfile_to_workload,
142
146
mock_container .replan .assert_not_called ()
143
147
defer .assert_not_called ()
144
148
149
+ @patch ("charm.MongoDBCharm.get_current_termination_period" )
150
+ @patch ("charm.MongoDBCharm.update_termination_grace_period" )
145
151
@patch ("ops.framework.EventBase.defer" )
146
152
@patch ("charm.MongoDBCharm._push_keyfile_to_workload" )
147
- def test_pebble_ready_container_cannot_connect (self , push_keyfile_to_workload , defer ):
153
+ def test_pebble_ready_container_cannot_connect (self , push_keyfile_to_workload , defer , * unused ):
148
154
"""Test verifies behavior when cannot connect to container in pebble ready function.
149
155
150
156
Verifies that when a failure to connect to container results in a deferral and that no
@@ -203,11 +209,15 @@ def test_pebble_ready_no_storage_yet(self, defer):
203
209
mock_container .replan .assert_not_called ()
204
210
defer .assert_called ()
205
211
212
+ @patch ("charm.MongoDBCharm.get_current_termination_period" )
213
+ @patch ("charm.MongoDBCharm.update_termination_grace_period" )
206
214
@patch ("ops.framework.EventBase.defer" )
207
215
@patch ("charm.MongoDBProvider" )
208
216
@patch ("charm.MongoDBCharm._init_operator_user" )
209
217
@patch ("charm.MongoDBConnection" )
210
- def test_start_cannot_retrieve_container (self , connection , init_user , provider , defer ):
218
+ def test_start_cannot_retrieve_container (
219
+ self , connection , init_user , provider , defer , * unused
220
+ ):
211
221
"""Verifies that failures to get container result in a ModelError being raised.
212
222
213
223
Further this function verifies that on error no attempts to set up the replica set or
@@ -230,11 +240,13 @@ def test_start_cannot_retrieve_container(self, connection, init_user, provider,
230
240
self .assertEqual ("db_initialised" in self .harness .charm .app_peer_data , False )
231
241
defer .assert_not_called ()
232
242
243
+ @patch ("charm.MongoDBCharm.get_current_termination_period" )
244
+ @patch ("charm.MongoDBCharm.update_termination_grace_period" )
233
245
@patch ("ops.framework.EventBase.defer" )
234
246
@patch ("charm.MongoDBProvider" )
235
247
@patch ("charm.MongoDBCharm._init_operator_user" )
236
248
@patch ("charm.MongoDBConnection" )
237
- def test_start_container_cannot_connect (self , connection , init_user , provider , defer ):
249
+ def test_start_container_cannot_connect (self , connection , init_user , provider , defer , * unused ):
238
250
"""Tests inability to connect results in deferral.
239
251
240
252
Verifies that if connection is not possible, that there are no attempts to set up the
@@ -257,11 +269,13 @@ def test_start_container_cannot_connect(self, connection, init_user, provider, d
257
269
self .assertEqual ("db_initialised" in self .harness .charm .app_peer_data , False )
258
270
defer .assert_called ()
259
271
272
+ @patch ("charm.MongoDBCharm.get_current_termination_period" )
273
+ @patch ("charm.MongoDBCharm.update_termination_grace_period" )
260
274
@patch ("ops.framework.EventBase.defer" )
261
275
@patch ("charm.MongoDBProvider" )
262
276
@patch ("charm.MongoDBCharm._init_operator_user" )
263
277
@patch ("charm.MongoDBConnection" )
264
- def test_start_container_does_not_exist (self , connection , init_user , provider , defer ):
278
+ def test_start_container_does_not_exist (self , connection , init_user , provider , defer , * unused ):
265
279
"""Tests lack of existence of files on container results in deferral.
266
280
267
281
Verifies that if files do not exists, that there are no attempts to set up the replica set
@@ -285,11 +299,13 @@ def test_start_container_does_not_exist(self, connection, init_user, provider, d
285
299
self .assertEqual ("db_initialised" in self .harness .charm .app_peer_data , False )
286
300
defer .assert_called ()
287
301
302
+ @patch ("charm.MongoDBCharm.get_current_termination_period" )
303
+ @patch ("charm.MongoDBCharm.update_termination_grace_period" )
288
304
@patch ("ops.framework.EventBase.defer" )
289
305
@patch ("charm.MongoDBProvider" )
290
306
@patch ("charm.MongoDBCharm._init_operator_user" )
291
307
@patch ("charm.MongoDBConnection" )
292
- def test_start_container_exists_fails (self , connection , init_user , provider , defer ):
308
+ def test_start_container_exists_fails (self , connection , init_user , provider , defer , * unused ):
293
309
"""Tests failure in checking file existence on container raises an APIError.
294
310
295
311
Verifies that when checking container files raises an API Error, we raise that same error
@@ -314,11 +330,13 @@ def test_start_container_exists_fails(self, connection, init_user, provider, def
314
330
self .assertEqual ("db_initialised" in self .harness .charm .app_peer_data , False )
315
331
defer .assert_not_called ()
316
332
333
+ @patch ("charm.MongoDBCharm.get_current_termination_period" )
334
+ @patch ("charm.MongoDBCharm.update_termination_grace_period" )
317
335
@patch ("ops.framework.EventBase.defer" )
318
336
@patch ("charm.MongoDBProvider" )
319
337
@patch ("charm.MongoDBCharm._init_operator_user" )
320
338
@patch ("charm.MongoDBConnection" )
321
- def test_start_already_initialised (self , connection , init_user , provider , defer ):
339
+ def test_start_already_initialised (self , connection , init_user , provider , defer , * unused ):
322
340
"""Tests that if the replica set has already been set up that we return.
323
341
324
342
Verifies that if the replica set is already set up that no attempts to set it up again are
@@ -343,11 +361,13 @@ def test_start_already_initialised(self, connection, init_user, provider, defer)
343
361
provider .return_value .oversee_users .assert_not_called ()
344
362
defer .assert_not_called ()
345
363
364
+ @patch ("charm.MongoDBCharm.get_current_termination_period" )
365
+ @patch ("charm.MongoDBCharm.update_termination_grace_period" )
346
366
@patch ("ops.framework.EventBase.defer" )
347
367
@patch ("charm.MongoDBProvider" )
348
368
@patch ("charm.MongoDBCharm._init_operator_user" )
349
369
@patch ("charm.MongoDBConnection" )
350
- def test_start_mongod_not_ready (self , connection , init_user , provider , defer ):
370
+ def test_start_mongod_not_ready (self , connection , init_user , provider , defer , * unused ):
351
371
"""Tests that if mongod is not ready that we defer and return.
352
372
353
373
Verifies that if mongod is not ready that no attempts to set up the replica set and set up
@@ -374,12 +394,14 @@ def test_start_mongod_not_ready(self, connection, init_user, provider, defer):
374
394
self .assertEqual ("db_initialised" in self .harness .charm .app_peer_data , False )
375
395
defer .assert_called ()
376
396
397
+ @patch ("charm.MongoDBCharm.get_current_termination_period" )
398
+ @patch ("charm.MongoDBCharm.update_termination_grace_period" )
377
399
@patch ("ops.framework.EventBase.defer" )
378
400
@patch ("charm.MongoDBProvider" )
379
401
@patch ("charm.MongoDBCharm._initialise_users" )
380
402
@patch ("charm.MongoDBConnection" )
381
403
def test_start_mongod_error_initalising_replica_set (
382
- self , connection , init_users , provider , defer
404
+ self , connection , init_users , provider , defer , * unused
383
405
):
384
406
"""Tests that failure to initialise replica set is properly handled.
385
407
@@ -403,12 +425,14 @@ def test_start_mongod_error_initalising_replica_set(
403
425
self .assertEqual ("replica_set_initialised" in self .harness .charm .app_peer_data , False )
404
426
defer .assert_called ()
405
427
428
+ @patch ("charm.MongoDBCharm.get_current_termination_period" )
429
+ @patch ("charm.MongoDBCharm.update_termination_grace_period" )
406
430
@patch ("ops.framework.EventBase.defer" )
407
431
@patch ("charm.MongoDBProvider" )
408
432
@patch ("charm.MongoDBCharm._init_operator_user" )
409
433
@patch ("charm.MongoDBConnection" )
410
434
@patch ("tenacity.nap.time.sleep" , MagicMock ())
411
- def test_error_initalising_users (self , connection , init_user , provider , defer ):
435
+ def test_error_initalising_users (self , connection , init_user , provider , defer , * unused ):
412
436
"""Tests that failure to initialise users set is properly handled.
413
437
414
438
Verifies that when there is a failure to initialise users that overseeing users is not
@@ -433,6 +457,8 @@ def test_error_initalising_users(self, connection, init_user, provider, defer):
433
457
# verify app data
434
458
self .assertEqual ("db_initialised" in self .harness .charm .app_peer_data , False )
435
459
460
+ @patch ("charm.MongoDBCharm.get_current_termination_period" )
461
+ @patch ("charm.MongoDBCharm.update_termination_grace_period" )
436
462
@patch ("ops.framework.EventBase.defer" )
437
463
@patch ("charm.MongoDBProvider" )
438
464
@patch ("charm.MongoDBCharm._init_operator_user" )
@@ -444,7 +470,7 @@ def test_error_initalising_users(self, connection, init_user, provider, defer):
444
470
@patch ("charm.wait_fixed" )
445
471
@patch ("charm.stop_after_attempt" )
446
472
def test_start_mongod_error_overseeing_users (
447
- self , retry_stop , retry_wait , connection , init_user , provider , defer
473
+ self , retry_stop , retry_wait , connection , init_user , provider , defer , * unused
448
474
):
449
475
"""Tests failures related to pymongo are properly handled when overseeing users.
450
476
@@ -640,10 +666,14 @@ def test_reconfigure_add_member_failure(self, connection, defer):
640
666
connection .return_value .__enter__ .return_value .add_replset_member .assert_called ()
641
667
defer .assert_called ()
642
668
669
+ @patch ("charm.MongoDBCharm.get_current_termination_period" )
670
+ @patch ("charm.MongoDBCharm.update_termination_grace_period" )
643
671
@patch ("ops.framework.EventBase.defer" )
644
672
@patch ("charm.MongoDBProvider.oversee_users" )
645
673
@patch ("charm.MongoDBConnection" )
646
- def test_start_init_operator_user_after_second_call (self , connection , oversee_users , defer ):
674
+ def test_start_init_operator_user_after_second_call (
675
+ self , connection , oversee_users , defer , * unused
676
+ ):
647
677
"""Tests that the creation of the admin user is only performed once.
648
678
649
679
Verifies that if the user is already set up, that no attempts to set it up again are
@@ -999,6 +1029,8 @@ def test__connect_mongodb_exporter_success(
999
1029
expected_uri = uri_template .format (password = "mongo123" )
1000
1030
self .assertEqual (expected_uri , new_uri )
1001
1031
1032
+ @patch ("charm.MongoDBCharm.get_current_termination_period" )
1033
+ @patch ("charm.MongoDBCharm.update_termination_grace_period" )
1002
1034
@patch ("tenacity.nap.time.sleep" , MagicMock ())
1003
1035
@patch ("charm.USER_CREATING_MAX_ATTEMPTS" , 1 )
1004
1036
@patch ("charm.USER_CREATION_COOLDOWN" , 1 )
@@ -1021,6 +1053,7 @@ def test__backup_user_created(
1021
1053
_connect_mongodb_exporter ,
1022
1054
_init_operator_user ,
1023
1055
_init_monitor_user ,
1056
+ * unused ,
1024
1057
):
1025
1058
"""Tests what backup user was created."""
1026
1059
self .harness .charm ._initialise_users .retry .wait = wait_none ()
@@ -1032,8 +1065,10 @@ def test__backup_user_created(
1032
1065
self .harness .charm ._initialise_users .retry .wait = wait_none ()
1033
1066
self .assertIsNotNone (password ) # verify the password is set
1034
1067
1068
+ @patch ("charm.MongoDBCharm.get_current_termination_period" )
1069
+ @patch ("charm.MongoDBCharm.update_termination_grace_period" )
1035
1070
@patch ("charm.MongoDBConnection" )
1036
- def test_set_password_provided (self , connection ):
1071
+ def test_set_password_provided (self , connection , * unused ):
1037
1072
"""Tests that a given password is set as the new mongodb password for backup user."""
1038
1073
container = self .harness .model .unit .get_container ("mongod" )
1039
1074
self .harness .set_leader (True )
0 commit comments