| 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 pytest |
| 11 |
import os |
| 12 |
from lib389.backend import Backends |
| 13 |
from lib389.mappingTree import MappingTrees |
| 14 |
from lib389.replica import Changelog5, Changelog |
| 15 |
from lib389.utils import * |
| 16 |
from lib389._constants import * |
| 17 |
from lib389.cli_base import FakeArgs |
| 18 |
from test389.topologies import topology_st, topology_no_sample, topology_m2 |
| 19 |
from lib389.cli_ctl.health import health_check_run |
| 20 |
from lib389.paths import Paths |
| 21 |
|
| 22 |
CMD_OUTPUT = 'No issues found.' |
| 23 |
JSON_OUTPUT = '[]' |
| 24 |
CHANGELOG = 'cn=changelog,{}'.format(DN_USERROOT_LDBM) |
| 25 |
|
| 26 |
ds_paths = Paths() |
| 27 |
log = logging.getLogger(__name__) |
| 28 |
|
| 29 |
|
| 30 |
def run_healthcheck_and_flush_log(logcap, instance, searched_code=None, |
| 31 |
json=False, searched_code2=None, |
| 32 |
list_checks=False, list_errors=False, |
| 33 |
check=None, searched_list=None): |
| 34 |
# If we are using BDB as a backend, we will get error DSBLE0006 on new |
| 35 |
# versions |
| 36 |
|
| 37 |
if ds_is_newer("3.0.0") and instance.get_db_lib() == 'bdb' and \ |
| 38 |
((check is not None and check[0] == "backends:userroot:backend_implementation") or |
| 39 |
(searched_code is CMD_OUTPUT or searched_code is JSON_OUTPUT)): |
| 40 |
searched_code = 'DSBLE0006' |
| 41 |
|
| 42 |
args = FakeArgs() |
| 43 |
args.instance = instance.serverid |
| 44 |
args.verbose = instance.verbose |
| 45 |
args.list_errors = list_errors |
| 46 |
args.list_checks = list_checks |
| 47 |
args.check = check |
| 48 |
args.exclude_check = [] |
| 49 |
args.dry_run = False |
| 50 |
args.json = json |
| 51 |
|
| 52 |
log.info('Use healthcheck with --json == {} option'.format(json)) |
| 53 |
health_check_run(instance, logcap.log, args) |
| 54 |
|
| 55 |
if searched_list is not None: |
| 56 |
for item in searched_list: |
| 57 |
assert logcap.contains(item) |
| 58 |
log.info('Healthcheck returned searched item: %s', item) |
| 59 |
else: |
| 60 |
if not logcap.contains(searched_code): |
| 61 |
print("DEBUG logcap does not contain searched code: %s", searched_code) |
| 62 |
print("DEBUG logcap contents: ", logcap.print()) |
| 63 |
|
| 64 |
assert logcap.contains(searched_code) |
| 65 |
log.info('Healthcheck returned searched code: %s', searched_code) |
| 66 |
|
| 67 |
if searched_code2 is not None: |
| 68 |
code2 = searched_code2 |
| 69 |
if ds_is_newer("3.0.0") and instance.get_db_lib() == 'bdb' and \ |
| 70 |
(check is not None and check[0] == "backends:userroot:backend_implementation"): |
| 71 |
code2 = 'DSBLE0006' |
| 72 |
|
| 73 |
assert logcap.contains(code2) |
| 74 |
log.info('Healthcheck returned searched code2: %s', code2) |
| 75 |
|
| 76 |
log.info('Clear the log') |
| 77 |
logcap.flush() |
| 78 |
|
| 79 |
|
| 80 |
def run_healthcheck_exclude(logcap, instance, unwanted, wanted, exclude_check): |
| 81 |
args = FakeArgs() |
| 82 |
args.instance = instance.serverid |
| 83 |
args.verbose = instance.verbose |
| 84 |
args.list_errors = False |
| 85 |
args.list_checks = False |
| 86 |
args.check = None |
| 87 |
args.exclude_check = [exclude_check] |
| 88 |
args.dry_run = False |
| 89 |
args.json = False |
| 90 |
|
| 91 |
health_check_run(instance, logcap.log, args) |
| 92 |
|
| 93 |
assert not logcap.contains(unwanted) |
| 94 |
assert logcap.contains(wanted) |
| 95 |
|
| 96 |
log.info('Clear the log') |
| 97 |
logcap.flush() |
| 98 |
|
| 99 |
|
| 100 |
def set_changelog_trimming(instance): |
| 101 |
log.info('Set nsslapd-changelogmaxage to 30d') |
| 102 |
|
| 103 |
if ds_supports_new_changelog(): |
| 104 |
cl = Changelog(instance, DEFAULT_SUFFIX) |
| 105 |
else: |
| 106 |
cl = Changelog5(instance) |
| 107 |
cl.replace('nsslapd-changelogmaxage', '30d') |
| 108 |
|
| 109 |
|
| 110 |
def test_healthcheck_disabled_suffix(topology_st): |
| 111 |
"""Test that we report when a suffix is disabled |
| 112 |
|
| 113 |
:id: 49ebce72-7e7b-4eff-8bd9-8384d12251b4 |
| 114 |
:setup: Standalone Instance |
| 115 |
:steps: |
| 116 |
1. Disable suffix |
| 117 |
2. Use HealthCheck without --json option |
| 118 |
3. Use HealthCheck with --json option |
| 119 |
:expectedresults: |
| 120 |
1. Success |
| 121 |
2. HealthCheck should return code DSBLE0002 |
| 122 |
3. HealthCheck should return code DSBLE0002 |
| 123 |
""" |
| 124 |
|
| 125 |
RET_CODE = 'DSBLE0002' |
| 126 |
|
| 127 |
mts = MappingTrees(topology_st.standalone) |
| 128 |
mt = mts.get(DEFAULT_SUFFIX) |
| 129 |
mt.replace("nsslapd-state", "disabled") |
| 130 |
topology_st.standalone.config.set("nsslapd-accesslog-logbuffering", "on") |
| 131 |
|
| 132 |
standalone = topology_st.standalone |
| 133 |
|
| 134 |
run_healthcheck_and_flush_log(topology_st.logcap, standalone, RET_CODE, json=False) |
| 135 |
run_healthcheck_and_flush_log(topology_st.logcap, standalone, RET_CODE, json=True) |
| 136 |
|
| 137 |
# reset the suffix state |
| 138 |
mt.replace("nsslapd-state", "backend") |
| 139 |
|
| 140 |
|
| 141 |
@pytest.mark.skipif(ds_is_older("1.4.1"), reason="Not implemented") |
| 142 |
def test_healthcheck_standalone(topology_st): |
| 143 |
"""Check functionality of HealthCheck Tool on standalone instance with no errors |
| 144 |
|
| 145 |
:id: 4844b446-3939-4fbd-b14b-293b20bb8be0 |
| 146 |
:setup: Standalone instance |
| 147 |
:steps: |
| 148 |
1. Create DS instance |
| 149 |
2. Use HealthCheck without --json option |
| 150 |
3. Use HealthCheck with --json option |
| 151 |
:expectedresults: |
| 152 |
1. Success |
| 153 |
2. Success |
| 154 |
3. Success |
| 155 |
""" |
| 156 |
|
| 157 |
standalone = topology_st.standalone |
| 158 |
standalone.config.set("nsslapd-accesslog-logbuffering", "on") |
| 159 |
|
| 160 |
standalone.stop() |
| 161 |
try: |
| 162 |
run_healthcheck_and_flush_log(topology_st.logcap, standalone, CMD_OUTPUT, json=False) |
| 163 |
run_healthcheck_and_flush_log(topology_st.logcap, standalone, JSON_OUTPUT, json=True) |
| 164 |
finally: |
| 165 |
if not standalone.status(): |
| 166 |
standalone.start() |
| 167 |
run_healthcheck_and_flush_log(topology_st.logcap, standalone, CMD_OUTPUT, json=False) |
| 168 |
run_healthcheck_and_flush_log(topology_st.logcap, standalone, JSON_OUTPUT, json=True) |
| 169 |
|
| 170 |
|
| 171 |
@pytest.mark.xfail(ds_is_older("1.4.2"), reason="Not implemented") |
| 172 |
def test_healthcheck_list_checks(topology_st): |
| 173 |
"""Check functionality of HealthCheck Tool with --list-checks option |
| 174 |
|
| 175 |
:id: 44b1d8d3-b94a-4c2d-9233-ebe876802803 |
| 176 |
:setup: Standalone instance |
| 177 |
:steps: |
| 178 |
1. Create DS instance |
| 179 |
2. Set list_checks to True |
| 180 |
3. Run HealthCheck |
| 181 |
:expectedresults: |
| 182 |
1. Success |
| 183 |
2. Success |
| 184 |
3. Success |
| 185 |
""" |
| 186 |
|
| 187 |
output_list = ['config:passwordscheme', |
| 188 |
'config:auditlog_buffering', |
| 189 |
# 'config:accesslog_buffering', Skip test access log buffering is disabled |
| 190 |
'config:securitylog_buffering', |
| 191 |
'config:unauth_binds', |
| 192 |
'backends:userroot:cl_trimming', |
| 193 |
'backends:userroot:mappingtree', |
| 194 |
'backends:userroot:search', |
| 195 |
'backends:userroot:system_indexes', |
| 196 |
'backends:userroot:virt_attrs', |
| 197 |
'backends:userroot:backend_implementation', |
| 198 |
'backends:userroot:backend_implementation_cleanup_needed', |
| 199 |
'backends:userroot:backend_implementation_config_attributes', |
| 200 |
'encryption:check_tls_version', |
| 201 |
'fschecks:file_perms', |
| 202 |
'refint:attr_indexes', |
| 203 |
'refint:update_delay', |
| 204 |
'memberof:member_attr_indexes', |
| 205 |
'memberof:member_globalbackend_lock', |
| 206 |
'memberof:member_substring_index', |
| 207 |
'monitor-disk-space:disk_space', |
| 208 |
'replication:agmts_status', |
| 209 |
'replication:conflicts', |
| 210 |
'replication:no_ruv', |
| 211 |
'dseldif:nsstate', |
| 212 |
'tls:certificate_expiration', |
| 213 |
'logs:notes', |
| 214 |
'tunables:thp'] |
| 215 |
|
| 216 |
standalone = topology_st.standalone |
| 217 |
|
| 218 |
standalone.stop() |
| 219 |
try: |
| 220 |
run_healthcheck_and_flush_log(topology_st.logcap, standalone, json=False, list_checks=True, searched_list=output_list) |
| 221 |
finally: |
| 222 |
if not standalone.status(): |
| 223 |
standalone.start() |
| 224 |
run_healthcheck_and_flush_log(topology_st.logcap, standalone, json=False, list_checks=True, searched_list=output_list) |
| 225 |
|
| 226 |
|
| 227 |
@pytest.mark.xfail(ds_is_older("1.4.2"), reason="Not implemented") |
| 228 |
def test_healthcheck_list_errors(topology_st): |
| 229 |
"""Check functionality of HealthCheck Tool with --list-errors option |
| 230 |
|
| 231 |
:id: 295c07c0-a939-4d5e-b3a6-b4c9d0da3897 |
| 232 |
:setup: Standalone instance |
| 233 |
:steps: |
| 234 |
1. Create DS instance |
| 235 |
2. Set list_errors to True |
| 236 |
3. Run HealthCheck |
| 237 |
:expectedresults: |
| 238 |
1. Success |
| 239 |
2. Success |
| 240 |
3. Success |
| 241 |
""" |
| 242 |
|
| 243 |
output_list = ['DSBLE0001 :: Possibly incorrect mapping tree', |
| 244 |
'DSBLE0002 :: Unable to query backend', |
| 245 |
'DSBLE0003 :: Uninitialized backend database', |
| 246 |
'DSBLE0004 :: Both MDB and BDB database files are present', |
| 247 |
'DSBLE0005 :: Backend configuration attributes mismatch', |
| 248 |
'DSBLE0006 :: BDB is still used as a backend', |
| 249 |
'DSCERTLE0001 :: Certificate about to expire', |
| 250 |
'DSCERTLE0002 :: Certificate expired', |
| 251 |
'DSCLE0002 :: Weak passwordStorageScheme', |
| 252 |
'DSCLE0003 :: Unauthorized Binds Allowed', |
| 253 |
'DSCLE0004 :: Access Log buffering disabled', |
| 254 |
'DSCLE0005 :: Security Log buffering disabled', |
| 255 |
'DSCLLE0001 :: Changelog trimming not configured', |
| 256 |
'DSDSLE0001 :: Low disk space', |
| 257 |
'DSELE0001 :: Weak TLS protocol version', |
| 258 |
'DSLOGNOTES0001 :: Unindexed Search', |
| 259 |
'DSLOGNOTES0002 :: Unknown Attribute In Filter', |
| 260 |
'DSPERMLE0001 :: Incorrect file permissions', |
| 261 |
'DSPERMLE0002 :: Incorrect security database file permissions', |
| 262 |
'DSREPLLE0001 :: Replication agreement not set to be synchronized', |
| 263 |
'DSREPLLE0002 :: Replication conflict entries found', |
| 264 |
'DSREPLLE0003 :: Unsynchronized replication agreement', |
| 265 |
'DSREPLLE0004 :: Unable to get replication agreement status', |
| 266 |
'DSREPLLE0005 :: Replication consumer not reachable', |
| 267 |
'DSRILE0001 :: Referential integrity plugin may be slower', |
| 268 |
'DSRILE0002 :: Referential integrity plugin configured with unindexed attribute', |
| 269 |
'DSSKEWLE0001 :: Medium time skew', |
| 270 |
'DSSKEWLE0002 :: Major time skew', |
| 271 |
'DSSKEWLE0003 :: Extensive time skew', |
| 272 |
'DSTHPLE0001 :: Transparent Huge Pages', |
| 273 |
'DSVIRTLE0001 :: Virtual attribute indexed'] |
| 274 |
|
| 275 |
standalone = topology_st.standalone |
| 276 |
|
| 277 |
standalone.stop() |
| 278 |
try: |
| 279 |
run_healthcheck_and_flush_log(topology_st.logcap, standalone, json=False, list_errors=True, searched_list=output_list) |
| 280 |
finally: |
| 281 |
if not standalone.status(): |
| 282 |
standalone.start() |
| 283 |
run_healthcheck_and_flush_log(topology_st.logcap, standalone, json=False, list_errors=True, searched_list=output_list) |
| 284 |
|
| 285 |
|
| 286 |
@pytest.mark.xfail(ds_is_older("1.4.2"), reason="Not implemented") |
| 287 |
def test_healthcheck_check_option(topology_st): |
| 288 |
"""Check functionality of HealthCheck Tool with --check option |
| 289 |
|
| 290 |
:id: ee382d6f-8bec-4236-ace4-4700d19dc9fd |
| 291 |
:setup: Standalone instance |
| 292 |
:steps: |
| 293 |
1. Create DS instance |
| 294 |
2. Set check to value from list |
| 295 |
3. Run HealthCheck |
| 296 |
:expectedresults: |
| 297 |
1. Success |
| 298 |
2. Success |
| 299 |
3. Success |
| 300 |
""" |
| 301 |
|
| 302 |
output_list = ['config:passwordscheme', |
| 303 |
'config:auditlog_buffering', |
| 304 |
# 'config:accesslog_buffering', Skip test access log buffering is disabled |
| 305 |
'config:securitylog_buffering', |
| 306 |
'config:unauth_binds', |
| 307 |
'backends:userroot:cl_trimming', |
| 308 |
'backends:userroot:mappingtree', |
| 309 |
'backends:userroot:search', |
| 310 |
'backends:userroot:system_indexes', |
| 311 |
'backends:userroot:virt_attrs', |
| 312 |
'backends:userroot:backend_implementation', |
| 313 |
'backends:userroot:backend_implementation_cleanup_needed', |
| 314 |
'backends:userroot:backend_implementation_config_attributes', |
| 315 |
'encryption:check_tls_version', |
| 316 |
'fschecks:file_perms', |
| 317 |
'refint:attr_indexes', |
| 318 |
'refint:update_delay', |
| 319 |
'memberof:member_attr_indexes', |
| 320 |
'memberof:member_globalbackend_lock', |
| 321 |
'memberof:member_substring_index', |
| 322 |
'monitor-disk-space:disk_space', |
| 323 |
'replication:agmts_status', |
| 324 |
'replication:conflicts', |
| 325 |
'replication:no_ruv', |
| 326 |
'dseldif:nsstate', |
| 327 |
'tunables:thp', |
| 328 |
'tls:certificate_expiration', |
| 329 |
'logs:notes'] |
| 330 |
|
| 331 |
standalone = topology_st.standalone |
| 332 |
|
| 333 |
for item in output_list: |
| 334 |
pattern = 'Checking ' + item |
| 335 |
log.info('Check {}'.format(item)) |
| 336 |
standalone.stop() |
| 337 |
|
| 338 |
try: |
| 339 |
run_healthcheck_and_flush_log(topology_st.logcap, standalone, searched_code=pattern, json=False, check=[item], |
| 340 |
searched_code2=CMD_OUTPUT) |
| 341 |
finally: |
| 342 |
if not standalone.status(): |
| 343 |
standalone.start() |
| 344 |
run_healthcheck_and_flush_log(topology_st.logcap, standalone, searched_code=pattern, json=False, check=[item], |
| 345 |
searched_code2=CMD_OUTPUT) |
| 346 |
|
| 347 |
|
| 348 |
def test_healthcheck_exclude_option(topology_st): |
| 349 |
"""Check functionality of HealthCheck Tool with --exclude-check option |
| 350 |
|
| 351 |
:id: a4e2103c-67b8-4359-a8ba-67a8650cd3b7 |
| 352 |
:setup: Standalone instance |
| 353 |
:steps: |
| 354 |
1. Set check to exclude from list |
| 355 |
2. Run HealthCheck |
| 356 |
:expectedresults: |
| 357 |
1. Success |
| 358 |
2. Success |
| 359 |
""" |
| 360 |
|
| 361 |
inst = topology_st.standalone |
| 362 |
|
| 363 |
exclude_list = [ |
| 364 |
('config:passwordscheme', 'config:passwordscheme', |
| 365 |
'config:securitylog_buffering'), |
| 366 |
('config', 'config:', 'backends:userroot:mappingtree') |
| 367 |
] |
| 368 |
|
| 369 |
for exclude, unwanted, wanted in exclude_list: |
| 370 |
unwanted_pattern = 'Checking ' + unwanted |
| 371 |
wanted_pattern = 'Checking ' + wanted |
| 372 |
|
| 373 |
log.info('Exclude check: %s unwanted: %s wanted: %s', |
| 374 |
exclude, unwanted, wanted) |
| 375 |
|
| 376 |
inst.stop() |
| 377 |
try: |
| 378 |
run_healthcheck_exclude(topology_st.logcap, inst, |
| 379 |
unwanted=unwanted_pattern, |
| 380 |
wanted=wanted_pattern, |
| 381 |
exclude_check=exclude) |
| 382 |
finally: |
| 383 |
if not inst.status(): |
| 384 |
inst.start() |
| 385 |
run_healthcheck_exclude(topology_st.logcap, inst, |
| 386 |
unwanted=unwanted_pattern, |
| 387 |
wanted=wanted_pattern, |
| 388 |
exclude_check=exclude) |
| 389 |
|
| 390 |
|
| 391 |
@pytest.mark.skipif(ds_is_older("1.4.1"), reason="Not implemented") |
| 392 |
def test_healthcheck_standalone_tls(topology_st): |
| 393 |
"""Check functionality of HealthCheck Tool on TLS enabled standalone instance with no errors |
| 394 |
|
| 395 |
:id: 832374e6-6d2c-42af-80c8-d3685dbfa234 |
| 396 |
:setup: Standalone instance |
| 397 |
:steps: |
| 398 |
1. Create DS instance |
| 399 |
2. Enable TLS |
| 400 |
3. Use HealthCheck without --json option |
| 401 |
4. Use HealthCheck with --json option |
| 402 |
:expectedresults: |
| 403 |
1. Success |
| 404 |
2. Success |
| 405 |
3. Success |
| 406 |
4. Success |
| 407 |
""" |
| 408 |
|
| 409 |
standalone = topology_st.standalone |
| 410 |
standalone.config.set("nsslapd-accesslog-logbuffering", "on") |
| 411 |
standalone.enable_tls() |
| 412 |
|
| 413 |
standalone.stop() |
| 414 |
try: |
| 415 |
run_healthcheck_and_flush_log(topology_st.logcap, standalone, CMD_OUTPUT, json=False) |
| 416 |
run_healthcheck_and_flush_log(topology_st.logcap, standalone, JSON_OUTPUT, json=True) |
| 417 |
finally: |
| 418 |
if not standalone.status(): |
| 419 |
standalone.start() |
| 420 |
run_healthcheck_and_flush_log(topology_st.logcap, standalone, CMD_OUTPUT, json=False) |
| 421 |
run_healthcheck_and_flush_log(topology_st.logcap, standalone, JSON_OUTPUT, json=True) |
| 422 |
|
| 423 |
|
| 424 |
@pytest.mark.skipif(ds_is_older("1.4.1"), reason="Not implemented") |
| 425 |
def test_healthcheck_replication(topology_m2): |
| 426 |
"""Check functionality of HealthCheck Tool on replication instance with no errors |
| 427 |
|
| 428 |
:id: d7751cc3-271c-4c33-b296-8a4c8941233e |
| 429 |
:setup: 2 MM topology |
| 430 |
:steps: |
| 431 |
1. Create a two suppliers replication topology |
| 432 |
2. Set nsslapd-changelogmaxage to 30d |
| 433 |
3. Use HealthCheck without --json option |
| 434 |
4. Use HealthCheck with --json option |
| 435 |
:expectedresults: |
| 436 |
1. Success |
| 437 |
2. Success |
| 438 |
3. Success |
| 439 |
4. Success |
| 440 |
""" |
| 441 |
|
| 442 |
M1 = topology_m2.ms['supplier1'] |
| 443 |
M2 = topology_m2.ms['supplier2'] |
| 444 |
|
| 445 |
# If we don't set changelog trimming, we will get error DSCLLE0001 |
| 446 |
set_changelog_trimming(M1) |
| 447 |
set_changelog_trimming(M2) |
| 448 |
M1.config.set("nsslapd-accesslog-logbuffering", "on") |
| 449 |
M2.config.set("nsslapd-accesslog-logbuffering", "on") |
| 450 |
|
| 451 |
log.info('Run healthcheck for supplier1') |
| 452 |
M1.stop() |
| 453 |
try: |
| 454 |
run_healthcheck_and_flush_log(topology_m2.logcap, M1, CMD_OUTPUT, json=False) |
| 455 |
run_healthcheck_and_flush_log(topology_m2.logcap, M1, JSON_OUTPUT, json=True) |
| 456 |
finally: |
| 457 |
if not M1.status(): |
| 458 |
M1.start() |
| 459 |
run_healthcheck_and_flush_log(topology_m2.logcap, M1, CMD_OUTPUT, json=False) |
| 460 |
run_healthcheck_and_flush_log(topology_m2.logcap, M1, JSON_OUTPUT, json=True) |
| 461 |
|
| 462 |
log.info('Run healthcheck for supplier2') |
| 463 |
M2.stop() |
| 464 |
try: |
| 465 |
run_healthcheck_and_flush_log(topology_m2.logcap, M2, CMD_OUTPUT, json=False) |
| 466 |
run_healthcheck_and_flush_log(topology_m2.logcap, M2, JSON_OUTPUT, json=True) |
| 467 |
finally: |
| 468 |
if not M2.status(): |
| 469 |
M2.start() |
| 470 |
run_healthcheck_and_flush_log(topology_m2.logcap, M2, CMD_OUTPUT, json=False) |
| 471 |
run_healthcheck_and_flush_log(topology_m2.logcap, M2, JSON_OUTPUT, json=True) |
| 472 |
|
| 473 |
|
| 474 |
@pytest.mark.skipif(ds_is_older("1.4.1"), reason="Not implemented") |
| 475 |
def test_healthcheck_replication_tls(topology_m2): |
| 476 |
"""Check functionality of HealthCheck Tool on replication instance with no errors |
| 477 |
|
| 478 |
:id: 9ee6d491-d6d7-4c2c-ac78-70d08f054166 |
| 479 |
:setup: 2 MM topology |
| 480 |
:steps: |
| 481 |
1. Create a two suppliers replication topology |
| 482 |
2. Enable TLS |
| 483 |
3. Set nsslapd-changelogmaxage to 30d |
| 484 |
4. Use HealthCheck without --json option |
| 485 |
5. Use HealthCheck with --json option |
| 486 |
:expectedresults: |
| 487 |
1. Success |
| 488 |
2. Success |
| 489 |
3. Success |
| 490 |
4. Success |
| 491 |
5. Success |
| 492 |
""" |
| 493 |
|
| 494 |
M1 = topology_m2.ms['supplier1'] |
| 495 |
M2 = topology_m2.ms['supplier2'] |
| 496 |
|
| 497 |
M1.enable_tls() |
| 498 |
M2.enable_tls() |
| 499 |
|
| 500 |
log.info('Run healthcheck for supplier1') |
| 501 |
M1.config.set("nsslapd-accesslog-logbuffering", "on") |
| 502 |
M2.config.set("nsslapd-accesslog-logbuffering", "on") |
| 503 |
M1.stop() |
| 504 |
try: |
| 505 |
run_healthcheck_and_flush_log(topology_m2.logcap, M1, CMD_OUTPUT, json=False) |
| 506 |
run_healthcheck_and_flush_log(topology_m2.logcap, M1, JSON_OUTPUT, json=True) |
| 507 |
finally: |
| 508 |
if not M1.status(): |
| 509 |
M1.start() |
| 510 |
run_healthcheck_and_flush_log(topology_m2.logcap, M1, CMD_OUTPUT, json=False) |
| 511 |
run_healthcheck_and_flush_log(topology_m2.logcap, M1, JSON_OUTPUT, json=True) |
| 512 |
|
| 513 |
log.info('Run healthcheck for supplier2') |
| 514 |
M2.stop() |
| 515 |
try: |
| 516 |
run_healthcheck_and_flush_log(topology_m2.logcap, M2, CMD_OUTPUT, json=False) |
| 517 |
run_healthcheck_and_flush_log(topology_m2.logcap, M2, JSON_OUTPUT, json=True) |
| 518 |
finally: |
| 519 |
if not M2.status(): |
| 520 |
M2.start() |
| 521 |
run_healthcheck_and_flush_log(topology_m2.logcap, M2, CMD_OUTPUT, json=False) |
| 522 |
run_healthcheck_and_flush_log(topology_m2.logcap, M2, JSON_OUTPUT, json=True) |
| 523 |
|
| 524 |
|
| 525 |
@pytest.mark.skipif(ds_is_older("1.4.1"), reason="Not implemented") |
| 526 |
@pytest.mark.xfail(ds_is_older("1.4.3"),reason="Might fail because of bz1835619") |
| 527 |
def test_healthcheck_backend_missing_mapping_tree(topology_st): |
| 528 |
"""Check if HealthCheck returns DSBLE0001 and DSBLE0003 code |
| 529 |
|
| 530 |
:id: 4c83ffcf-01a4-4ec8-a3d2-01022b566225 |
| 531 |
:setup: Standalone instance |
| 532 |
:steps: |
| 533 |
1. Create DS instance |
| 534 |
2. Disable the dc=example,dc=com backend suffix entry in the mapping tree |
| 535 |
3. Use HealthCheck without --json option |
| 536 |
4. Use HealthCheck with --json option |
| 537 |
5. Enable the dc=example,dc=com backend suffix entry in the mapping tree |
| 538 |
6. Use HealthCheck without --json option |
| 539 |
7. Use HealthCheck with --json option |
| 540 |
:expectedresults: |
| 541 |
1. Success |
| 542 |
2. Success |
| 543 |
3. Healthcheck reports DSBLE0001 and DSBLE0003 codes and related details |
| 544 |
4. Healthcheck reports DSBLE0001 and DSBLE0003 codes and related details |
| 545 |
5. Success |
| 546 |
6. Healthcheck reports no issue found |
| 547 |
7. Healthcheck reports no issue found |
| 548 |
""" |
| 549 |
|
| 550 |
RET_CODE1 = 'DSBLE0001' |
| 551 |
RET_CODE2 = 'DSBLE0003' |
| 552 |
|
| 553 |
standalone = topology_st.standalone |
| 554 |
standalone.config.set("nsslapd-accesslog-logbuffering", "on") |
| 555 |
|
| 556 |
log.info('Delete the dc=example,dc=com backend suffix entry in the mapping tree') |
| 557 |
mts = MappingTrees(standalone) |
| 558 |
mt = mts.get(DEFAULT_SUFFIX) |
| 559 |
mt.delete() |
| 560 |
|
| 561 |
standalone.stop() |
| 562 |
try: |
| 563 |
run_healthcheck_and_flush_log(topology_st.logcap, standalone, RET_CODE1, json=False) |
| 564 |
run_healthcheck_and_flush_log(topology_st.logcap, standalone, RET_CODE1, json=True) |
| 565 |
finally: |
| 566 |
if not standalone.status(): |
| 567 |
standalone.start() |
| 568 |
run_healthcheck_and_flush_log(topology_st.logcap, standalone, RET_CODE1, json=False, searched_code2=RET_CODE2) |
| 569 |
run_healthcheck_and_flush_log(topology_st.logcap, standalone, RET_CODE1, json=True, searched_code2=RET_CODE2) |
| 570 |
|
| 571 |
log.info('Create the dc=example,dc=com backend suffix entry') |
| 572 |
mts.create(properties={ |
| 573 |
'cn': DEFAULT_SUFFIX, |
| 574 |
'nsslapd-state': 'backend', |
| 575 |
'nsslapd-backend': 'USERROOT', |
| 576 |
}) |
| 577 |
|
| 578 |
standalone.stop() |
| 579 |
try: |
| 580 |
run_healthcheck_and_flush_log(topology_st.logcap, standalone, CMD_OUTPUT, json=False) |
| 581 |
run_healthcheck_and_flush_log(topology_st.logcap, standalone, JSON_OUTPUT, json=True) |
| 582 |
finally: |
| 583 |
if not standalone.status(): |
| 584 |
standalone.start() |
| 585 |
run_healthcheck_and_flush_log(topology_st.logcap, standalone, CMD_OUTPUT, json=False) |
| 586 |
run_healthcheck_and_flush_log(topology_st.logcap, standalone, JSON_OUTPUT, json=True) |
| 587 |
|
| 588 |
|
| 589 |
@pytest.mark.skipif(ds_is_older("1.4.1"), reason="Not implemented") |
| 590 |
@pytest.mark.xfail(reason="Will fail because of bz1837315. Set proper version after bug is fixed") |
| 591 |
def test_healthcheck_unable_to_query_backend(topology_st): |
| 592 |
"""Check if HealthCheck returns DSBLE0002 code |
| 593 |
|
| 594 |
:id: 01de2fe5-079d-4166-b4c9-1f1e00bb091c |
| 595 |
:setup: Standalone instance |
| 596 |
:steps: |
| 597 |
1. Create DS instance |
| 598 |
2. Create a new root suffix and database |
| 599 |
3. Disable new suffix |
| 600 |
4. Use HealthCheck without --json option |
| 601 |
5. Use HealthCheck with --json option |
| 602 |
:expectedresults: |
| 603 |
1. Success |
| 604 |
2. Success |
| 605 |
3. Success |
| 606 |
4. HealthCheck should return code DSBLE0002 |
| 607 |
5. HealthCheck should return code DSBLE0002 |
| 608 |
""" |
| 609 |
|
| 610 |
RET_CODE = 'DSBLE0002' |
| 611 |
NEW_SUFFIX = 'dc=test,dc=com' |
| 612 |
NEW_BACKEND = 'userData' |
| 613 |
|
| 614 |
standalone = topology_st.standalone |
| 615 |
standalone.config.set("nsslapd-accesslog-logbuffering", "on") |
| 616 |
|
| 617 |
log.info('Create new suffix') |
| 618 |
backends = Backends(standalone) |
| 619 |
backends.create(properties={ |
| 620 |
'cn': NEW_BACKEND, |
| 621 |
'nsslapd-suffix': NEW_SUFFIX, |
| 622 |
}) |
| 623 |
|
| 624 |
log.info('Disable the newly created suffix') |
| 625 |
mts = MappingTrees(standalone) |
| 626 |
mt_new = mts.get(NEW_SUFFIX) |
| 627 |
mt_new.replace('nsslapd-state', 'disabled') |
| 628 |
|
| 629 |
standalone.stop() |
| 630 |
try: |
| 631 |
run_healthcheck_and_flush_log(topology_st.logcap, standalone, RET_CODE, json=False) |
| 632 |
run_healthcheck_and_flush_log(topology_st.logcap, standalone, RET_CODE, json=True) |
| 633 |
finally: |
| 634 |
if not standalone.status(): |
| 635 |
standalone.start() |
| 636 |
run_healthcheck_and_flush_log(topology_st.logcap, standalone, RET_CODE, json=False) |
| 637 |
run_healthcheck_and_flush_log(topology_st.logcap, standalone, RET_CODE, json=True) |
| 638 |
|
| 639 |
log.info('Enable the suffix again and check if nothing is broken') |
| 640 |
mt_new.replace('nsslapd-state', 'backend') |
| 641 |
standalone.stop() |
| 642 |
try: |
| 643 |
run_healthcheck_and_flush_log(topology_st.logcap, standalone, RET_CODE, json=False) |
| 644 |
run_healthcheck_and_flush_log(topology_st.logcap, standalone, RET_CODE, json=True) |
| 645 |
finally: |
| 646 |
if not standalone.status(): |
| 647 |
standalone.start() |
| 648 |
run_healthcheck_and_flush_log(topology_st.logcap, standalone, RET_CODE, json=False) |
| 649 |
run_healthcheck_and_flush_log(topology_st.logcap, standalone, RET_CODE, json=True) |
| 650 |
|
| 651 |
|
| 652 |
@pytest.mark.skipif(ds_is_older("1.4.1"), reason="Not implemented") |
| 653 |
def test_healthcheck_database_not_initialized(topology_no_sample): |
| 654 |
"""Check if HealthCheck returns DSBLE0003 code |
| 655 |
|
| 656 |
:id: 716b1ff1-94bd-4780-98b8-96ff8ef21e30 |
| 657 |
:setup: Standalone instance |
| 658 |
:steps: |
| 659 |
1. Create DS instance without example entries |
| 660 |
2. Use HealthCheck without --json option |
| 661 |
3. Use HealthCheck with --json option |
| 662 |
:expectedresults: |
| 663 |
1. Success |
| 664 |
2. HealthCheck should return code DSBLE0003 |
| 665 |
3. HealthCheck should return code DSBLE0003 |
| 666 |
""" |
| 667 |
|
| 668 |
RET_CODE = 'DSBLE0003' |
| 669 |
standalone = topology_no_sample.standalone |
| 670 |
|
| 671 |
run_healthcheck_and_flush_log(topology_no_sample.logcap, standalone, RET_CODE, json=False) |
| 672 |
run_healthcheck_and_flush_log(topology_no_sample.logcap, standalone, RET_CODE, json=True) |
| 673 |
|
| 674 |
|
| 675 |
@pytest.mark.skipif(get_default_db_lib() == "mdb", reason="Not needed for mdb") |
| 676 |
def test_lint_backend_implementation(topology_st): |
| 677 |
"""Test the lint for backend implementation mismatch |
| 678 |
|
| 679 |
:id: eff607de-768a-4cf4-bcde-48d4c7368934 |
| 680 |
:setup: Custom instance with db_lib set to either mdb or bdb. |
| 681 |
:steps: |
| 682 |
1. Fetch the 'nsslapd-backend-implement' attribute value. |
| 683 |
2. Manually set BDB as the backend implementation if MDB |
| 684 |
3. Run the linting function to check if BDB is used |
| 685 |
:expectedresults: |
| 686 |
1. The 'nsslapd-backend-implement' attribute is fetched correctly. |
| 687 |
2. The implementation is set to BDB. |
| 688 |
3. The linting function identifies that BDB is still used as a backend and reports the correct severity issue. |
| 689 |
""" |
| 690 |
|
| 691 |
RET_CODE = 'DSBLE0006' |
| 692 |
inst = topology_st.standalone |
| 693 |
|
| 694 |
inst.stop() |
| 695 |
try: |
| 696 |
run_healthcheck_and_flush_log(topology_st.logcap, inst, RET_CODE, json=False) |
| 697 |
run_healthcheck_and_flush_log(topology_st.logcap, inst, RET_CODE, json=True) |
| 698 |
finally: |
| 699 |
if not inst.status(): |
| 700 |
inst.start(post_open=False) |
| 701 |
|
| 702 |
run_healthcheck_and_flush_log(topology_st.logcap, inst, RET_CODE, json=False) |
| 703 |
run_healthcheck_and_flush_log(topology_st.logcap, inst, RET_CODE, json=True) |
| 704 |
|
| 705 |
|
| 706 |
def create_dummy_db_files(inst, backend_type): |
| 707 |
# Define the sets of dummy files for each backend type |
| 708 |
mdb_files = ['data.mdb', 'lock.mdb', 'INFO.mdb'] |
| 709 |
bdb_files = ['__db.001', 'DBVERSION', '__db.003', 'userRoot', 'log.0000000001', '__db.002'] |
| 710 |
|
| 711 |
# Determine the target file list based on the backend type |
| 712 |
if backend_type == 'mdb': |
| 713 |
target_files = mdb_files |
| 714 |
else: |
| 715 |
target_files = bdb_files |
| 716 |
|
| 717 |
# Get the database directory paths from the instance |
| 718 |
db_dir = inst.ds_paths.db_dir |
| 719 |
|
| 720 |
# Create dummy files in the primary database directory |
| 721 |
for filename in target_files: |
| 722 |
filepath = os.path.join(db_dir, filename) |
| 723 |
with open(filepath, 'w') as f: |
| 724 |
f.write('') # Create an empty file for simplicity |
| 725 |
|
| 726 |
|
| 727 |
def test_lint_backend_implementation_wrong_files(topology_st): |
| 728 |
"""Test the lint for backend implementation wrong files |
| 729 |
|
| 730 |
:id: 22cd14f2-c5ba-45e0-96fc-0678adc5c5db |
| 731 |
:setup: Custom instance with db_lib set to either mdb or bdb. |
| 732 |
:steps: |
| 733 |
1. Manually create dummy backend files for the test instance. |
| 734 |
2. Run the linting function to check for errors. |
| 735 |
:expectedresults: |
| 736 |
1. The dummy backend files are created successfully. |
| 737 |
2. The linting function identifies the issue and reports correctly. |
| 738 |
""" |
| 739 |
|
| 740 |
RET_CODE = 'DSBLE0004' |
| 741 |
|
| 742 |
inst = topology_st.standalone |
| 743 |
|
| 744 |
if inst.get_db_lib() == 'mdb': |
| 745 |
create_dummy_db_files(inst, 'bdb') |
| 746 |
else: |
| 747 |
create_dummy_db_files(inst, 'mdb') |
| 748 |
|
| 749 |
run_healthcheck_and_flush_log(topology_st.logcap, inst, RET_CODE, json=False) |
| 750 |
run_healthcheck_and_flush_log(topology_st.logcap, inst, RET_CODE, json=True) |
| 751 |
|
| 752 |
inst.stop() |
| 753 |
run_healthcheck_and_flush_log(topology_st.logcap, inst, RET_CODE, json=False) |
| 754 |
run_healthcheck_and_flush_log(topology_st.logcap, inst, RET_CODE, json=True) |
| 755 |
|
| 756 |
|
| 757 |
if __name__ == '__main__': |
| 758 |
# Run isolated |
| 759 |
# -s for DEBUG mode |
| 760 |
CURRENT_FILE = os.path.realpath(__file__) |