| 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 |
from lib389.config import CertmapLegacy |
| 18 |
from lib389.idm.services import ServiceAccounts |
| 19 |
|
| 20 |
log = logging.getLogger(__name__) |
| 21 |
|
| 22 |
|
| 23 |
def test_clean_shutdown_crash(topology_m2): |
| 24 |
"""Check that server didn't crash after shutdown when running CleanAllRUV task |
| 25 |
|
| 26 |
:id: c34d0b40-3c3e-4f53-8656-5e4c2a310aaf |
| 27 |
:setup: Replication setup with two suppliers |
| 28 |
:steps: |
| 29 |
1. Enable TLS on both suppliers |
| 30 |
2. Reconfigure both agreements to use TLS Client auth |
| 31 |
3. Stop supplier2 |
| 32 |
4. Run the CleanAllRUV task |
| 33 |
5. Restart supplier1 |
| 34 |
6. Check if supplier1 didn't crash |
| 35 |
7. Restart supplier1 again |
| 36 |
8. Check if supplier1 didn't crash |
| 37 |
|
| 38 |
:expectedresults: |
| 39 |
1. Success |
| 40 |
2. Success |
| 41 |
3. Success |
| 42 |
4. Success |
| 43 |
5. Success |
| 44 |
6. Success |
| 45 |
7. Success |
| 46 |
8. Success |
| 47 |
""" |
| 48 |
|
| 49 |
m1 = topology_m2.ms["supplier1"] |
| 50 |
m2 = topology_m2.ms["supplier2"] |
| 51 |
|
| 52 |
repl = ReplicationManager(DEFAULT_SUFFIX) |
| 53 |
|
| 54 |
cm_m1 = CertmapLegacy(m1) |
| 55 |
cm_m2 = CertmapLegacy(m2) |
| 56 |
|
| 57 |
certmaps = cm_m1.list() |
| 58 |
certmaps['default']['DNComps'] = None |
| 59 |
certmaps['default']['CmapLdapAttr'] = 'nsCertSubjectDN' |
| 60 |
|
| 61 |
cm_m1.set(certmaps) |
| 62 |
cm_m2.set(certmaps) |
| 63 |
|
| 64 |
log.info('Enabling TLS') |
| 65 |
[i.enable_tls() for i in topology_m2] |
| 66 |
|
| 67 |
log.info('Creating replication dns') |
| 68 |
services = ServiceAccounts(m1, DEFAULT_SUFFIX) |
| 69 |
repl_m1 = services.get(f'{DEFAULT_SUFFIX}:{m1.host}:{m1.sslport}') |
| 70 |
repl_m1.set('nsCertSubjectDN', m1.get_server_tls_subject()) |
| 71 |
|
| 72 |
repl_m2 = services.get(f'{DEFAULT_SUFFIX}:{m2.host}:{m2.sslport}') |
| 73 |
repl_m2.set('nsCertSubjectDN', m2.get_server_tls_subject()) |
| 74 |
|
| 75 |
log.info('Changing auth type') |
| 76 |
replica_m1 = Replicas(m1).get(DEFAULT_SUFFIX) |
| 77 |
agmt_m1 = replica_m1.get_agreements().list()[0] |
| 78 |
agmt_m1.replace_many( |
| 79 |
('nsDS5ReplicaBindMethod', 'SSLCLIENTAUTH'), |
| 80 |
('nsDS5ReplicaTransportInfo', 'SSL'), |
| 81 |
('nsDS5ReplicaPort', '%s' % m2.sslport), |
| 82 |
) |
| 83 |
|
| 84 |
agmt_m1.remove_all('nsDS5ReplicaBindDN') |
| 85 |
|
| 86 |
replica_m2 = Replicas(m2).get(DEFAULT_SUFFIX) |
| 87 |
agmt_m2 = replica_m2.get_agreements().list()[0] |
| 88 |
|
| 89 |
agmt_m2.replace_many( |
| 90 |
('nsDS5ReplicaBindMethod', 'SSLCLIENTAUTH'), |
| 91 |
('nsDS5ReplicaTransportInfo', 'SSL'), |
| 92 |
('nsDS5ReplicaPort', '%s' % m1.sslport), |
| 93 |
) |
| 94 |
agmt_m2.remove_all('nsDS5ReplicaBindDN') |
| 95 |
|
| 96 |
log.info('Stopping supplier2') |
| 97 |
m2.stop() |
| 98 |
|
| 99 |
log.info('Run the cleanAllRUV task') |
| 100 |
cruv_task = CleanAllRUVTask(m1) |
| 101 |
cruv_task.create(properties={ |
| 102 |
'replica-id': repl.get_rid(m1), |
| 103 |
'replica-base-dn': DEFAULT_SUFFIX, |
| 104 |
'replica-force-cleaning': 'no', |
| 105 |
'replica-certify-all': 'yes' |
| 106 |
}) |
| 107 |
|
| 108 |
m1.restart() |
| 109 |
|
| 110 |
log.info('Check if supplier1 crashed') |
| 111 |
assert not m1.detectDisorderlyShutdown() |
| 112 |
|
| 113 |
log.info('Repeat') |
| 114 |
m1.restart() |
| 115 |
assert not m1.detectDisorderlyShutdown() |
| 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 |
|