Debian Codegraph @

dirsrvtests/tests/suites/replication/cleanallruv_abort_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
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
60 @pytest.mark.flaky(max_runs=2, min_passes=1)
61 def test_abort(topology_m4):
62 """Test the abort task basic functionality
63
64 :id: b09a6887-8de0-4fac-8e41-73ccbaaf7a08
65 :setup: Replication setup with four suppliers
66 :steps:
67 1. Disable replication on supplier 4
68 2. Remove agreements to supplier 4 from other suppliers
69 3. Stop supplier 2
70 4. Run a cleanallruv task on supplier 1
71 5. Run a cleanallruv abort task on supplier 1
72 :expectedresults: No hanging tasks left
73 1. Replication on supplier 4 should be disabled
74 2. Agreements to supplier 4 should be removed
75 3. Supplier 2 should be stopped
76 4. Operation should be successful
77 5. Operation should be successful
78 """
79
80 log.info('Running test_abort...')
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", topology_m4)
85
86 # Stop supplier 2
87 log.info('test_abort: stop supplier 2 to freeze the cleanAllRUV task...')
88 topology_m4.ms["supplier2"].stop()
89
90 # Run the task
91 log.info('test_abort: 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 cruv_task.abort()
104
105 # Check supplier 1 does not have the clean task running
106 log.info('test_abort: check supplier 1 no longer has a cleanAllRUV task...')
107 if not task_done(topology_m4, cruv_task.dn):
108 log.fatal('test_abort: CleanAllRUV task was not aborted')
109 assert False
110
111 # Start supplier 2
112 log.info('test_abort: start supplier 2 to begin the restore process...')
113 topology_m4.ms["supplier2"].start()
114
115 log.info('test_abort PASSED')
116
117
118 if __name__ == '__main__':
119 # Run isolated
120 # -s for DEBUG mode
121 CURRENT_FILE = os.path.realpath(__file__)
122 pytest.main(["-s", CURRENT_FILE])
123