| 1 |
# --- BEGIN COPYRIGHT BLOCK --- |
| 2 |
# Copyright (C) 2025 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 |
import json |
| 14 |
import subprocess |
| 15 |
from lib389._constants import DEFAULT_SUFFIX, DN_DM |
| 16 |
from test389.topologies import topology_m2 as topo |
| 17 |
from lib389.idm.group import Groups |
| 18 |
from lib389.conflicts import ConflictEntries |
| 19 |
log = logging.getLogger(__name__) |
| 20 |
|
| 21 |
|
| 22 |
def execute_dsconf_command(dsconf_cmd, subcommands): |
| 23 |
"""Execute dsconf command and return output and return code""" |
| 24 |
|
| 25 |
cmdline = dsconf_cmd + subcommands |
| 26 |
proc = subprocess.Popen(cmdline, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
| 27 |
out, err = proc.communicate() |
| 28 |
|
| 29 |
if proc.returncode != 0 and err: |
| 30 |
log.error(f"Command failed: {' '.join(cmdline)}") |
| 31 |
log.error(f"Stderr: {err.decode('utf-8')}") |
| 32 |
|
| 33 |
return out.decode('utf-8'), proc.returncode |
| 34 |
|
| 35 |
|
| 36 |
def get_dsconf_base_cmd(inst): |
| 37 |
"""Return base dsconf command list""" |
| 38 |
return ['/usr/sbin/dsconf', inst.serverid, |
| 39 |
'-D', DN_DM, '-w', 'password', 'repl-conflict'] |
| 40 |
|
| 41 |
|
| 42 |
def get_conflict_dn(output): |
| 43 |
"""Get the conflict DN from the output""" |
| 44 |
return output.split("\n")[0].replace('dn: ', '') |
| 45 |
|
| 46 |
|
| 47 |
def test_dsconf_repl_coniflict(topo): |
| 48 |
"""Test all the dsconf repl-conflict features |
| 49 |
|
| 50 |
:id: 2ef33fd8-dd5c-4fe6-858e-e8a00e707410 |
| 51 |
:setup: 2 Supplier Instances |
| 52 |
:steps: |
| 53 |
1. Create conflict entries |
| 54 |
2. List conflicts |
| 55 |
3. Compare conflict |
| 56 |
4. Delete conflict |
| 57 |
5. Convert conflict |
| 58 |
6. Swap conflict |
| 59 |
7. Delete all conflicts |
| 60 |
:expectedresults: |
| 61 |
1. Success |
| 62 |
2. Success |
| 63 |
3. Success |
| 64 |
4. Success |
| 65 |
5. Success |
| 66 |
6. Success |
| 67 |
7. Success |
| 68 |
""" |
| 69 |
|
| 70 |
supplier1 = topo.ms["supplier1"] |
| 71 |
supplier2 = topo.ms["supplier2"] |
| 72 |
group1 = Groups(supplier1, DEFAULT_SUFFIX) |
| 73 |
group2 = Groups(supplier2, DEFAULT_SUFFIX) |
| 74 |
dsconf_cmd = get_dsconf_base_cmd(supplier1) |
| 75 |
|
| 76 |
# Create conflict entries |
| 77 |
supplier1.stop() |
| 78 |
group2.create(properties={'cn': 'test', 'description': 'value1'}) |
| 79 |
group2.create(properties={'cn': 'test2', 'description': 'value1'}) |
| 80 |
group2.create(properties={'cn': 'test3', 'description': 'value1'}) |
| 81 |
group2.create(properties={'cn': 'test4', 'description': 'value1'}) |
| 82 |
group2.create(properties={'cn': 'test5', 'description': 'value1'}) |
| 83 |
supplier2.stop() |
| 84 |
supplier1.start() |
| 85 |
group1.create(properties={'cn': 'test', 'description': 'value2'}) |
| 86 |
group1.create(properties={'cn': 'test2', 'description': 'value2'}) |
| 87 |
group1.create(properties={'cn': 'test3', 'description': 'value2'}) |
| 88 |
group1.create(properties={'cn': 'test4', 'description': 'value2'}) |
| 89 |
group1.create(properties={'cn': 'test5', 'description': 'value2'}) |
| 90 |
supplier2.start() |
| 91 |
|
| 92 |
time.sleep(2) # Let replication catch up |
| 93 |
|
| 94 |
# list conflicts |
| 95 |
conflicts1 = ConflictEntries(supplier1, DEFAULT_SUFFIX) |
| 96 |
assert len(conflicts1.list()) == 5 |
| 97 |
|
| 98 |
output, rc = execute_dsconf_command(dsconf_cmd, ["list", DEFAULT_SUFFIX]) |
| 99 |
assert rc == 0 |
| 100 |
assert len(output) > 0 |
| 101 |
assert output != "There were no conflict entries found under the suffix" |
| 102 |
conflict_dn = get_conflict_dn(output) |
| 103 |
|
| 104 |
# Compare a conflict |
| 105 |
output, rc = execute_dsconf_command(dsconf_cmd, ["compare", conflict_dn]) |
| 106 |
assert rc == 0 |
| 107 |
assert len(output) > 0 |
| 108 |
assert "Conflict Entry" in output |
| 109 |
assert "Valid Entry" in output |
| 110 |
|
| 111 |
# Delete a single conflict |
| 112 |
output, rc = execute_dsconf_command(dsconf_cmd, ["delete", conflict_dn]) |
| 113 |
assert rc == 0 |
| 114 |
assert len(conflicts1.list()) == 4 |
| 115 |
output, rc = execute_dsconf_command(dsconf_cmd, ["list", DEFAULT_SUFFIX]) |
| 116 |
assert rc == 0 |
| 117 |
conflict_dn = get_conflict_dn(output) |
| 118 |
|
| 119 |
# Convert conflict |
| 120 |
output, rc = execute_dsconf_command(dsconf_cmd, ["convert", conflict_dn, |
| 121 |
"--new-rdn=cn=testtest"]) |
| 122 |
assert rc == 0 |
| 123 |
assert len(conflicts1.list()) == 3 |
| 124 |
output, rc = execute_dsconf_command(dsconf_cmd, ["list", DEFAULT_SUFFIX]) |
| 125 |
assert rc == 0 |
| 126 |
conflict_dn = get_conflict_dn(output) |
| 127 |
|
| 128 |
# Swap conflict |
| 129 |
output, rc = execute_dsconf_command(dsconf_cmd, ["swap", conflict_dn]) |
| 130 |
assert rc == 0 |
| 131 |
assert len(conflicts1.list()) == 2 |
| 132 |
|
| 133 |
# Delete all the remaining conflicts |
| 134 |
output, rc = execute_dsconf_command(dsconf_cmd, ["delete-all", DEFAULT_SUFFIX]) |
| 135 |
assert rc == 0 |
| 136 |
assert "Deleted 2 conflict entries" in output |
| 137 |
|
| 138 |
# Check conflicts are deleted |
| 139 |
assert len(conflicts1.list()) == 0 |
| 140 |
output, rc = execute_dsconf_command(dsconf_cmd, ["list", DEFAULT_SUFFIX]) |
| 141 |
assert output.strip() == "There were no conflict entries found under the suffix" |
| 142 |
|
| 143 |
|
| 144 |
if __name__ == '__main__': |
| 145 |
# Run isolated |
| 146 |
# -s for DEBUG mode |
| 147 |
CURRENT_FILE = os.path.realpath(__file__) |
| 148 |
pytest.main(["-s", CURRENT_FILE]) |