| 1 |
# --- BEGIN COPYRIGHT BLOCK --- |
| 2 |
# Copyright (C) 2020 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.replica import Replicas, Replica |
| 11 |
from lib389.tasks import * |
| 12 |
from lib389.utils import * |
| 13 |
from lib389.paths import Paths |
| 14 |
from test389.topologies import topology_m2 |
| 15 |
|
| 16 |
from lib389._constants import (DEFAULT_SUFFIX, DN_CONFIG) |
| 17 |
from lib389.properties import (REPLICA_PURGE_DELAY, REPLICA_PURGE_INTERVAL) |
| 18 |
|
| 19 |
from lib389.idm.user import UserAccounts |
| 20 |
|
| 21 |
pytestmark = pytest.mark.tier2 |
| 22 |
|
| 23 |
DEBUGGING = os.getenv("DEBUGGING", default=False) |
| 24 |
if DEBUGGING: |
| 25 |
logging.getLogger(__name__).setLevel(logging.DEBUG) |
| 26 |
else: |
| 27 |
logging.getLogger(__name__).setLevel(logging.INFO) |
| 28 |
log = logging.getLogger(__name__) |
| 29 |
|
| 30 |
ds_paths = Paths() |
| 31 |
|
| 32 |
@pytest.fixture(scope="module") |
| 33 |
def topology_setup(topology_m2): |
| 34 |
"""Configure the topology with purge parameters and enable audit logging |
| 35 |
|
| 36 |
- configure replica purge delay and interval on supplier1 and supplier2 |
| 37 |
- enable audit log on supplier1 and supplier2 |
| 38 |
- restart supplier1 and supplier2 |
| 39 |
""" |
| 40 |
m1 = topology_m2.ms["supplier1"] |
| 41 |
m2 = topology_m2.ms["supplier2"] |
| 42 |
|
| 43 |
replica1 = Replicas(m1).get(DEFAULT_SUFFIX) |
| 44 |
replica2 = Replicas(m2).get(DEFAULT_SUFFIX) |
| 45 |
|
| 46 |
replica1.set('nsDS5ReplicaPurgeDelay','5') |
| 47 |
replica2.set('nsDS5ReplicaPurgeDelay','5') |
| 48 |
assert replica1.present('nsDS5ReplicaPurgeDelay') |
| 49 |
assert replica2.present('nsDS5ReplicaPurgeDelay') |
| 50 |
replica1.display_attr('nsDS5ReplicaPurgeDelay') |
| 51 |
replica2.display_attr('nsDS5ReplicaPurgeDelay') |
| 52 |
|
| 53 |
replica1.set('nsDS5ReplicaTombstonePurgeInterval', '5') |
| 54 |
replica2.set('nsDS5ReplicaTombstonePurgeInterval', '5') |
| 55 |
assert replica1.present('nsDS5ReplicaTombstonePurgeInterval') |
| 56 |
assert replica2.present('nsDS5ReplicaTombstonePurgeInterval') |
| 57 |
replica1.display_attr('nsDS5ReplicaTombstonePurgeInterval') |
| 58 |
replica2.display_attr('nsDS5ReplicaTombstonePurgeInterval') |
| 59 |
|
| 60 |
|
| 61 |
m1.config.set('nsslapd-auditlog-logging-enabled', 'on') |
| 62 |
m2.config.set('nsslapd-auditlog-logging-enabled', 'on') |
| 63 |
m1.restart() |
| 64 |
m2.restart() |
| 65 |
|
| 66 |
|
| 67 |
@pytest.mark.skipif(not ds_paths.asan_enabled, reason="Don't run if ASAN is not enabled") |
| 68 |
def test_MMR_double_free(topology_m2, topology_setup, timeout=5): |
| 69 |
"""Reproduce conditions where a double free occurs and check it does not make |
| 70 |
the server crash |
| 71 |
|
| 72 |
:id: 91580b1c-ad10-49bc-8aed-402edac59f46 |
| 73 |
:setup: replicated topology - purge delay and purge interval are configured |
| 74 |
:steps: |
| 75 |
1. create an entry on supplier1 |
| 76 |
2. modify the entry with description add |
| 77 |
3. check the entry is correctly replicated on supplier2 |
| 78 |
4. stop supplier2 |
| 79 |
5. delete the entry's description on supplier1 |
| 80 |
6. stop supplier1 |
| 81 |
7. start supplier2 |
| 82 |
8. delete the entry's description on supplier2 |
| 83 |
9. add an entry's description on supplier2 |
| 84 |
10. wait the purge delay duration |
| 85 |
11. add again an entry's description on supplier2 |
| 86 |
:expectedresults: |
| 87 |
1. entry exists on supplier1 |
| 88 |
2. modification is effective |
| 89 |
3. entry exists on supplier2 and modification is effective |
| 90 |
4. supplier2 is stopped |
| 91 |
5. description is removed from entry on supplier1 |
| 92 |
6. supplier1 is stopped |
| 93 |
7. supplier2 is started - not synchronized with supplier1 |
| 94 |
8. description is removed from entry on supplier2 (same op should be performed too by replication mecanism) |
| 95 |
9. description to entry is added on supplier2 |
| 96 |
10. Purge delay has expired - changes are erased |
| 97 |
11. description to entry is added again on supplier2 |
| 98 |
""" |
| 99 |
name = 'test_entry' |
| 100 |
|
| 101 |
entry_m1 = UserAccounts(topology_m2.ms["supplier1"], DEFAULT_SUFFIX) |
| 102 |
entry = entry_m1.create(properties={ |
| 103 |
'uid': name, |
| 104 |
'sn': name, |
| 105 |
'cn': name, |
| 106 |
'uidNumber': '1001', |
| 107 |
'gidNumber': '1001', |
| 108 |
'homeDirectory': '/home/test_entry', |
| 109 |
'userPassword': 'test_entry_pwd' |
| 110 |
}) |
| 111 |
|
| 112 |
log.info('First do an update that is replicated') |
| 113 |
entry.add('description', '5') |
| 114 |
|
| 115 |
log.info('Check the update in the replicated entry') |
| 116 |
entry_m2 = UserAccounts(topology_m2.ms["supplier2"], DEFAULT_SUFFIX) |
| 117 |
|
| 118 |
success = 0 |
| 119 |
for i in range(0, timeout): |
| 120 |
try: |
| 121 |
entry_repl = entry_m2.get(name) |
| 122 |
out = entry_repl.display_attr('description') |
| 123 |
if len(out) > 0: |
| 124 |
success = 1 |
| 125 |
break |
| 126 |
except: |
| 127 |
time.sleep(1) |
| 128 |
|
| 129 |
assert success |
| 130 |
|
| 131 |
log.info('Stop M2 so that it will not receive the next update') |
| 132 |
topology_m2.ms["supplier2"].stop(10) |
| 133 |
|
| 134 |
log.info('Perform a del operation that is not replicated') |
| 135 |
entry.remove('description', '5') |
| 136 |
|
| 137 |
log.info("Stop M1 so that it will keep del '5' that is unknown from supplier2") |
| 138 |
topology_m2.ms["supplier1"].stop(10) |
| 139 |
|
| 140 |
log.info('start M2 to do the next updates') |
| 141 |
topology_m2.ms["supplier2"].start() |
| 142 |
|
| 143 |
log.info("del 'description' by '5'") |
| 144 |
entry_repl.remove('description', '5') |
| 145 |
|
| 146 |
log.info("add 'description' by '5'") |
| 147 |
entry_repl.add('description', '5') |
| 148 |
|
| 149 |
log.info('sleep of purge delay so that the next update will purge the CSN_7') |
| 150 |
time.sleep(6) |
| 151 |
|
| 152 |
log.info("add 'description' by '6' that purge the state info") |
| 153 |
entry_repl.add('description', '6') |
| 154 |
|
| 155 |
log.info('Restart supplier1') |
| 156 |
topology_m2.ms["supplier1"].start(30) |
| 157 |
|
| 158 |
|
| 159 |
if __name__ == '__main__': |
| 160 |
# Run isolated |
| 161 |
# -s for DEBUG mode |
| 162 |
CURRENT_FILE = os.path.realpath(__file__) |
| 163 |
pytest.main("-s %s" % CURRENT_FILE) |