| 1 |
# --- BEGIN COPYRIGHT BLOCK --- |
| 2 |
# Copyright (C) 2023 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 time |
| 10 |
import ldap |
| 11 |
import pytest |
| 12 |
from test389.topologies import topology_m2 |
| 13 |
from lib389.idm.user import UserAccounts |
| 14 |
from lib389._constants import DEFAULT_SUFFIX |
| 15 |
from lib389.replica import Replicas, ReplicationManager |
| 16 |
from lib389.tombstone import Tombstones |
| 17 |
|
| 18 |
# Constants for user names |
| 19 |
USER1_UID = "1" |
| 20 |
USER2_UID = "2" |
| 21 |
NEW_USER2_UID = "new_user2" |
| 22 |
|
| 23 |
pytestmark = pytest.mark.tier2 |
| 24 |
|
| 25 |
|
| 26 |
def test_replication_with_mod_delete_and_modrdn_operations(topology_m2): |
| 27 |
""" Test replication with modifications |
| 28 |
|
| 29 |
:id: d7798eb7-8b04-486a-95ea-4cd1a5031fdb |
| 30 |
:setup: Two supplier instances (S1 and S2) with initial users |
| 31 |
:steps: |
| 32 |
1. Pause all replication agreements |
| 33 |
2. Perform a delete operation on S1 (e.g., delete a user) |
| 34 |
3. Perform a modify operation on S1 (e.g., change the description of a test user) |
| 35 |
4. Sleep for 1 second to ensure CSNs are different |
| 36 |
5. Perform a modrdn operation on S2 (e.g., rename a user) |
| 37 |
6. Perform a modify operation on S2 (e.g., change the description of a test user) |
| 38 |
7. Resume all replication agreements |
| 39 |
8. Sleep for 5 seconds to allow replication to propagate |
| 40 |
9. Validate that replication is working |
| 41 |
:expectedresults: |
| 42 |
1. All replication agreements should be paused successfully |
| 43 |
2. User should be deleted on S1 |
| 44 |
3. Description should be modified for a test user on S1 |
| 45 |
4. 1 second should elapse |
| 46 |
5. User should be renamed on S2 |
| 47 |
6. Description should be modified for a test user on S2 |
| 48 |
7. All replication agreements should be resumed |
| 49 |
8. Sufficient time should pass to allow replication to propagate |
| 50 |
9. Entries should be in the expected state on both servers |
| 51 |
""" |
| 52 |
|
| 53 |
S1 = topology_m2.ms["supplier1"] |
| 54 |
S2 = topology_m2.ms["supplier2"] |
| 55 |
repl = ReplicationManager(DEFAULT_SUFFIX) |
| 56 |
|
| 57 |
# Add entries for the test |
| 58 |
users_s1 = UserAccounts(S1, DEFAULT_SUFFIX) |
| 59 |
user1 = users_s1.create_test_user(uid=USER1_UID) |
| 60 |
test1 = users_s1.create_test_user(uid=USER2_UID) |
| 61 |
repl.wait_for_replication(S1, S2) |
| 62 |
|
| 63 |
topology_m2.pause_all_replicas() |
| 64 |
|
| 65 |
users_s2 = UserAccounts(S2, DEFAULT_SUFFIX) |
| 66 |
user2 = users_s2.get(f"test_user_{USER1_UID}") |
| 67 |
test2 = users_s2.get(f"test_user_{USER2_UID}") |
| 68 |
|
| 69 |
# Delete operation on S1 |
| 70 |
user1.delete() |
| 71 |
|
| 72 |
# Modify operation on S1 |
| 73 |
test1.replace("description", "modified on S1") |
| 74 |
|
| 75 |
# Ensure CSN different |
| 76 |
time.sleep(1) |
| 77 |
|
| 78 |
# modrdn operation on S2 |
| 79 |
user2.rename(f"uid={NEW_USER2_UID}") |
| 80 |
|
| 81 |
# Modify operation on S2 |
| 82 |
test2.replace("description", "modified on S2") |
| 83 |
|
| 84 |
# Resume all replication |
| 85 |
topology_m2.resume_all_replicas() |
| 86 |
|
| 87 |
# Check if replication is working |
| 88 |
repl.wait_for_replication(S1, S2) |
| 89 |
repl.wait_for_replication(S2, S1) |
| 90 |
|
| 91 |
assert not users_s1.exists(f"test_user_{USER1_UID}") |
| 92 |
assert not users_s2.exists(f"test_user_{USER1_UID}") |
| 93 |
assert not users_s1.exists(NEW_USER2_UID) |
| 94 |
assert not users_s2.exists(NEW_USER2_UID) |
| 95 |
|
| 96 |
tombstones = Tombstones(S1, DEFAULT_SUFFIX) |
| 97 |
assert tombstones.filter(f"(&(objectClass=nstombstone)(uid=test_user_{USER1_UID}))") |
| 98 |
tombstones = Tombstones(S2, DEFAULT_SUFFIX) |
| 99 |
assert tombstones.filter(f"(&(objectClass=nstombstone)(uid={NEW_USER2_UID}))") |
| 100 |
|
| 101 |
assert test1.get_attr_val_utf8("description") == "modified on S2" |
| 102 |
assert test2.get_attr_val_utf8("description") == "modified on S2" |