| 1 |
# --- BEGIN COPYRIGHT BLOCK --- |
| 2 |
# Copyright (C) 2018 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 |
|
| 10 |
import os, shutil, time, pytest, re, pwd, grp |
| 11 |
from lib389.tasks import * |
| 12 |
from lib389.utils import * |
| 13 |
from test389.topologies import topology_m4 as topo_m4 |
| 14 |
from lib389.replica import * |
| 15 |
from lib389.idm.user import UserAccounts, UserAccount |
| 16 |
from lib389.agreement import * |
| 17 |
from contextlib import suppress |
| 18 |
|
| 19 |
pytestmark = pytest.mark.tier2 |
| 20 |
|
| 21 |
@pytest.fixture(scope="function") |
| 22 |
def _cleanupentris(request, topo_m4): |
| 23 |
users = UserAccounts(topo_m4.ms["supplier1"], DEFAULT_SUFFIX) |
| 24 |
for i in range(10): users.create_test_user(uid=i) |
| 25 |
|
| 26 |
def fin(): |
| 27 |
try: |
| 28 |
for i in users.list(): |
| 29 |
i.delete() |
| 30 |
except: pass |
| 31 |
request.addfinalizer(fin) |
| 32 |
|
| 33 |
|
| 34 |
def test_verify_trees(topo_m4): |
| 35 |
"""All 4 suppliers should have consistent data |
| 36 |
|
| 37 |
:id: 01733ef8-e764-11e8-98f3-8c16451d917b |
| 38 |
:setup: 4 Instances with replication |
| 39 |
:steps: |
| 40 |
1. All 4 suppliers should have consistent data now |
| 41 |
:expectedresults: |
| 42 |
1. Should success |
| 43 |
""" |
| 44 |
# all 4 suppliers should have consistent data now |
| 45 |
repl = ReplicationManager(DEFAULT_SUFFIX) |
| 46 |
repl.test_replication( |
| 47 |
topo_m4.ms["supplier1"], topo_m4.ms["supplier2"], 30 |
| 48 |
) |
| 49 |
repl.test_replication( |
| 50 |
topo_m4.ms["supplier1"], topo_m4.ms["supplier3"], 30 |
| 51 |
) |
| 52 |
repl.test_replication( |
| 53 |
topo_m4.ms["supplier1"], topo_m4.ms["supplier4"], 30 |
| 54 |
) |
| 55 |
|
| 56 |
|
| 57 |
def test_sync_through_to_all_4_suppliers(topo_m4, _cleanupentris): |
| 58 |
"""Insert fresh data into Supplier 2 - about 10 entries |
| 59 |
|
| 60 |
:id: 10917e04-e764-11e8-8367-8c16451d917b |
| 61 |
:setup: 4 Instances with replication |
| 62 |
:steps: |
| 63 |
1. Insert fresh data into M2 - about 100 entries |
| 64 |
2. Begin verification process |
| 65 |
:expectedresults: |
| 66 |
1. Should success |
| 67 |
2. Should success |
| 68 |
""" |
| 69 |
# Insert fresh data into M2 - about 100 entries |
| 70 |
# Wait for a minute for data to sync through to all 4 suppliers |
| 71 |
# Begin verification process |
| 72 |
repl = ReplicationManager(DEFAULT_SUFFIX) |
| 73 |
repl.test_replication( |
| 74 |
topo_m4.ms["supplier1"], topo_m4.ms["supplier2"], 30 |
| 75 |
) |
| 76 |
repl.test_replication( |
| 77 |
topo_m4.ms["supplier1"], topo_m4.ms["supplier3"], 30 |
| 78 |
) |
| 79 |
repl.test_replication( |
| 80 |
topo_m4.ms["supplier1"], topo_m4.ms["supplier4"], 30 |
| 81 |
) |
| 82 |
|
| 83 |
|
| 84 |
def test_modify_some_data_in_m3(topo_m4): |
| 85 |
"""Modify some data in Supplier 3 , check trees on all 4 suppliers |
| 86 |
|
| 87 |
:id: 33583ff4-e764-11e8-8491-8c16451d917b |
| 88 |
:setup: 4 Instances with replication |
| 89 |
:steps: |
| 90 |
1. Modify some data in M3 , wait for 20 seconds ,check trees on all 4 suppliers |
| 91 |
:expectedresults: |
| 92 |
1. Should success |
| 93 |
""" |
| 94 |
# modify some data in M3 |
| 95 |
# wait for 20 seconds |
| 96 |
# check trees on all 4 suppliers |
| 97 |
users = UserAccounts(topo_m4.ms["supplier3"], DEFAULT_SUFFIX) |
| 98 |
repl = ReplicationManager(DEFAULT_SUFFIX) |
| 99 |
for i in range(15, 20): |
| 100 |
users.create_test_user(uid=i) |
| 101 |
time.sleep(1) |
| 102 |
for i in range(15, 20):users.list()[19-i].set("description", "description for user{} CHANGED".format(i)) |
| 103 |
repl.test_replication( |
| 104 |
topo_m4.ms["supplier3"], topo_m4.ms["supplier1"], 30 |
| 105 |
) |
| 106 |
repl.test_replication( |
| 107 |
topo_m4.ms["supplier3"], topo_m4.ms["supplier2"], 30 |
| 108 |
) |
| 109 |
repl.test_replication( |
| 110 |
topo_m4.ms["supplier3"], topo_m4.ms["supplier4"], 30 |
| 111 |
) |
| 112 |
for i in users.list(): |
| 113 |
i.delete() |
| 114 |
|
| 115 |
|
| 116 |
def test_delete_a_few_entries_in_m4(topo_m4, _cleanupentris): |
| 117 |
"""Delete a few entries in Supplier 4 , verify trees. |
| 118 |
|
| 119 |
:id: 6ea94d78-e764-11e8-987f-8c16451d917b |
| 120 |
:setup: 4 Instances with replication |
| 121 |
:steps: |
| 122 |
1. Delete a few entries in M4 , |
| 123 |
2. Wait for 60 seconds for them to propagate, |
| 124 |
3. Verify trees |
| 125 |
:expectedresults: |
| 126 |
1. Should success |
| 127 |
2. Should success |
| 128 |
3. Should success |
| 129 |
""" |
| 130 |
# delete a few entries in M4 |
| 131 |
# wait for 60 seconds for them to propagate |
| 132 |
# verify trees |
| 133 |
users = UserAccounts(topo_m4.ms["supplier1"], DEFAULT_SUFFIX) |
| 134 |
repl = ReplicationManager(DEFAULT_SUFFIX) |
| 135 |
repl.wait_for_replication(topo_m4.ms["supplier4"], topo_m4.ms["supplier1"]) |
| 136 |
for i in users.list(): |
| 137 |
i.delete() |
| 138 |
repl.test_replication( |
| 139 |
topo_m4.ms["supplier4"], topo_m4.ms["supplier1"], 30 |
| 140 |
) |
| 141 |
repl.test_replication( |
| 142 |
topo_m4.ms["supplier4"], topo_m4.ms["supplier2"], 30 |
| 143 |
) |
| 144 |
repl.test_replication( |
| 145 |
topo_m4.ms["supplier4"], topo_m4.ms["supplier3"], 30 |
| 146 |
) |
| 147 |
|
| 148 |
def test_replicated_multivalued_entries(topo_m4): |
| 149 |
"""Replicated multivalued entries are ordered the same way on all consumers |
| 150 |
|
| 151 |
:id: 7bf9a34c-e764-11e8-928c-8c16451d917b |
| 152 |
:setup: 4 Instances with replication |
| 153 |
:steps: |
| 154 |
1. Replicated multivalued entries are ordered the same way on all consumers |
| 155 |
:expectedresults: |
| 156 |
1. Should success |
| 157 |
""" |
| 158 |
# This test case checks that replicated multivalued entries are |
| 159 |
# ordered the same way on all consumers |
| 160 |
users = UserAccounts(topo_m4.ms["supplier1"], DEFAULT_SUFFIX) |
| 161 |
repl = ReplicationManager(DEFAULT_SUFFIX) |
| 162 |
user_properties = { |
| 163 |
"uid": "test_replicated_multivalued_entries", |
| 164 |
"cn": "test_replicated_multivalued_entries", |
| 165 |
"sn": "test_replicated_multivalued_entries", |
| 166 |
"userpassword": "test_replicated_multivalued_entries", |
| 167 |
"uidNumber": "1001", |
| 168 |
"gidNumber": "2002", |
| 169 |
"homeDirectory": "/home/{}".format("test_replicated_multivalued_entries"), |
| 170 |
} |
| 171 |
users.create(properties=user_properties) |
| 172 |
testuser = users.get("test_replicated_multivalued_entries") |
| 173 |
testuser.set("mail", ["test1", "test2", "test3"]) |
| 174 |
# Now we check the entry on each consumer, making sure the order of the |
| 175 |
# multi-valued mail attribute is the same on all server instances |
| 176 |
# Make sure the entry has been replicated everywhere |
| 177 |
repl.wait_for_replication(topo_m4.ms["supplier1"], topo_m4.ms["supplier2"]) |
| 178 |
repl.wait_for_replication(topo_m4.ms["supplier1"], topo_m4.ms["supplier3"]) |
| 179 |
repl.wait_for_replication(topo_m4.ms["supplier1"], topo_m4.ms["supplier4"]) |
| 180 |
assert topo_m4.ms["supplier1"].search_s("uid=test_replicated_multivalued_entries,ou=People,dc=example,dc=com", |
| 181 |
ldap.SCOPE_SUBTREE, '(objectclass=*)', ['mail']) == topo_m4.ms[ |
| 182 |
"supplier2"].search_s("uid=test_replicated_multivalued_entries,ou=People,dc=example,dc=com", |
| 183 |
ldap.SCOPE_SUBTREE, '(objectclass=*)', ['mail']) == topo_m4.ms["supplier3"].search_s( |
| 184 |
"uid=test_replicated_multivalued_entries,ou=People,dc=example,dc=com", ldap.SCOPE_SUBTREE, '(objectclass=*)', |
| 185 |
['mail']) == topo_m4.ms["supplier4"].search_s( |
| 186 |
"uid=test_replicated_multivalued_entries,ou=People,dc=example,dc=com", ldap.SCOPE_SUBTREE, '(objectclass=*)', |
| 187 |
['mail']) |
| 188 |
|
| 189 |
|
| 190 |
def test_bad_replication_agreement(topo_m4): |
| 191 |
"""Create the bad replication agreement and try to add it |
| 192 |
|
| 193 |
:id: 9cf3daf4-e764-11e8-a132-8c16451d917b |
| 194 |
:setup: 4 Instances with replication |
| 195 |
:steps: |
| 196 |
1. Create the bad replication agreement and try to add it |
| 197 |
:expectedresults: |
| 198 |
1. Should not success |
| 199 |
""" |
| 200 |
# The return code for adding a bad replication agreement to the directory server is now |
| 201 |
# correct. Check that the return code is zero ( unsuccessful ). What used to happen is |
| 202 |
# the directory server would not give the correct non-zero return code, add the bad replication |
| 203 |
# agreement and then core dump. |
| 204 |
# Stop the server and backup the dse.ldif so it can be restored later |
| 205 |
for inst in topo_m4: inst.stop() |
| 206 |
for i in range(1, 5): |
| 207 |
if os.path.exists( |
| 208 |
topo_m4.ms["supplier{}".format(i)].confdir |
| 209 |
+ "/dse_test_bug157377.ldif" |
| 210 |
): |
| 211 |
os.remove( |
| 212 |
topo_m4.ms["supplier{}".format(i)].confdir |
| 213 |
+ "/dse_test_bug157377.ldif" |
| 214 |
) |
| 215 |
shutil.copy( |
| 216 |
topo_m4.ms["supplier{}".format(i)].confdir + "/dse.ldif", |
| 217 |
topo_m4.ms["supplier{}".format(i)].confdir |
| 218 |
+ "/dse_test_bug157377.ldif", |
| 219 |
) |
| 220 |
with suppress(PermissionError): |
| 221 |
os.chown('{}/dse_test_bug157377.ldif'.format(topo_m4.all_insts.get('supplier{}'.format(i)).confdir), |
| 222 |
pwd.getpwnam('dirsrv').pw_uid, grp.getgrnam('dirsrv').gr_gid) |
| 223 |
for i in ["supplier1", "supplier2", "supplier3", "supplier4"]: |
| 224 |
topo_m4.all_insts.get(i).start() |
| 225 |
# Create the bad replication agreement and try to add it |
| 226 |
# Its a agreement as Missing replica host and port information makes for a bad agreement. |
| 227 |
properties = { |
| 228 |
"basedn": "cn=Ze_bad_agreeemnt,cn=replica,cn=dc\=example\,dc\=com,cn=mapping tree,cn=config", |
| 229 |
"objectclass": ["top", "nsds5replicationagreement"], |
| 230 |
"cn": "Ze_bad_agreement", |
| 231 |
"nsds5replicabinddn": "{},{}".format("cn=replication manager", "o=fr"), |
| 232 |
"nsds5replicabindmethod": "SIMPLE", |
| 233 |
"nsds5replicaroot": DEFAULT_SUFFIX, |
| 234 |
"description": "Ze_bad_agreement", |
| 235 |
"nsds5replicacredentials": "Secret123", |
| 236 |
} |
| 237 |
for i in ["supplier1", "supplier2", "supplier3", "supplier4"]: |
| 238 |
with pytest.raises(ldap.UNWILLING_TO_PERFORM): |
| 239 |
Agreement(topo_m4.all_insts.get("{}".format(i))).create( |
| 240 |
properties=properties |
| 241 |
) |
| 242 |
for inst in topo_m4: inst.stop() |
| 243 |
# Now retore the original dse.ldif |
| 244 |
for i in range(1, 5): |
| 245 |
shutil.copy( |
| 246 |
topo_m4.ms["supplier{}".format(i)].confdir |
| 247 |
+ "/dse_test_bug157377.ldif", |
| 248 |
topo_m4.ms["supplier{}".format(i)].confdir + "/dse.ldif", |
| 249 |
) |
| 250 |
with suppress(PermissionError): |
| 251 |
os.chown('{}/dse_test_bug157377.ldif'.format(topo_m4.all_insts.get('supplier{}'.format(i)).confdir), |
| 252 |
pwd.getpwnam('dirsrv').pw_uid, grp.getgrnam('dirsrv').gr_gid) |
| 253 |
for inst in topo_m4: inst.start() |
| 254 |
|
| 255 |
|
| 256 |
def test_nsds5replicaenabled_verify(topo_m4): |
| 257 |
"""Add the attribute nsds5ReplicaEnabled to cn=config |
| 258 |
|
| 259 |
:id: ba6dd634-e764-11e8-b158-8c16451d917b |
| 260 |
:setup: 4 Instances with replication |
| 261 |
:steps: |
| 262 |
1. Add the attribute nsds5ReplicaEnabled to cn=config |
| 263 |
2. Add data |
| 264 |
3. Delete data |
| 265 |
4. Very the replication |
| 266 |
:expectedresults: |
| 267 |
1. Should success |
| 268 |
2. Should success |
| 269 |
3. Should success |
| 270 |
4. Should success |
| 271 |
""" |
| 272 |
# Add the attribute nsds5ReplicaEnabled to cn=config |
| 273 |
# Stop M3 and M4 instances, as not required for this test |
| 274 |
repl = ReplicationManager(DEFAULT_SUFFIX) |
| 275 |
for i in ["supplier3", "supplier4"]: |
| 276 |
topo_m4.all_insts.get(i).stop() |
| 277 |
# Adding nsds5ReplicaEnabled to M1 |
| 278 |
topo_m4.ms["supplier1"].modify_s( |
| 279 |
topo_m4.ms["supplier1"].agreement.list(suffix=DEFAULT_SUFFIX)[0].dn, |
| 280 |
[(ldap.MOD_ADD, "nsds5ReplicaEnabled", b"on")], |
| 281 |
) |
| 282 |
topo_m4.ms["supplier1"].modify_s( |
| 283 |
topo_m4.ms["supplier1"].agreement.list(suffix=DEFAULT_SUFFIX)[0].dn, |
| 284 |
[(ldap.MOD_REPLACE, "nsds5ReplicaEnabled", b"off")], |
| 285 |
) |
| 286 |
# Adding data to Supplier1 |
| 287 |
users = UserAccounts(topo_m4.ms["supplier1"], DEFAULT_SUFFIX) |
| 288 |
user_properties = { |
| 289 |
"uid": "test_bug834074", |
| 290 |
"cn": "test_bug834074", |
| 291 |
"sn": "test_bug834074", |
| 292 |
"userpassword": "test_bug834074", |
| 293 |
"uidNumber": "1000", |
| 294 |
"gidNumber": "2000", |
| 295 |
"homeDirectory": "/home/{}".format("test_bug834074"), |
| 296 |
} |
| 297 |
users.create(properties=user_properties) |
| 298 |
test_user_very = users.get("test_bug834074").dn |
| 299 |
# No replication no data in Supplier2 |
| 300 |
with pytest.raises(Exception): |
| 301 |
repl.wait_for_replication(topo_m4.ms["supplier1"], topo_m4.ms["supplier2"]) |
| 302 |
# Replication on |
| 303 |
topo_m4.ms["supplier1"].modify_s( |
| 304 |
topo_m4.ms["supplier1"].agreement.list(suffix=DEFAULT_SUFFIX)[0].dn, |
| 305 |
[(ldap.MOD_REPLACE, "nsds5ReplicaEnabled", b"on")], |
| 306 |
) |
| 307 |
repl.wait_for_replication(topo_m4.ms["supplier1"], topo_m4.ms["supplier2"]) |
| 308 |
# Now data is available on supplier2 |
| 309 |
assert len(topo_m4.ms['supplier2'].search_s(test_user_very, ldap.SCOPE_SUBTREE, 'objectclass=*')) == 1 |
| 310 |
## Stop replication to supplier2 |
| 311 |
topo_m4.ms["supplier1"].modify_s( |
| 312 |
topo_m4.ms["supplier1"].agreement.list(suffix=DEFAULT_SUFFIX)[0].dn, |
| 313 |
[(ldap.MOD_REPLACE, "nsds5ReplicaEnabled", b"off")], |
| 314 |
) |
| 315 |
# Modify some data in supplier1 |
| 316 |
topo_m4.ms["supplier1"].modrdn_s(test_user_very, 'uid=test_bug834075', 1) |
| 317 |
with pytest.raises(Exception): |
| 318 |
repl.wait_for_replication(topo_m4.ms["supplier1"], topo_m4.ms["supplier2"]) |
| 319 |
# changes are not replicated in supplier2 |
| 320 |
with pytest.raises(Exception): topo_m4.ms['supplier2'].search_s( |
| 321 |
'uid=test_bug834075,ou=People,{}'.format(DEFAULT_SUFFIX), ldap.SCOPE_SUBTREE, 'objectclass=*') |
| 322 |
# Turn on the replication |
| 323 |
topo_m4.ms["supplier1"].modify_s( |
| 324 |
topo_m4.ms["supplier1"].agreement.list(suffix=DEFAULT_SUFFIX)[0].dn, |
| 325 |
[(ldap.MOD_REPLACE, "nsds5ReplicaEnabled", b"on")], |
| 326 |
) |
| 327 |
repl.wait_for_replication(topo_m4.ms["supplier1"], topo_m4.ms["supplier2"]) |
| 328 |
# Now same data is available in supplier2 |
| 329 |
assert len( |
| 330 |
topo_m4.ms['supplier2'].search_s('uid=test_bug834075,ou=People,{}'.format(DEFAULT_SUFFIX), ldap.SCOPE_SUBTREE, |
| 331 |
'objectclass=*')) == 1 |
| 332 |
# Turn off the replication from supplier1 to supplier2 |
| 333 |
topo_m4.ms["supplier1"].modify_s( |
| 334 |
topo_m4.ms["supplier1"].agreement.list(suffix=DEFAULT_SUFFIX)[0].dn, |
| 335 |
[(ldap.MOD_REPLACE, "nsds5ReplicaEnabled", b"off")], |
| 336 |
) |
| 337 |
# delete some data in supplier1 |
| 338 |
topo_m4.ms["supplier1"].delete_s( |
| 339 |
'uid=test_bug834075,ou=People,{}'.format(DEFAULT_SUFFIX) |
| 340 |
) |
| 341 |
with pytest.raises(Exception): |
| 342 |
repl.wait_for_replication(topo_m4.ms["supplier1"], topo_m4.ms["supplier2"]) |
| 343 |
# deleted data from supplier1 is still there in supplier2 as repliaction is off |
| 344 |
assert len( |
| 345 |
topo_m4.ms['supplier2'].search_s('uid=test_bug834075,ou=People,{}'.format(DEFAULT_SUFFIX), ldap.SCOPE_SUBTREE, |
| 346 |
'objectclass=*')) == 1 |
| 347 |
topo_m4.ms["supplier1"].modify_s( |
| 348 |
topo_m4.ms["supplier1"].agreement.list(suffix=DEFAULT_SUFFIX)[0].dn, |
| 349 |
[(ldap.MOD_REPLACE, "nsds5ReplicaEnabled", b"on")], |
| 350 |
) |
| 351 |
repl.wait_for_replication(topo_m4.ms["supplier1"], topo_m4.ms["supplier2"]) |
| 352 |
# After repliction is on same is gone from supplier2 also. |
| 353 |
with pytest.raises(ldap.NO_SUCH_OBJECT): |
| 354 |
topo_m4.ms['supplier2'].search_s('uid=test_bug834075,ou=People,{}'.format(DEFAULT_SUFFIX), ldap.SCOPE_SUBTREE, |
| 355 |
'objectclass=*') |
| 356 |
with pytest.raises(ldap.OPERATIONS_ERROR): |
| 357 |
topo_m4.ms["supplier1"].modify_s( |
| 358 |
topo_m4.ms["supplier1"] |
| 359 |
.agreement.list(suffix=DEFAULT_SUFFIX)[0] |
| 360 |
.dn, |
| 361 |
[(ldap.MOD_REPLACE, "nsds5ReplicaEnabled", b"invalid")], |
| 362 |
) |
| 363 |
for i in ["supplier3", "supplier4"]: |
| 364 |
topo_m4.all_insts.get(i).start() |
| 365 |
|
| 366 |
|
| 367 |
def test_create_an_entry_on_the_supplier(topo_m4): |
| 368 |
"""Shut down one instance and create an entry on the supplier |
| 369 |
|
| 370 |
:id: f57538d0-e764-11e8-94fc-8c16451d917b |
| 371 |
:setup: standalone |
| 372 |
:steps: |
| 373 |
1. Shut down one instance and create an entry on the supplier |
| 374 |
:expectedresults: |
| 375 |
1. Should not success |
| 376 |
""" |
| 377 |
# Bug 830344: Shut down one instance and create an entry on the supplier |
| 378 |
topo_m4.ms["supplier1"].stop() |
| 379 |
users = UserAccounts(topo_m4.ms["supplier2"], DEFAULT_SUFFIX) |
| 380 |
users.create_test_user(uid=4) |
| 381 |
# ldapsearch output |
| 382 |
assert \ |
| 383 |
topo_m4.ms["supplier2"].search_s('cn=replica,cn="dc=example,dc=com",cn=mapping tree,cn=config', ldap.SCOPE_SUBTREE, |
| 384 |
"(objectclass=*)", ["nsds5replicaLastUpdateStatus"], )[1].getValue( |
| 385 |
'nsds5replicalastupdatestatus') |
| 386 |
topo_m4.ms["supplier1"].start() |
| 387 |
|
| 388 |
|
| 389 |
def test_bob_acceptance_tests(topo_m4): |
| 390 |
"""Run multiple modrdn_s operation on supplier1 |
| 391 |
|
| 392 |
:id: 26eb87f2-e765-11e8-9698-8c16451d917b |
| 393 |
:setup: standalone |
| 394 |
:steps: |
| 395 |
1. Add entry |
| 396 |
2. Run multiple modrdn_s operation on supplier1 |
| 397 |
3. Check everything is fine. |
| 398 |
:expectedresults: |
| 399 |
1. Should success |
| 400 |
2. Should success |
| 401 |
3. Should success |
| 402 |
""" |
| 403 |
# Bug description: run BOB acceptance tests...but it may be not systematic |
| 404 |
# Testing bug #923502: Crash in MODRDN |
| 405 |
users = UserAccounts(topo_m4.ms["supplier1"], DEFAULT_SUFFIX) |
| 406 |
repl = ReplicationManager(DEFAULT_SUFFIX) |
| 407 |
users.create_test_user() |
| 408 |
users.create_test_user(uid=2) |
| 409 |
# 2*30 MORDRDN looks enough |
| 410 |
for _ in range(30): |
| 411 |
topo_m4.ms["supplier1"].modrdn_s("uid=test_user_1000,ou=People,{}".format(DEFAULT_SUFFIX), "uid=userB", 1) |
| 412 |
topo_m4.ms["supplier1"].modrdn_s("uid=userB,ou=People,{}".format(DEFAULT_SUFFIX), "uid=test_user_1000", 1) |
| 413 |
repl.wait_for_replication(topo_m4.ms["supplier1"], topo_m4.ms["supplier2"]) |
| 414 |
|
| 415 |
# 2*30 MORDRDN looks enough |
| 416 |
for i in range(30): |
| 417 |
topo_m4.ms["supplier2"].modrdn_s("uid=test_user_2,ou=People,{}".format(DEFAULT_SUFFIX), "uid=userB", 1) |
| 418 |
topo_m4.ms["supplier2"].modrdn_s("uid=userB,ou=People,{}".format(DEFAULT_SUFFIX), "uid=test_user_2", 1) |
| 419 |
assert topo_m4.ms["supplier1"].status() == True |
| 420 |
assert topo_m4.ms["supplier2"].status() == True |
| 421 |
|
| 422 |
# Now make sure replication is in-sync to prevent impacting |
| 423 |
# the following testcases |
| 424 |
repl.wait_for_replication(topo_m4.ms["supplier1"], topo_m4.ms["supplier2"]) |
| 425 |
repl.wait_for_replication(topo_m4.ms["supplier2"], topo_m4.ms["supplier1"]) |
| 426 |
|
| 427 |
|
| 428 |
def list_agmt_towards(topo_m4, serverid): |
| 429 |
# Note: all instances must be started to use that. |
| 430 |
res = [] |
| 431 |
for inst in topo_m4: |
| 432 |
for agmt in Agreements(inst).list(): |
| 433 |
if agmt.get_attr_val_int(AGMT_PORT) == topo_m4.ms[serverid].port: |
| 434 |
res.append(agmt) |
| 435 |
return res |
| 436 |
|
| 437 |
|
| 438 |
def test_replica_backup_and_restore(topo_m4): |
| 439 |
"""Test Backup and restore |
| 440 |
|
| 441 |
:id: 5ad1b85c-e765-11e8-9668-8c16451d917b |
| 442 |
:setup: standalone |
| 443 |
:steps: |
| 444 |
1. Add entries |
| 445 |
2. Take backup db2ldif on supplier1 |
| 446 |
3. Delete entries on supplier1 |
| 447 |
4. Restore entries ldif2db |
| 448 |
5. Check entries |
| 449 |
:expectedresults: |
| 450 |
1. Should success |
| 451 |
2. Should success |
| 452 |
3. Should success |
| 453 |
4. Should success |
| 454 |
5. Should success |
| 455 |
""" |
| 456 |
# Testing bug #830335: Taking a replica backup and Restore on M1 after deleting few entries from M1 nad M2 |
| 457 |
# Make sure to update S1 to avoid useless replication delay |
| 458 |
repl = ReplicationManager(DEFAULT_SUFFIX) |
| 459 |
users = UserAccounts(topo_m4.ms["supplier1"], DEFAULT_SUFFIX) |
| 460 |
for i in range(20, 25): |
| 461 |
users.create_test_user(uid=i) |
| 462 |
time.sleep(1) |
| 463 |
repl.wait_for_replication(topo_m4.ms["supplier1"], topo_m4.ms["supplier2"]) |
| 464 |
repl.test_replication(topo_m4.ms["supplier1"], topo_m4.ms["supplier2"], 30) |
| 465 |
|
| 466 |
# Get a backup |
| 467 |
topo_m4.ms["supplier1"].stop() |
| 468 |
topo_m4.ms["supplier1"].db2ldif( |
| 469 |
bename=DEFAULT_BENAME, |
| 470 |
suffixes=[DEFAULT_SUFFIX], |
| 471 |
excludeSuffixes=[], |
| 472 |
encrypt=False, |
| 473 |
repl_data=True, |
| 474 |
outputfile="/tmp/output_file", |
| 475 |
) |
| 476 |
|
| 477 |
# Do some updates (that are not in the backup |
| 478 |
# and restore the backup |
| 479 |
topo_m4.ms["supplier1"].start() |
| 480 |
for i in users.list(): topo_m4.ms["supplier1"].delete_s(i.dn) |
| 481 |
repl.wait_for_replication(topo_m4.ms["supplier1"], topo_m4.ms["supplier2"]) |
| 482 |
repl.test_replication(topo_m4.ms["supplier1"], topo_m4.ms["supplier2"], 30) |
| 483 |
# disable the agmt (while server is up) to avoid the DEL get replayed too early |
| 484 |
for agmt in list_agmt_towards(topo_m4, "supplier1"): |
| 485 |
agmt.pause() |
| 486 |
topo_m4.ms["supplier1"].stop() |
| 487 |
topo_m4.ms["supplier1"].ldif2db( |
| 488 |
bename=None, |
| 489 |
excludeSuffixes=None, |
| 490 |
encrypt=False, |
| 491 |
suffixes=[DEFAULT_SUFFIX], |
| 492 |
import_file="/tmp/output_file", |
| 493 |
) |
| 494 |
topo_m4.ms["supplier1"].start() |
| 495 |
|
| 496 |
# Check that the updates (DEL) are no longer there |
| 497 |
for i in users.list(): |
| 498 |
testuser = UserAccount(topo_m4.ms["supplier1"], i.dn) |
| 499 |
assert testuser.exists() |
| 500 |
|
| 501 |
# Re enable the agmts |
| 502 |
for agmt in list_agmt_towards(topo_m4, "supplier1"): |
| 503 |
agmt.resume() |
| 504 |
|
| 505 |
# Here the changelog of supplier1 has been cleared. |
| 506 |
# Let's wait the supplier2 resync supplier1 BEFORE doing |
| 507 |
# any update to supplier1. |
| 508 |
# Else (a new update on S1), the others supplier will not update |
| 509 |
# it and the changelog of S1 will not contain the starting points |
| 510 |
# of the others suppliers. |
| 511 |
repl.wait_for_replication(topo_m4.ms["supplier2"], topo_m4.ms["supplier1"]) |
| 512 |
repl.wait_for_replication(topo_m4.ms["supplier3"], topo_m4.ms["supplier1"]) |
| 513 |
repl.wait_for_replication(topo_m4.ms["supplier4"], topo_m4.ms["supplier1"]) |
| 514 |
|
| 515 |
for i in range(31, 35): |
| 516 |
users.create_test_user(uid=i) |
| 517 |
time.sleep(1) |
| 518 |
repl.wait_for_replication(topo_m4.ms["supplier1"], topo_m4.ms["supplier2"]) |
| 519 |
repl.test_replication(topo_m4.ms["supplier1"], topo_m4.ms["supplier2"], 30) |
| 520 |
|
| 521 |
|
| 522 |
if __name__ == "__main__": |
| 523 |
CURRENT_FILE = os.path.realpath(__file__) |
| 524 |
pytest.main("-s -v %s" % CURRENT_FILE) |