| 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 |
|
| 60 |
def check_ruvs(msg, topology_m4, m4rid): |
| 61 |
"""Check suppliers 1-3 for supplier 4's rid.""" |
| 62 |
for inst in (topology_m4.ms["supplier1"], topology_m4.ms["supplier2"], topology_m4.ms["supplier3"]): |
| 63 |
clean = False |
| 64 |
replicas = Replicas(inst) |
| 65 |
replica = replicas.get(DEFAULT_SUFFIX) |
| 66 |
log.info('check_ruvs for replica %s:%s (suffix:rid)' % (replica.get_suffix(), replica.get_rid())) |
| 67 |
|
| 68 |
count = 0 |
| 69 |
while not clean and count < 20: |
| 70 |
ruv = replica.get_ruv() |
| 71 |
if m4rid in ruv._rids: |
| 72 |
time.sleep(5) |
| 73 |
count = count + 1 |
| 74 |
else: |
| 75 |
clean = True |
| 76 |
if not clean: |
| 77 |
raise Exception("Supplier %s was not cleaned in time." % inst.serverid) |
| 78 |
return True |
| 79 |
|
| 80 |
|
| 81 |
@pytest.mark.flaky(max_runs=2, min_passes=1) |
| 82 |
def test_clean_restart(topology_m4): |
| 83 |
"""Check that cleanallruv task works properly after a restart |
| 84 |
|
| 85 |
:id: c6233bb3-092c-4919-9ac9-80dd02cc6e02 |
| 86 |
:setup: Replication setup with four suppliers |
| 87 |
:steps: |
| 88 |
1. Disable replication on supplier 4 |
| 89 |
2. Remove agreements to supplier 4 from other suppliers |
| 90 |
3. Stop supplier 3 |
| 91 |
4. Run a cleanallruv task on supplier 1 |
| 92 |
5. Stop supplier 1 |
| 93 |
6. Start supplier 3 |
| 94 |
7. Make sure that no crash happened |
| 95 |
8. Start supplier 1 |
| 96 |
9. Make sure that no crash happened |
| 97 |
10. Check that everything was cleaned |
| 98 |
:expectedresults: |
| 99 |
1. Operation should be successful |
| 100 |
2. Agreements to supplier 4 should be removed |
| 101 |
3. Supplier 3 should be stopped |
| 102 |
4. Cleanallruv task should be successfully executed |
| 103 |
5. Supplier 1 should be stopped |
| 104 |
6. Supplier 3 should be started |
| 105 |
7. No crash should happened |
| 106 |
8. Supplier 1 should be started |
| 107 |
9. No crash should happened |
| 108 |
10. Everything should be cleaned |
| 109 |
""" |
| 110 |
log.info('Running test_clean_restart...') |
| 111 |
|
| 112 |
# Disable supplier 4 |
| 113 |
log.info('test_clean: disable supplier 4...') |
| 114 |
|
| 115 |
# Remove the agreements from the other suppliers that point to supplier 4 |
| 116 |
repl = ReplicationManager(DEFAULT_SUFFIX) |
| 117 |
m4rid = repl.get_rid(topology_m4.ms["supplier4"]) |
| 118 |
remove_supplier4_agmts("test_clean", topology_m4) |
| 119 |
|
| 120 |
# Stop supplier 3 to keep the task running, so we can stop supplier 1... |
| 121 |
topology_m4.ms["supplier3"].stop() |
| 122 |
|
| 123 |
# Run the task |
| 124 |
log.info('test_clean: run the cleanAllRUV task...') |
| 125 |
cruv_task = CleanAllRUVTask(topology_m4.ms["supplier1"]) |
| 126 |
cruv_task.create(properties={ |
| 127 |
'replica-id': m4rid, |
| 128 |
'replica-base-dn': DEFAULT_SUFFIX, |
| 129 |
'replica-force-cleaning': 'no', |
| 130 |
'replica-certify-all': 'yes' |
| 131 |
}) |
| 132 |
|
| 133 |
# Sleep a bit, then stop supplier 1 |
| 134 |
time.sleep(5) |
| 135 |
topology_m4.ms["supplier1"].stop() |
| 136 |
|
| 137 |
# Now start supplier 3 & 1, and make sure we didn't crash |
| 138 |
topology_m4.ms["supplier3"].start() |
| 139 |
if topology_m4.ms["supplier3"].detectDisorderlyShutdown(): |
| 140 |
log.fatal('test_clean_restart: Supplier 3 previously crashed!') |
| 141 |
assert False |
| 142 |
|
| 143 |
topology_m4.ms["supplier1"].start(timeout=30) |
| 144 |
if topology_m4.ms["supplier1"].detectDisorderlyShutdown(): |
| 145 |
log.fatal('test_clean_restart: Supplier 1 previously crashed!') |
| 146 |
assert False |
| 147 |
|
| 148 |
# Check the other supplier's RUV for 'replica 4' |
| 149 |
log.info('test_clean_restart: check all the suppliers have been cleaned...') |
| 150 |
clean = check_ruvs("test_clean_restart", topology_m4, m4rid) |
| 151 |
assert clean |
| 152 |
|
| 153 |
log.info('test_clean_restart PASSED, restoring supplier 4...') |
| 154 |
|
| 155 |
|
| 156 |
if __name__ == '__main__': |
| 157 |
# Run isolated |
| 158 |
# -s for DEBUG mode |
| 159 |
CURRENT_FILE = os.path.realpath(__file__) |
| 160 |
pytest.main(["-s", CURRENT_FILE]) |
| 161 |
|