| 1 |
# --- BEGIN COPYRIGHT BLOCK --- |
| 2 |
# Copyright (C) 2017 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.tasks import * |
| 11 |
from lib389.utils import * |
| 12 |
|
| 13 |
from lib389.idm.user import UserAccounts, TEST_USER_PROPERTIES |
| 14 |
|
| 15 |
from lib389.replica import ReplicationManager, Replicas |
| 16 |
from lib389.agreement import Agreements |
| 17 |
from lib389.backend import Backends |
| 18 |
|
| 19 |
from test389.topologies import topology_m1c1 as topo_r # Replication |
| 20 |
from test389.topologies import topology_i2 as topo_nr # No replication |
| 21 |
from lib389.utils import ldap, os, ds_is_older, get_default_db_lib |
| 22 |
|
| 23 |
from lib389._constants import (ReplicaRole, DEFAULT_SUFFIX, REPLICAID_SUPPLIER_1, |
| 24 |
REPLICATION_BIND_DN, REPLICATION_BIND_PW, |
| 25 |
REPLICATION_BIND_METHOD, REPLICATION_TRANSPORT, DEFAULT_BACKUPDIR, |
| 26 |
RA_NAME, RA_BINDDN, RA_BINDPW, RA_METHOD, RA_TRANSPORT_PROT, |
| 27 |
defaultProperties) |
| 28 |
import json |
| 29 |
|
| 30 |
pytestmark = pytest.mark.tier1 |
| 31 |
|
| 32 |
DEBUGGING = os.getenv("DEBUGGING", default=False) |
| 33 |
if DEBUGGING: |
| 34 |
logging.getLogger(__name__).setLevel(logging.DEBUG) |
| 35 |
else: |
| 36 |
logging.getLogger(__name__).setLevel(logging.INFO) |
| 37 |
log = logging.getLogger(__name__) |
| 38 |
|
| 39 |
@pytest.mark.skipif(get_default_db_lib() != "bdb", reason="Test requires bdb files") |
| 40 |
def test_mail_attr_repl(topo_r): |
| 41 |
"""Check that no crash happens during mail attribute replication |
| 42 |
|
| 43 |
:id: 959edc84-05be-4bf9-a541-53afae482052 |
| 44 |
:customerscenario: True |
| 45 |
:setup: Replication setup with supplier and consumer instances, |
| 46 |
test user on supplier |
| 47 |
:steps: |
| 48 |
1. Check that user was replicated to consumer |
| 49 |
2. Back up mail database file |
| 50 |
3. Remove mail attribute from the user entry |
| 51 |
4. Restore mail database |
| 52 |
5. Search for the entry with a substring 'mail=user*' |
| 53 |
6. Search for the entry once again to make sure that server is alive |
| 54 |
:expectedresults: |
| 55 |
1. The user should be replicated to consumer |
| 56 |
2. Operation should be successful |
| 57 |
3. The mail attribute should be removed |
| 58 |
4. Operation should be successful |
| 59 |
5. Search should be successful |
| 60 |
6. No crash should happen |
| 61 |
""" |
| 62 |
|
| 63 |
supplier = topo_r.ms["supplier1"] |
| 64 |
consumer = topo_r.cs["consumer1"] |
| 65 |
repl = ReplicationManager(DEFAULT_SUFFIX) |
| 66 |
|
| 67 |
m_users = UserAccounts(topo_r.ms["supplier1"], DEFAULT_SUFFIX) |
| 68 |
m_user = m_users.ensure_state(properties=TEST_USER_PROPERTIES) |
| 69 |
m_user.ensure_present('mail', '[email protected]') |
| 70 |
|
| 71 |
log.info("Check that replication is working") |
| 72 |
repl.wait_for_replication(supplier, consumer) |
| 73 |
c_users = UserAccounts(topo_r.cs["consumer1"], DEFAULT_SUFFIX) |
| 74 |
c_user = c_users.get('testuser') |
| 75 |
|
| 76 |
c_bes = Backends(consumer) |
| 77 |
c_be = c_bes.get(DEFAULT_SUFFIX) |
| 78 |
|
| 79 |
db_dir = c_be.get_attr_val_utf8('nsslapd-directory') |
| 80 |
|
| 81 |
mail_db = list(filter(lambda fl: fl.startswith("mail"), os.listdir(db_dir))) |
| 82 |
assert mail_db, "mail.* wasn't found in {}" |
| 83 |
mail_db_path = os.path.join(db_dir, mail_db[0]) |
| 84 |
backup_path = os.path.join(DEFAULT_BACKUPDIR, mail_db[0]) |
| 85 |
|
| 86 |
consumer.stop() |
| 87 |
log.info("Back up {} to {}".format(mail_db_path, backup_path)) |
| 88 |
shutil.copyfile(mail_db_path, backup_path) |
| 89 |
consumer.start() |
| 90 |
|
| 91 |
log.info("Remove 'mail' attr from supplier") |
| 92 |
m_user.remove_all('mail') |
| 93 |
|
| 94 |
log.info("Wait for the replication to happen") |
| 95 |
repl.wait_for_replication(supplier, consumer) |
| 96 |
|
| 97 |
consumer.stop() |
| 98 |
log.info("Restore {} to {}".format(backup_path, mail_db_path)) |
| 99 |
shutil.copyfile(backup_path, mail_db_path) |
| 100 |
consumer.start() |
| 101 |
|
| 102 |
log.info("Make a search for mail attribute in attempt to crash server") |
| 103 |
c_user.get_attr_val("mail") |
| 104 |
|
| 105 |
log.info("Make sure that server hasn't crashed") |
| 106 |
repl.test_replication(supplier, consumer) |
| 107 |
|
| 108 |
|
| 109 |
def test_lastupdate_attr_before_init(topo_nr): |
| 110 |
"""Check that LastUpdate replica attributes show right values |
| 111 |
|
| 112 |
:id: bc8ce431-ff65-41f5-9331-605cbcaaa887 |
| 113 |
:customerscenario: True |
| 114 |
:setup: Replication setup with supplier and consumer instances |
| 115 |
without initialization |
| 116 |
:steps: |
| 117 |
1. Check nsds5replicaLastUpdateStart value |
| 118 |
2. Check nsds5replicaLastUpdateEnd value |
| 119 |
3. Check nsds5replicaLastUpdateStatus value |
| 120 |
4. Check nsds5replicaLastUpdateStatusJSON is parsable |
| 121 |
:expectedresults: |
| 122 |
1. nsds5replicaLastUpdateStart should be equal to 0 |
| 123 |
2. nsds5replicaLastUpdateEnd should be equal to 0 |
| 124 |
3. nsds5replicaLastUpdateStatus should not be equal |
| 125 |
to "Replica acquired successfully: Incremental update started" |
| 126 |
4. Success |
| 127 |
""" |
| 128 |
|
| 129 |
supplier = topo_nr.ins["standalone1"] |
| 130 |
consumer = topo_nr.ins["standalone2"] |
| 131 |
|
| 132 |
repl = ReplicationManager(DEFAULT_SUFFIX) |
| 133 |
repl.create_first_supplier(supplier) |
| 134 |
|
| 135 |
# Manually create an un-synced consumer. |
| 136 |
|
| 137 |
consumer_replicas = Replicas(consumer) |
| 138 |
consumer_replicas.create(properties={ |
| 139 |
'cn': 'replica', |
| 140 |
'nsDS5ReplicaRoot': DEFAULT_SUFFIX, |
| 141 |
'nsDS5ReplicaId': '65535', |
| 142 |
'nsDS5Flags': '0', |
| 143 |
'nsDS5ReplicaType': '2', |
| 144 |
}) |
| 145 |
|
| 146 |
agmt = repl.ensure_agreement(supplier, consumer) |
| 147 |
with pytest.raises(Exception): |
| 148 |
repl.wait_for_replication(supplier, consumer, timeout=5) |
| 149 |
|
| 150 |
assert agmt.get_attr_val_utf8('nsds5replicaLastUpdateStart') == "19700101000000Z" |
| 151 |
assert agmt.get_attr_val_utf8("nsds5replicaLastUpdateEnd") == "19700101000000Z" |
| 152 |
assert "replica acquired successfully" not in agmt.get_attr_val_utf8_l("nsds5replicaLastUpdateStatus") |
| 153 |
|
| 154 |
# make sure the JSON attribute is parsable |
| 155 |
json_status = agmt.get_attr_val_utf8("nsds5replicaLastUpdateStatusJSON") |
| 156 |
if json_status is not None: |
| 157 |
json_obj = json.loads(json_status) |
| 158 |
log.debug("JSON status message: {}".format(json_obj)) |
| 159 |
|
| 160 |
def test_total_init_operational_attr(topo_r): |
| 161 |
"""Check that operation attributes nsds5replicaLastInitStatus |
| 162 |
nsds5replicaLastInitStart and nsds5replicaLastInitEnd |
| 163 |
are preserved between restart |
| 164 |
|
| 165 |
:id: 6ba00bb1-87c0-47dd-86e0-ccf892b3985b |
| 166 |
:customerscenario: True |
| 167 |
:setup: Replication setup with supplier and consumer instances, |
| 168 |
test user on supplier |
| 169 |
:steps: |
| 170 |
1. Check that user was replicated to consumer |
| 171 |
2. Trigger a first total init |
| 172 |
3. Check status/start/end values are set on the supplier |
| 173 |
4. Restart supplier |
| 174 |
5. Check previous status/start/end values are preserved |
| 175 |
6. Trigger a second total init |
| 176 |
7. Check status/start/end values are set on the supplier |
| 177 |
8. Restart supplier |
| 178 |
9. Check previous status/start/end values are preserved |
| 179 |
10. Check status/start/end values are different between |
| 180 |
first and second total init |
| 181 |
:expectedresults: |
| 182 |
1. The user should be replicated to consumer |
| 183 |
2. Total init should be successful |
| 184 |
3. It must exist a values |
| 185 |
4. Operation should be successful |
| 186 |
5. Check values are identical before/after restart |
| 187 |
6. Total init should be successful |
| 188 |
7. It must exist a values |
| 189 |
8. Operation should be successful |
| 190 |
9. Check values are identical before/after restart |
| 191 |
10. values must differ between first/second total init |
| 192 |
""" |
| 193 |
|
| 194 |
supplier = topo_r.ms["supplier1"] |
| 195 |
consumer = topo_r.cs["consumer1"] |
| 196 |
repl = ReplicationManager(DEFAULT_SUFFIX) |
| 197 |
|
| 198 |
# Create a test user |
| 199 |
m_users = UserAccounts(topo_r.ms["supplier1"], DEFAULT_SUFFIX) |
| 200 |
m_user = m_users.ensure_state(properties=TEST_USER_PROPERTIES) |
| 201 |
m_user.ensure_present('mail', '[email protected]') |
| 202 |
|
| 203 |
# Then check it is replicated |
| 204 |
log.info("Check that replication is working") |
| 205 |
repl.wait_for_replication(supplier, consumer) |
| 206 |
c_users = UserAccounts(topo_r.cs["consumer1"], DEFAULT_SUFFIX) |
| 207 |
c_user = c_users.get('testuser') |
| 208 |
assert c_user |
| 209 |
|
| 210 |
# Retrieve the replication agreement S1->C1 |
| 211 |
replica_supplier = Replicas(supplier).get(DEFAULT_SUFFIX) |
| 212 |
agmts_supplier = Agreements(supplier, replica_supplier.dn) |
| 213 |
supplier_consumer = None |
| 214 |
for agmt in agmts_supplier.list(): |
| 215 |
if (agmt.get_attr_val_utf8('nsDS5ReplicaPort') == str(consumer.port) and |
| 216 |
agmt.get_attr_val_utf8('nsDS5ReplicaHost') == consumer.host): |
| 217 |
supplier_consumer = agmt |
| 218 |
break |
| 219 |
assert supplier_consumer |
| 220 |
|
| 221 |
# Trigger a first total init and check that |
| 222 |
# start/end/status is updated AND preserved during a restart |
| 223 |
log.info("First total init") |
| 224 |
supplier_consumer.begin_reinit() |
| 225 |
(done, error) = supplier_consumer.wait_reinit() |
| 226 |
assert done is True |
| 227 |
|
| 228 |
status_1 = supplier_consumer.get_attr_val_utf8("nsds5replicaLastInitStatus") |
| 229 |
assert status_1 |
| 230 |
|
| 231 |
initStart_1 = supplier_consumer.get_attr_val_utf8("nsds5replicaLastInitStart") |
| 232 |
assert initStart_1 |
| 233 |
|
| 234 |
initEnd_1 = supplier_consumer.get_attr_val_utf8("nsds5replicaLastInitEnd") |
| 235 |
assert initEnd_1 |
| 236 |
|
| 237 |
log.info("Check values from first total init are preserved") |
| 238 |
supplier.restart() |
| 239 |
post_restart_status_1 = supplier_consumer.get_attr_val_utf8("nsds5replicaLastInitStatus") |
| 240 |
assert post_restart_status_1 |
| 241 |
assert post_restart_status_1 == status_1 |
| 242 |
|
| 243 |
post_restart_initStart_1 = supplier_consumer.get_attr_val_utf8("nsds5replicaLastInitStart") |
| 244 |
assert post_restart_initStart_1 |
| 245 |
assert post_restart_initStart_1 == initStart_1 |
| 246 |
|
| 247 |
post_restart_initEnd_1 = supplier_consumer.get_attr_val_utf8("nsds5replicaLastInitEnd") |
| 248 |
assert post_restart_initEnd_1 == initEnd_1 |
| 249 |
|
| 250 |
# Trigger a second total init and check that |
| 251 |
# start/end/status is updated (differ from previous values) |
| 252 |
# AND new values are preserved during a restart |
| 253 |
time.sleep(1) |
| 254 |
log.info("Second total init") |
| 255 |
supplier_consumer.begin_reinit() |
| 256 |
(done, error) = supplier_consumer.wait_reinit() |
| 257 |
assert done is True |
| 258 |
|
| 259 |
status_2 = supplier_consumer.get_attr_val_utf8("nsds5replicaLastInitStatus") |
| 260 |
assert status_2 |
| 261 |
|
| 262 |
initStart_2 = supplier_consumer.get_attr_val_utf8("nsds5replicaLastInitStart") |
| 263 |
assert initStart_2 |
| 264 |
|
| 265 |
initEnd_2 = supplier_consumer.get_attr_val_utf8("nsds5replicaLastInitEnd") |
| 266 |
assert initEnd_2 |
| 267 |
|
| 268 |
log.info("Check values from second total init are preserved") |
| 269 |
supplier.restart() |
| 270 |
post_restart_status_2 = supplier_consumer.get_attr_val_utf8("nsds5replicaLastInitStatus") |
| 271 |
assert post_restart_status_2 |
| 272 |
assert post_restart_status_2 == status_2 |
| 273 |
|
| 274 |
post_restart_initStart_2 = supplier_consumer.get_attr_val_utf8("nsds5replicaLastInitStart") |
| 275 |
assert post_restart_initStart_2 |
| 276 |
assert post_restart_initStart_2 == initStart_2 |
| 277 |
|
| 278 |
post_restart_initEnd_2 = supplier_consumer.get_attr_val_utf8("nsds5replicaLastInitEnd") |
| 279 |
assert post_restart_initEnd_2 == initEnd_2 |
| 280 |
|
| 281 |
# Check that values are updated by total init |
| 282 |
log.info("Check values from first/second total init are different") |
| 283 |
assert status_2 == status_1 |
| 284 |
assert initStart_2 != initStart_1 |
| 285 |
assert initEnd_2 != initEnd_1 |
| 286 |
|
| 287 |
if __name__ == '__main__': |
| 288 |
# Run isolated |
| 289 |
# -s for DEBUG mode |
| 290 |
CURRENT_FILE = os.path.realpath(__file__) |
| 291 |
pytest.main("-s %s" % CURRENT_FILE) |