| 1 |
# --- BEGIN COPYRIGHT BLOCK --- |
| 2 |
# Copyright (C) 2026 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 logging |
| 11 |
import os |
| 12 |
import pytest |
| 13 |
import subprocess |
| 14 |
from lib389._constants import DEFAULT_SUFFIX |
| 15 |
from lib389.dseldif import DSEldif |
| 16 |
from lib389.replica import ReplicationManager |
| 17 |
from test389.topologies import topology_m2 |
| 18 |
|
| 19 |
pytestmark = pytest.mark.tier1 |
| 20 |
|
| 21 |
CMD_OUTPUT = 'No issues found.' |
| 22 |
JSON_OUTPUT = '[]' |
| 23 |
|
| 24 |
log = logging.getLogger(__name__) |
| 25 |
|
| 26 |
|
| 27 |
def run_healthcheck_and_check_result(instance, searched_code, json=False, isnot=False): |
| 28 |
"""Run dsctl healthcheck and verify the expected code is in the output.""" |
| 29 |
expected = JSON_OUTPUT if json and searched_code == CMD_OUTPUT else searched_code |
| 30 |
|
| 31 |
cmd = ['dsctl'] |
| 32 |
if json: |
| 33 |
cmd.append('--json') |
| 34 |
cmd.append(instance.serverid) |
| 35 |
cmd.extend(['healthcheck', '--check', 'dseldif:nsstate']) |
| 36 |
|
| 37 |
result = subprocess.run(cmd, capture_output=True, universal_newlines=True) |
| 38 |
log.info(f'Running: {cmd}') |
| 39 |
log.info(f'Stdout: {result.stdout}') |
| 40 |
log.info(f'Stderr: {result.stderr}') |
| 41 |
log.info(f'Return code: {result.returncode}') |
| 42 |
stdout = result.stdout |
| 43 |
|
| 44 |
# stdout should not be empty |
| 45 |
assert stdout is not None |
| 46 |
assert len(stdout) > 0 |
| 47 |
|
| 48 |
if isnot: |
| 49 |
assert expected not in stdout, \ |
| 50 |
f'{expected} should NOT be in healthcheck output but was found' |
| 51 |
log.info(f'Verified {expected} is NOT in healthcheck output') |
| 52 |
else: |
| 53 |
assert expected in stdout, \ |
| 54 |
f'{expected} should be in healthcheck output but was not found' |
| 55 |
log.info(f'Verified {expected} is in healthcheck output') |
| 56 |
|
| 57 |
|
| 58 |
def test_healthcheck_time_skew_extensive(topology_m2): |
| 59 |
"""Check if HealthCheck returns DSSKEWLE0003 and DSSKEWLE0004 codes for extensive time skew |
| 60 |
|
| 61 |
:id: 7591cd2b-8d66-4d33-9f8d-babff0571086 |
| 62 |
:setup: Two suppliers replication topology |
| 63 |
:steps: |
| 64 |
1. Create a replicated topology |
| 65 |
2. Stop supplier1 |
| 66 |
3. Increase time skew on supplier1 to over 24 hours |
| 67 |
4. Start supplier1 |
| 68 |
5. Use HealthCheck and verify DSSKEWLE0003 is reported |
| 69 |
6. Set nsslapd-ignore-time-skew to on |
| 70 |
7. Use HealthCheck and verify DSSKEWLE0003 is NOT reported |
| 71 |
8. Stop supplier1 |
| 72 |
9. Increase time skew on supplier1 to over 365 days |
| 73 |
10. Start supplier1 |
| 74 |
11. Use HealthCheck and verify only DSSKEWLE0004 is reported |
| 75 |
:expectedresults: |
| 76 |
1. Success |
| 77 |
2. Success |
| 78 |
3. Success |
| 79 |
4. Success |
| 80 |
5. Healthcheck reports DSSKEWLE0003 code |
| 81 |
6. Success |
| 82 |
7. Healthcheck does not report DSSKEWLE0003 code |
| 83 |
8. Success |
| 84 |
9. Success |
| 85 |
10. Success |
| 86 |
11. Healthcheck reports DSSKEWLE0004 code and not DSSKEWLE0003 |
| 87 |
""" |
| 88 |
|
| 89 |
M1 = topology_m2.ms['supplier1'] |
| 90 |
M2 = topology_m2.ms['supplier2'] |
| 91 |
|
| 92 |
# Ensure replication is working first |
| 93 |
repl = ReplicationManager(DEFAULT_SUFFIX) |
| 94 |
repl.wait_for_replication(M1, M2) |
| 95 |
|
| 96 |
# Step 2-4: Stop supplier1, increase time skew to over 24 hours, start supplier1 |
| 97 |
log.info('Stop supplier1 to modify dse.ldif') |
| 98 |
M1.stop() |
| 99 |
|
| 100 |
# Set time skew to over 24 hours (86400 seconds) |
| 101 |
# Add a margin to be safely over the threshold |
| 102 |
time_skew_24h = 86400 + 3600 # 25 hours |
| 103 |
log.info(f'Increase time skew on supplier1 by {time_skew_24h} seconds') |
| 104 |
DSEldif(M1)._increaseTimeSkew(DEFAULT_SUFFIX, time_skew_24h) |
| 105 |
|
| 106 |
log.info('Start supplier1') |
| 107 |
M1.start() |
| 108 |
|
| 109 |
# Step 5: Verify DSSKEWLE0003 is reported |
| 110 |
log.info('Run healthcheck and verify DSSKEWLE0003 is reported') |
| 111 |
M1.stop() |
| 112 |
try: |
| 113 |
run_healthcheck_and_check_result(M1, 'DSSKEWLE0003', json=False) |
| 114 |
run_healthcheck_and_check_result(M1, 'DSSKEWLE0003', json=True) |
| 115 |
finally: |
| 116 |
if not M1.status(): |
| 117 |
M1.start() |
| 118 |
run_healthcheck_and_check_result(M1, 'DSSKEWLE0003', json=False) |
| 119 |
run_healthcheck_and_check_result(M1, 'DSSKEWLE0003', json=True) |
| 120 |
|
| 121 |
# Step 6: Set nsslapd-ignore-time-skew to on |
| 122 |
log.info('Set nsslapd-ignore-time-skew to on') |
| 123 |
M1.config.set('nsslapd-ignore-time-skew', 'on') |
| 124 |
|
| 125 |
# Step 7: Verify DSSKEWLE0003 is NOT reported when ignoring time skew |
| 126 |
log.info('Run healthcheck and verify DSSKEWLE0003 is NOT reported') |
| 127 |
M1.stop() |
| 128 |
try: |
| 129 |
run_healthcheck_and_check_result(M1, 'DSSKEWLE0003', json=False, isnot=True) |
| 130 |
run_healthcheck_and_check_result(M1, 'DSSKEWLE0003', json=True, isnot=True) |
| 131 |
finally: |
| 132 |
if not M1.status(): |
| 133 |
M1.start() |
| 134 |
run_healthcheck_and_check_result(M1, 'DSSKEWLE0003', json=False, isnot=True) |
| 135 |
run_healthcheck_and_check_result(M1, 'DSSKEWLE0003', json=True, isnot=True) |
| 136 |
|
| 137 |
# Step 8-10: Stop supplier1, increase time skew to over 365 days, start supplier1 |
| 138 |
log.info('Stop supplier1 to modify dse.ldif') |
| 139 |
M1.stop() |
| 140 |
|
| 141 |
# Increase time skew to over 365 days (31536000 seconds) |
| 142 |
# We need to add enough to go from current ~25 hours to over 365 days |
| 143 |
time_skew_year = (86400 * 365) + 86400 # 366 days total additional |
| 144 |
log.info(f'Increase time skew on supplier1 by {time_skew_year} seconds') |
| 145 |
DSEldif(M1)._increaseTimeSkew(DEFAULT_SUFFIX, time_skew_year) |
| 146 |
|
| 147 |
log.info('Start supplier1') |
| 148 |
M1.start() |
| 149 |
|
| 150 |
# Step 11: Verify only DSSKEWLE0004 is reported (not DSSKEWLE0003) |
| 151 |
log.info('Run healthcheck and verify only DSSKEWLE0004 is reported') |
| 152 |
M1.stop() |
| 153 |
try: |
| 154 |
run_healthcheck_and_check_result(M1, 'DSSKEWLE0004', json=False) |
| 155 |
run_healthcheck_and_check_result(M1, 'DSSKEWLE0004', json=True) |
| 156 |
run_healthcheck_and_check_result(M1, 'DSSKEWLE0003', json=False, isnot=True) |
| 157 |
run_healthcheck_and_check_result(M1, 'DSSKEWLE0003', json=True, isnot=True) |
| 158 |
finally: |
| 159 |
if not M1.status(): |
| 160 |
M1.start() |
| 161 |
run_healthcheck_and_check_result(M1, 'DSSKEWLE0004', json=False) |
| 162 |
run_healthcheck_and_check_result(M1, 'DSSKEWLE0004', json=True) |
| 163 |
run_healthcheck_and_check_result(M1, 'DSSKEWLE0003', json=False, isnot=True) |
| 164 |
run_healthcheck_and_check_result(M1, 'DSSKEWLE0003', json=True, isnot=True) |
| 165 |
|
| 166 |
|
| 167 |
if __name__ == '__main__': |
| 168 |
# Run isolated |
| 169 |
# -s for DEBUG mode |
| 170 |
CURRENT_FILE = os.path.realpath(__file__) |
| 171 |
pytest.main("-s %s" % CURRENT_FILE) |