Debian Codegraph @

dirsrvtests/tests/suites/replication/cleanallruv_abort_certify_test.py

raw
1 # --- BEGIN COPYRIGHT BLOCK ---
2 # Copyright (C) 2022 Red Hat, Inc.
3 # All rights reserved.
4 #
5 # License: GPL (version 3 or any later version).
6 # See LICENSE for details.
7 # --- END COPYRIGHT BLOCK ---
8 #
9 import logging
10 import pytest
11 import os
12 import time
13 from lib389._constants import DEFAULT_SUFFIX
14 from test389.topologies import topology_m4
15 from lib389.tasks import CleanAllRUVTask
16 from lib389.replica import ReplicationManager, Replicas
17
18 log = logging.getLogger(__name__)
19
20
21 def remove_supplier4_agmts(msg, topology_m4):
22 """Remove all the repl agmts to supplier4. """
23
24 log.info('%s: remove all the agreements to supplier 4...' % msg)
25 repl = ReplicationManager(DEFAULT_SUFFIX)
26 # This will delete m4 from the topo *and* remove all incoming agreements
27 # to m4.
28 repl.remove_supplier(topology_m4.ms["supplier4"],
29 [topology_m4.ms["supplier1"], topology_m4.ms["supplier2"], topology_m4.ms["supplier3"]])
30
31 def task_done(topology_m4, task_dn, timeout=60):
32 """Check if the task is complete"""
33
34 attrlist = ['nsTaskLog', 'nsTaskStatus', 'nsTaskExitCode',
35 'nsTaskCurrentItem', 'nsTaskTotalItems']
36 done = False
37 count = 0
38
39 while not done and count < timeout:
40 try:
41 entry = topology_m4.ms["supplier1"].getEntry(task_dn, attrlist=attrlist)
42 if entry is not None:
43 if entry.hasAttr('nsTaskExitCode'):
44 done = True
45 break
46 else:
47 done = True
48 break
49 except ldap.NO_SUCH_OBJECT:
50 done = True
51 break
52 except ldap.LDAPError:
53 break
54 time.sleep(1)
55 count += 1
56
57 return done
58
59 @pytest.mark.flaky(max_runs=2, min_passes=1)
60 def test_abort_certify(topology_m4):
61 """Test the abort task with a replica-certify-all option
62
63 :id: 78959966-d644-44a8-b98c-1fcf21b45eb0
64 :setup: Replication setup with four suppliers
65 :steps:
66 1. Disable replication on supplier 4
67 2. Remove agreements to supplier 4 from other suppliers
68 3. Stop supplier 2
69 4. Run a cleanallruv task on supplier 1
70 5. Run a cleanallruv abort task on supplier 1 with a replica-certify-all option
71 :expectedresults: No hanging tasks left
72 1. Replication on supplier 4 should be disabled
73 2. Agreements to supplier 4 should be removed
74 3. Supplier 2 should be stopped
75 4. Operation should be successful
76 5. Operation should be successful
77 """
78
79 log.info('Running test_abort_certify...')
80
81 # Remove the agreements from the other suppliers that point to supplier 4
82 repl = ReplicationManager(DEFAULT_SUFFIX)
83 m4rid = repl.get_rid(topology_m4.ms["supplier4"])
84 remove_supplier4_agmts("test_abort_certify", topology_m4)
85
86 # Stop supplier 2
87 log.info('test_abort_certify: stop supplier 2 to freeze the cleanAllRUV task...')
88 topology_m4.ms["supplier2"].stop()
89
90 # Run the task
91 log.info('test_abort_certify: add the cleanAllRUV task...')
92 cruv_task = CleanAllRUVTask(topology_m4.ms["supplier1"])
93 cruv_task.create(properties={
94 'replica-id': m4rid,
95 'replica-base-dn': DEFAULT_SUFFIX,
96 'replica-force-cleaning': 'no',
97 'replica-certify-all': 'yes'
98 })
99 # Wait a bit
100 time.sleep(2)
101
102 # Abort the task
103 log.info('test_abort_certify: abort the cleanAllRUV task...')
104 abort_task = cruv_task.abort(certify=True)
105
106 # Wait a while and make sure the abort task is still running
107 log.info('test_abort_certify...')
108
109 if task_done(topology_m4, abort_task.dn, 10):
110 log.fatal('test_abort_certify: abort task incorrectly finished')
111 assert False
112
113 # Now start supplier 2 so it can be aborted
114 log.info('test_abort_certify: start supplier 2 to allow the abort task to finish...')
115 topology_m4.ms["supplier2"].start()
116
117 # Wait for the abort task to stop
118 if not task_done(topology_m4, abort_task.dn, 90):
119 log.fatal('test_abort_certify: The abort CleanAllRUV task was not aborted')
120 assert False
121
122 # Check supplier 1 does not have the clean task running
123 log.info('test_abort_certify: check supplier 1 no longer has a cleanAllRUV task...')
124 if not task_done(topology_m4, cruv_task.dn):
125 log.fatal('test_abort_certify: CleanAllRUV task was not aborted')
126 assert False
127
128 log.info('test_abort_certify PASSED')
129
130
131 if __name__ == '__main__':
132 # Run isolated
133 # -s for DEBUG mode
134 CURRENT_FILE = os.path.realpath(__file__)
135 pytest.main(["-s", CURRENT_FILE])
136