Debian Codegraph @

dirsrvtests/tests/suites/replication/cleanallruv_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 pytest
10 from lib389 import DirSrv
11 from lib389.tasks import *
12 from lib389.utils import *
13 from lib389.monitor import Monitor
14 from test389.topologies import topology_m4, topology_m2, topology_m2c2
15 from lib389._constants import DEFAULT_SUFFIX
16 from lib389.replica import ReplicationManager, Replicas
17 from lib389.tasks import CleanAllRUVTask
18
19
20 pytestmark = pytest.mark.tier1
21
22 logging.getLogger(__name__).setLevel(logging.DEBUG)
23 log = logging.getLogger(__name__)
24
25
26 def remove_supplier4_agmts(msg, topology_m4):
27 """Remove all the repl agmts to supplier4. """
28
29 log.info('%s: remove all the agreements to supplier 4...' % msg)
30 repl = ReplicationManager(DEFAULT_SUFFIX)
31 # This will delete m4 from the topo *and* remove all incoming agreements
32 # to m4.
33 repl.remove_supplier(topology_m4.ms["supplier4"],
34 [topology_m4.ms["supplier1"], topology_m4.ms["supplier2"], topology_m4.ms["supplier3"]])
35
36 def check_ruvs(msg, topology_m4, m4rid):
37 """Check suppliers 1-3 for supplier 4's rid."""
38 for inst in (topology_m4.ms["supplier1"], topology_m4.ms["supplier2"], topology_m4.ms["supplier3"]):
39 clean = False
40 replicas = Replicas(inst)
41 replica = replicas.get(DEFAULT_SUFFIX)
42 log.info('check_ruvs for replica %s:%s (suffix:rid)' % (replica.get_suffix(), replica.get_rid()))
43
44 count = 0
45 while not clean and count < 20:
46 ruv = replica.get_ruv()
47 if m4rid in ruv._rids:
48 time.sleep(5)
49 count = count + 1
50 else:
51 clean = True
52 if not clean:
53 raise Exception("Supplier %s was not cleaned in time." % inst.serverid)
54 return True
55
56
57 def test_clean(topology_m4):
58 """Check that cleanallruv task works properly
59
60 :id: e9b3ce5c-e17c-409e-aafc-e97d630f2878
61 :setup: Replication setup with four suppliers
62 :steps:
63 1. Check that replication works on all suppliers
64 2. Disable replication on supplier 4
65 3. Remove agreements to supplier 4 from other suppliers
66 4. Run a cleanallruv task on supplier 1 with a 'force' option 'on'
67 5. Check that everything was cleaned
68 :expectedresults:
69 1. Replication should work properly on all suppliers
70 2. Operation should be successful
71 3. Agreements to supplier 4 should be removed
72 4. Cleanallruv task should be successfully executed
73 5. Everything should be cleaned
74 """
75
76 log.info('Running test_clean...')
77 # Disable supplier 4
78 # Remove the agreements from the other suppliers that point to supplier 4
79 log.info('test_clean: disable supplier 4...')
80 repl = ReplicationManager(DEFAULT_SUFFIX)
81 m4rid = repl.get_rid(topology_m4.ms["supplier4"])
82 remove_supplier4_agmts("test_clean", topology_m4)
83
84 # Run the task
85 log.info('test_clean: run the cleanAllRUV task...')
86 cruv_task = CleanAllRUVTask(topology_m4.ms["supplier1"])
87 cruv_task.create(properties={
88 'replica-id': m4rid,
89 'replica-base-dn': DEFAULT_SUFFIX,
90 'replica-force-cleaning': 'no'
91 })
92 cruv_task.wait()
93
94 # Check the other supplier's RUV for 'replica 4'
95 log.info('test_clean: check all the suppliers have been cleaned...')
96 clean = check_ruvs("test_clean", topology_m4, m4rid)
97 assert clean
98
99 log.info('test_clean PASSED, restoring supplier 4...')
100
101 def test_cleanallruv_consumer(topology_m2c2):
102 """Check that cleanallruv task works properly on consumer
103
104 :id: 2c0e7e83-314d-4df1-b1b7-07b7ab242976
105 :setup: Replication setup with 2 suppliers and 2 consumers
106 :steps:
107 1. Run a cleanallruv task on supplier 2
108 2. Waits until completion
109 3. Retrieve monitoring info from all servers
110 convenient way to check the server did not crash
111 :expectedresults:
112 1. pass
113 2. pass
114 3. pass
115 """
116
117 log.info('test_cleanallruv_consumer: Starts ...')
118 supplier1 = topology_m2c2.ms["supplier1"]
119 supplier2 = topology_m2c2.ms["supplier2"]
120 consumer1 = topology_m2c2.cs["consumer1"]
121 consumer2 = topology_m2c2.cs["consumer2"]
122 log.info('Running ...')
123
124 # Run the task
125 log.info('test_cleanallruv_consumer: run the cleanAllRUV task...')
126 repl = ReplicationManager(DEFAULT_SUFFIX)
127 m1rid = repl.get_rid(supplier1)
128 cruv_task = CleanAllRUVTask(supplier2)
129 cruv_task.create(properties={
130 'replica-id': m1rid,
131 'replica-base-dn': DEFAULT_SUFFIX,
132 'replica-force-cleaning': 'no'
133 })
134 cruv_task.wait()
135
136 # Check that all servers are alived
137 for server in (supplier1, supplier2, consumer1, consumer2):
138 monitor = Monitor(server)
139 version = monitor.get_version()
140 assert(version)
141
142 log.info('test_cleanallruv_consumer PASSED..')
143
144
145 if __name__ == '__main__':
146 # Run isolated
147 # -s for DEBUG mode
148 CURRENT_FILE = os.path.realpath(__file__)
149 pytest.main("-s %s" % CURRENT_FILE)