| 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 |
import subprocess |
| 13 |
import time |
| 14 |
from lib389.backend import Backends, DatabaseConfig |
| 15 |
from lib389.cos import CosTemplates, CosPointerDefinitions |
| 16 |
from lib389.dbgen import dbgen_users |
| 17 |
from lib389.idm.account import Accounts |
| 18 |
from lib389.index import Index |
| 19 |
from lib389.plugins import ReferentialIntegrityPlugin, MemberOfPlugin |
| 20 |
from lib389.utils import * |
| 21 |
from lib389._constants import * |
| 22 |
from lib389.cli_base import FakeArgs |
| 23 |
from test389.topologies import topology_st |
| 24 |
from lib389.cli_ctl.health import health_check_run |
| 25 |
from lib389.paths import Paths |
| 26 |
|
| 27 |
from time import sleep |
| 28 |
|
| 29 |
pytestmark = pytest.mark.tier1 |
| 30 |
|
| 31 |
CMD_OUTPUT = 'No issues found.' |
| 32 |
JSON_OUTPUT = '[]' |
| 33 |
log = logging.getLogger(__name__) |
| 34 |
|
| 35 |
|
| 36 |
def stop_and_flush(inst): |
| 37 |
inst.stop() |
| 38 |
inst.lint_clear_dse_cache() |
| 39 |
|
| 40 |
|
| 41 |
def run_healthcheck_and_flush_log(topology, instance, searched_code, json, searched_code2=None): |
| 42 |
# If we are using BDB as a backend, we will get error DSBLE0006 on new versions |
| 43 |
if ds_is_newer("3.0.0") and instance.get_db_lib() == 'bdb' and \ |
| 44 |
(searched_code is CMD_OUTPUT or searched_code is JSON_OUTPUT): |
| 45 |
searched_code = 'DSBLE0006' |
| 46 |
|
| 47 |
args = FakeArgs() |
| 48 |
args.instance = instance.serverid |
| 49 |
args.verbose = instance.verbose |
| 50 |
args.list_errors = False |
| 51 |
args.list_checks = False |
| 52 |
args.check = ['config', 'refint', 'backends', 'monitor-disk-space', 'logs', 'memberof'] |
| 53 |
args.dry_run = False |
| 54 |
args.exclude_check = [] |
| 55 |
|
| 56 |
if json: |
| 57 |
log.info('Use healthcheck with --json option') |
| 58 |
args.json = json |
| 59 |
health_check_run(instance, topology.logcap.log, args) |
| 60 |
assert topology.logcap.contains(searched_code) |
| 61 |
log.info('Healthcheck returned searched code: %s' % searched_code) |
| 62 |
|
| 63 |
if searched_code2 is not None: |
| 64 |
assert topology.logcap.contains(searched_code2) |
| 65 |
log.info('Healthcheck returned searched code: %s' % searched_code2) |
| 66 |
else: |
| 67 |
log.info('Use healthcheck without --json option') |
| 68 |
args.json = json |
| 69 |
health_check_run(instance, topology.logcap.log, args) |
| 70 |
|
| 71 |
assert topology.logcap.contains(searched_code) |
| 72 |
log.info('Healthcheck returned searched code: %s' % searched_code) |
| 73 |
|
| 74 |
if searched_code2 is not None: |
| 75 |
assert topology.logcap.contains(searched_code2) |
| 76 |
log.info('Healthcheck returned searched code: %s' % searched_code2) |
| 77 |
|
| 78 |
log.info('Clear the log') |
| 79 |
topology.logcap.flush() |
| 80 |
|
| 81 |
|
| 82 |
@pytest.fixture(scope="function") |
| 83 |
def setup_ldif(topology_st, request): |
| 84 |
log.info("Generating LDIF...") |
| 85 |
ldif_dir = topology_st.standalone.get_ldif_dir() |
| 86 |
global import_ldif |
| 87 |
import_ldif = ldif_dir + '/basic_import.ldif' |
| 88 |
dbgen_users(topology_st.standalone, 5000, import_ldif, DEFAULT_SUFFIX) |
| 89 |
|
| 90 |
def fin(): |
| 91 |
log.info('Delete file') |
| 92 |
os.remove(import_ldif) |
| 93 |
|
| 94 |
request.addfinalizer(fin) |
| 95 |
|
| 96 |
|
| 97 |
@pytest.mark.xfail(ds_is_older("1.4.1"), reason="Not implemented") |
| 98 |
def test_healthcheck_RI_plugin_is_misconfigured(topology_st): |
| 99 |
"""Check if HealthCheck returns DSRILE0001 code |
| 100 |
|
| 101 |
:id: de2e90a2-89fe-472c-acdb-e13cbca5178d |
| 102 |
:setup: Standalone instance |
| 103 |
:steps: |
| 104 |
1. Create DS instance |
| 105 |
2. Configure the instance with Integrity Plugin |
| 106 |
3. Set the referint-update-delay attribute of the RI plugin, to a value upper than 0 |
| 107 |
4. Use HealthCheck without --json option |
| 108 |
5. Use HealthCheck with --json option |
| 109 |
6. Set the referint-update-delay attribute to 0 |
| 110 |
7. Use HealthCheck without --json option |
| 111 |
8. Use HealthCheck with --json option |
| 112 |
:expectedresults: |
| 113 |
1. Success |
| 114 |
2. Success |
| 115 |
3. Success |
| 116 |
4. Healthcheck reports DSRILE0001 code and related details |
| 117 |
5. Healthcheck reports DSRILE0001 code and related details |
| 118 |
6. Success |
| 119 |
7. Healthcheck reports no issue found |
| 120 |
8. Healthcheck reports no issue found |
| 121 |
""" |
| 122 |
|
| 123 |
RET_CODE = 'DSRILE0001' |
| 124 |
|
| 125 |
standalone = topology_st.standalone |
| 126 |
|
| 127 |
standalone.config.set("nsslapd-accesslog-logbuffering", "on") |
| 128 |
|
| 129 |
plugin = ReferentialIntegrityPlugin(standalone) |
| 130 |
plugin.disable() |
| 131 |
plugin.enable() |
| 132 |
|
| 133 |
log.info('Set the referint-update-delay attribute to a value upper than 0') |
| 134 |
plugin.replace('referint-update-delay', '5') |
| 135 |
|
| 136 |
stop_and_flush(standalone) |
| 137 |
try: |
| 138 |
run_healthcheck_and_flush_log(topology_st, standalone, json=False, searched_code=RET_CODE) |
| 139 |
run_healthcheck_and_flush_log(topology_st, standalone, json=True, searched_code=RET_CODE) |
| 140 |
finally: |
| 141 |
if not standalone.status(): |
| 142 |
standalone.start() |
| 143 |
run_healthcheck_and_flush_log(topology_st, standalone, json=False, searched_code=RET_CODE) |
| 144 |
run_healthcheck_and_flush_log(topology_st, standalone, json=True, searched_code=RET_CODE) |
| 145 |
|
| 146 |
log.info('Set the referint-update-delay attribute back to 0') |
| 147 |
plugin.replace('referint-update-delay', '0') |
| 148 |
|
| 149 |
stop_and_flush(standalone) |
| 150 |
try: |
| 151 |
run_healthcheck_and_flush_log(topology_st, standalone, json=False, searched_code=CMD_OUTPUT) |
| 152 |
run_healthcheck_and_flush_log(topology_st, standalone, json=True, searched_code=JSON_OUTPUT) |
| 153 |
finally: |
| 154 |
if not standalone.status(): |
| 155 |
standalone.start() |
| 156 |
run_healthcheck_and_flush_log(topology_st, standalone, json=False, searched_code=CMD_OUTPUT) |
| 157 |
run_healthcheck_and_flush_log(topology_st, standalone, json=True, searched_code=JSON_OUTPUT) |
| 158 |
|
| 159 |
|
| 160 |
@pytest.mark.xfail(ds_is_older("1.4.1"), reason="Not implemented") |
| 161 |
def test_healthcheck_RI_plugin_missing_indexes(topology_st): |
| 162 |
"""Check if HealthCheck returns DSRILE0002 code |
| 163 |
|
| 164 |
:id: 05c55e37-bb3e-48d1-bbe8-29c980f94f10 |
| 165 |
:setup: Standalone instance |
| 166 |
:steps: |
| 167 |
1. Create DS instance |
| 168 |
2. Configure the instance with Integrity Plugin |
| 169 |
3. Change the index type of the member attribute index to ‘approx’ |
| 170 |
4. Use HealthCheck without --json option |
| 171 |
5. Use HealthCheck with --json option |
| 172 |
6. Set the index type of the member attribute index to ‘eq’ |
| 173 |
7. Use HealthCheck without --json option |
| 174 |
8. Use HealthCheck with --json option |
| 175 |
:expectedresults: |
| 176 |
1. Success |
| 177 |
2. Success |
| 178 |
3. Success |
| 179 |
4. Healthcheck reports DSRILE0002 code and related details |
| 180 |
5. Healthcheck reports DSRILE0002 code and related details |
| 181 |
6. Success |
| 182 |
7. Healthcheck reports no issue found |
| 183 |
8. Healthcheck reports no issue found |
| 184 |
""" |
| 185 |
|
| 186 |
RET_CODE = 'DSRILE0002' |
| 187 |
MEMBER_DN = 'cn=member,cn=index,cn=userroot,cn=ldbm database,cn=plugins,cn=config' |
| 188 |
|
| 189 |
standalone = topology_st.standalone |
| 190 |
standalone.config.set("nsslapd-accesslog-logbuffering", "on") |
| 191 |
|
| 192 |
log.info('Enable RI plugin') |
| 193 |
plugin = ReferentialIntegrityPlugin(standalone) |
| 194 |
plugin.disable() |
| 195 |
plugin.enable() |
| 196 |
|
| 197 |
log.info('Change the index type of the member attribute index to approx') |
| 198 |
index = Index(topology_st.standalone, MEMBER_DN) |
| 199 |
index.replace('nsIndexType', 'approx') |
| 200 |
|
| 201 |
stop_and_flush(standalone) |
| 202 |
try: |
| 203 |
run_healthcheck_and_flush_log(topology_st, standalone, json=False, searched_code=RET_CODE) |
| 204 |
run_healthcheck_and_flush_log(topology_st, standalone, json=True, searched_code=RET_CODE) |
| 205 |
finally: |
| 206 |
if not standalone.status(): |
| 207 |
standalone.start() |
| 208 |
run_healthcheck_and_flush_log(topology_st, standalone, json=False, searched_code=RET_CODE) |
| 209 |
run_healthcheck_and_flush_log(topology_st, standalone, json=True, searched_code=RET_CODE) |
| 210 |
|
| 211 |
log.info('Set the index type of the member attribute index back to eq') |
| 212 |
index.replace('nsIndexType', 'eq') |
| 213 |
|
| 214 |
stop_and_flush(standalone) |
| 215 |
try: |
| 216 |
run_healthcheck_and_flush_log(topology_st, standalone, json=False, searched_code=CMD_OUTPUT) |
| 217 |
run_healthcheck_and_flush_log(topology_st, standalone, json=True, searched_code=JSON_OUTPUT) |
| 218 |
finally: |
| 219 |
if not standalone.status(): |
| 220 |
standalone.start() |
| 221 |
run_healthcheck_and_flush_log(topology_st, standalone, json=False, searched_code=CMD_OUTPUT) |
| 222 |
run_healthcheck_and_flush_log(topology_st, standalone, json=True, searched_code=JSON_OUTPUT) |
| 223 |
|
| 224 |
|
| 225 |
def test_healthcheck_MO_plugin_missing_indexes(topology_st): |
| 226 |
"""Check if HealthCheck returns DSMOLE0001 code |
| 227 |
|
| 228 |
:id: 236b0ec2-13da-48fb-b65a-db7406d56d5d |
| 229 |
:setup: Standalone instance |
| 230 |
:steps: |
| 231 |
1. Create DS instance |
| 232 |
2. Configure the instance with MO Plugin with two memberOfGroupAttrs |
| 233 |
3. Use HealthCheck without --json option |
| 234 |
4. Use HealthCheck with --json option |
| 235 |
5. Add index for new group attr |
| 236 |
6. Use HealthCheck without --json option |
| 237 |
7. Use HealthCheck with --json option |
| 238 |
:expectedresults: |
| 239 |
1. Success |
| 240 |
2. Success |
| 241 |
3. Healthcheck reports DSMOLE0001 code and related details |
| 242 |
4. Healthcheck reports DSMOLE0001 code and related details |
| 243 |
5. Success |
| 244 |
6. Healthcheck reports no issue found |
| 245 |
7. Healthcheck reports no issue found |
| 246 |
""" |
| 247 |
|
| 248 |
RET_CODE = 'DSMOLE0001' |
| 249 |
MO_GROUP_ATTR = 'creatorsname' |
| 250 |
|
| 251 |
standalone = topology_st.standalone |
| 252 |
standalone.config.set("nsslapd-accesslog-logbuffering", "on") |
| 253 |
|
| 254 |
log.info('Enable MO plugin') |
| 255 |
plugin = MemberOfPlugin(standalone) |
| 256 |
plugin.disable() |
| 257 |
plugin.enable() |
| 258 |
plugin.add('memberofgroupattr', MO_GROUP_ATTR) |
| 259 |
time.sleep(.5) |
| 260 |
|
| 261 |
stop_and_flush(standalone) |
| 262 |
try: |
| 263 |
run_healthcheck_and_flush_log(topology_st, standalone, json=False, searched_code=RET_CODE) |
| 264 |
run_healthcheck_and_flush_log(topology_st, standalone, json=True, searched_code=RET_CODE) |
| 265 |
finally: |
| 266 |
if not standalone.status(): |
| 267 |
standalone.start() |
| 268 |
run_healthcheck_and_flush_log(topology_st, standalone, json=False, searched_code=RET_CODE) |
| 269 |
run_healthcheck_and_flush_log(topology_st, standalone, json=True, searched_code=RET_CODE) |
| 270 |
|
| 271 |
log.info('Add the missing "eq" index') |
| 272 |
be = Backends(standalone).get('userRoot') |
| 273 |
be.add_index(MO_GROUP_ATTR, "eq", None) |
| 274 |
time.sleep(.5) |
| 275 |
|
| 276 |
stop_and_flush(standalone) |
| 277 |
try: |
| 278 |
run_healthcheck_and_flush_log(topology_st, standalone, json=False, searched_code=CMD_OUTPUT) |
| 279 |
run_healthcheck_and_flush_log(topology_st, standalone, json=True, searched_code=JSON_OUTPUT) |
| 280 |
finally: |
| 281 |
if not standalone.status(): |
| 282 |
standalone.start() |
| 283 |
run_healthcheck_and_flush_log(topology_st, standalone, json=False, searched_code=CMD_OUTPUT) |
| 284 |
run_healthcheck_and_flush_log(topology_st, standalone, json=True, searched_code=JSON_OUTPUT) |
| 285 |
# Restart the intsnce after changing the plugin to avoid breaking the other tests |
| 286 |
standalone.restart() |
| 287 |
|
| 288 |
|
| 289 |
def test_healthcheck_MO_plugin_substring_index(topology_st): |
| 290 |
"""Check if HealthCheck returns DSMOLE0002 code when the |
| 291 |
member, uniquemember attribute contains a substring index type |
| 292 |
|
| 293 |
:id: 10954811-24ac-4886-8183-e30892f8e02d |
| 294 |
:setup: Standalone instance |
| 295 |
:steps: |
| 296 |
1. Create DS instance |
| 297 |
2. Configure the instance with MO Plugin |
| 298 |
3. Change index type to substring for member attribute |
| 299 |
4. Use HealthCheck without --json option |
| 300 |
5. Use HealthCheck with --json option |
| 301 |
6. Change index type back to equality for member attribute |
| 302 |
7. Use HealthCheck without --json option |
| 303 |
8. Use HealthCheck with --json option |
| 304 |
9. Change index type to substring for uniquemember attribute |
| 305 |
10. Use HealthCheck without --json option |
| 306 |
11. Use HealthCheck with --json option |
| 307 |
12. Change index type back to equality for uniquemember attribute |
| 308 |
13. Use HealthCheck without --json option |
| 309 |
14. Use HealthCheck with --json option |
| 310 |
|
| 311 |
:expectedresults: |
| 312 |
1. Success |
| 313 |
2. Success |
| 314 |
3. Success |
| 315 |
4. Healthcheck reports DSMOLE0002 code and related details |
| 316 |
5. Healthcheck reports DSMOLE0002 code and related details |
| 317 |
6. Success |
| 318 |
7. Healthcheck reports no issue found |
| 319 |
8. Healthcheck reports no issue found |
| 320 |
9. Success |
| 321 |
10. Healthcheck reports DSMOLE0002 code and related details |
| 322 |
11. Healthcheck reports DSMOLE0002 code and related details |
| 323 |
12. Success |
| 324 |
13. Healthcheck reports no issue found |
| 325 |
14. Healthcheck reports no issue found |
| 326 |
""" |
| 327 |
|
| 328 |
RET_CODE = 'DSMOLE0002' |
| 329 |
MEMBER_DN = 'cn=member,cn=index,cn=userroot,cn=ldbm database,cn=plugins,cn=config' |
| 330 |
UNIQUE_MEMBER_DN = 'cn=uniquemember,cn=index,cn=userroot,cn=ldbm database,cn=plugins,cn=config' |
| 331 |
|
| 332 |
standalone = topology_st.standalone |
| 333 |
standalone.config.set("nsslapd-accesslog-logbuffering", "on") |
| 334 |
|
| 335 |
log.info('Enable MO plugin') |
| 336 |
plugin = MemberOfPlugin(standalone) |
| 337 |
plugin.disable() |
| 338 |
plugin.enable() |
| 339 |
|
| 340 |
log.info('Change the index type of the member attribute index to substring') |
| 341 |
index = Index(topology_st.standalone, MEMBER_DN) |
| 342 |
index.replace('nsIndexType', 'sub') |
| 343 |
|
| 344 |
stop_and_flush(standalone) |
| 345 |
try: |
| 346 |
run_healthcheck_and_flush_log(topology_st, standalone, json=False, searched_code=RET_CODE) |
| 347 |
run_healthcheck_and_flush_log(topology_st, standalone, json=True, searched_code=RET_CODE) |
| 348 |
finally: |
| 349 |
if not standalone.status(): |
| 350 |
standalone.start() |
| 351 |
run_healthcheck_and_flush_log(topology_st, standalone, json=False, searched_code=RET_CODE) |
| 352 |
run_healthcheck_and_flush_log(topology_st, standalone, json=True, searched_code=RET_CODE) |
| 353 |
|
| 354 |
log.info('Set the index type of the member attribute index back to eq') |
| 355 |
index.replace('nsIndexType', 'eq') |
| 356 |
|
| 357 |
stop_and_flush(standalone) |
| 358 |
try: |
| 359 |
run_healthcheck_and_flush_log(topology_st, standalone, json=False, searched_code=CMD_OUTPUT) |
| 360 |
run_healthcheck_and_flush_log(topology_st, standalone, json=True, searched_code=JSON_OUTPUT) |
| 361 |
finally: |
| 362 |
if not standalone.status(): |
| 363 |
standalone.start() |
| 364 |
run_healthcheck_and_flush_log(topology_st, standalone, json=False, searched_code=CMD_OUTPUT) |
| 365 |
run_healthcheck_and_flush_log(topology_st, standalone, json=True, searched_code=JSON_OUTPUT) |
| 366 |
|
| 367 |
log.info('Change the index type of the uniquemember attribute index to substring') |
| 368 |
index = Index(topology_st.standalone, UNIQUE_MEMBER_DN) |
| 369 |
index.replace('nsIndexType', 'sub') |
| 370 |
|
| 371 |
stop_and_flush(standalone) |
| 372 |
try: |
| 373 |
run_healthcheck_and_flush_log(topology_st, standalone, json=False, searched_code=RET_CODE) |
| 374 |
run_healthcheck_and_flush_log(topology_st, standalone, json=True, searched_code=RET_CODE) |
| 375 |
finally: |
| 376 |
if not standalone.status(): |
| 377 |
standalone.start() |
| 378 |
run_healthcheck_and_flush_log(topology_st, standalone, json=False, searched_code=RET_CODE) |
| 379 |
run_healthcheck_and_flush_log(topology_st, standalone, json=True, searched_code=RET_CODE) |
| 380 |
|
| 381 |
log.info('Set the index type of the uniquemember attribute index back to eq') |
| 382 |
index.replace('nsIndexType', 'eq') |
| 383 |
|
| 384 |
stop_and_flush(standalone) |
| 385 |
try: |
| 386 |
run_healthcheck_and_flush_log(topology_st, standalone, json=False, searched_code=CMD_OUTPUT) |
| 387 |
run_healthcheck_and_flush_log(topology_st, standalone, json=True, searched_code=JSON_OUTPUT) |
| 388 |
finally: |
| 389 |
if not standalone.status(): |
| 390 |
standalone.start() |
| 391 |
run_healthcheck_and_flush_log(topology_st, standalone, json=False, searched_code=CMD_OUTPUT) |
| 392 |
run_healthcheck_and_flush_log(topology_st, standalone, json=True, searched_code=JSON_OUTPUT) |
| 393 |
|
| 394 |
# Restart the instance after changing the plugin to avoid breaking the other tests |
| 395 |
standalone.restart() |
| 396 |
|
| 397 |
|
| 398 |
def test_healthcheck_MO_plugin_global_lock(topology_st): |
| 399 |
"""Verify HealthCheck returns DSMOLE0003 when memberOfAllBackends=on |
| 400 |
and nsslapd-global-backend-lock=off |
| 401 |
|
| 402 |
:id: 2a93f824-4bb7-4958-adcb-4e8ba17bfcc0 |
| 403 |
:setup: Standalone instance |
| 404 |
:steps: |
| 405 |
1. Create DS instance |
| 406 |
2. Configure the instance with MO Plugin |
| 407 |
3. Set memberOfAllBackends and nsslapd-global-backend-lock to off |
| 408 |
4. Use HealthCheck without --json option |
| 409 |
5. Use HealthCheck with --json option |
| 410 |
6. Set memberOfAllBackends to on and nsslapd-global-backend-lock to off |
| 411 |
7. Use HealthCheck without --json option |
| 412 |
8. Use HealthCheck with --json option |
| 413 |
|
| 414 |
:expectedresults: |
| 415 |
1. Success |
| 416 |
2. Success |
| 417 |
3. Success |
| 418 |
4. Healthcheck reports no issue found |
| 419 |
5. Healthcheck reports no issue found |
| 420 |
6. Success |
| 421 |
7. Healthcheck reports DSMOLE0003 code and related details |
| 422 |
8. Healthcheck reports DSMOLE0003 code and related details |
| 423 |
""" |
| 424 |
|
| 425 |
RET_CODE = 'DSMOLE0003' |
| 426 |
|
| 427 |
standalone = topology_st.standalone |
| 428 |
standalone.config.set("nsslapd-accesslog-logbuffering", "on") |
| 429 |
|
| 430 |
log.info('Enable MO plugin') |
| 431 |
plugin = MemberOfPlugin(standalone) |
| 432 |
plugin.disable() |
| 433 |
plugin.enable() |
| 434 |
|
| 435 |
log.info('Verify no return code') |
| 436 |
standalone.config.set('nsslapd-global-backend-lock', "off") |
| 437 |
plugin.replace('memberOfAllBackends', 'off') |
| 438 |
standalone.restart() |
| 439 |
assert plugin.get_attr_val_utf8('memberOfAllBackends') == "off" |
| 440 |
assert standalone.config.get_attr_val_utf8('nsslapd-global-backend-lock') == 'off' |
| 441 |
|
| 442 |
stop_and_flush(standalone) |
| 443 |
try: |
| 444 |
run_healthcheck_and_flush_log(topology_st, standalone, CMD_OUTPUT, json=False) |
| 445 |
run_healthcheck_and_flush_log(topology_st, standalone, JSON_OUTPUT, json=True) |
| 446 |
finally: |
| 447 |
if not standalone.status(): |
| 448 |
standalone.start() |
| 449 |
run_healthcheck_and_flush_log(topology_st, standalone, CMD_OUTPUT, json=False) |
| 450 |
run_healthcheck_and_flush_log(topology_st, standalone, JSON_OUTPUT, json=True) |
| 451 |
|
| 452 |
log.info('Verify return code') |
| 453 |
plugin.replace('memberOfAllBackends', 'on') |
| 454 |
standalone.restart() |
| 455 |
assert plugin.get_attr_val_utf8('memberOfAllBackends') == "on" |
| 456 |
assert standalone.config.get_attr_val_utf8('nsslapd-global-backend-lock') == 'off' |
| 457 |
|
| 458 |
stop_and_flush(standalone) |
| 459 |
try: |
| 460 |
run_healthcheck_and_flush_log(topology_st, standalone, RET_CODE, json=False) |
| 461 |
run_healthcheck_and_flush_log(topology_st, standalone, RET_CODE, json=True) |
| 462 |
finally: |
| 463 |
if not standalone.status(): |
| 464 |
standalone.start() |
| 465 |
run_healthcheck_and_flush_log(topology_st, standalone, RET_CODE, json=False) |
| 466 |
run_healthcheck_and_flush_log(topology_st, standalone, RET_CODE, json=True) |
| 467 |
|
| 468 |
# Restart the instance after changing the plugin to avoid breaking the other tests |
| 469 |
plugin.replace('memberOfAllBackends', 'off') |
| 470 |
standalone.restart() |
| 471 |
|
| 472 |
|
| 473 |
@pytest.mark.xfail(ds_is_older("1.4.1"), reason="Not implemented") |
| 474 |
def test_healthcheck_virtual_attr_incorrectly_indexed(topology_st): |
| 475 |
"""Check if HealthCheck returns DSVIRTLE0001 code |
| 476 |
|
| 477 |
:id: 1055173b-21aa-4aaa-9e91-4dc6c5e0c01f |
| 478 |
:setup: Standalone instance |
| 479 |
:steps: |
| 480 |
1. Create DS instance |
| 481 |
2. Create a CoS definition entry |
| 482 |
3. Create the matching CoS template entry, with postalcode as virtual attribute |
| 483 |
4. Create an index for postalcode |
| 484 |
5. Use HealthCheck without --json option |
| 485 |
6. Use HealthCheck with --json option |
| 486 |
:expectedresults: |
| 487 |
1. Success |
| 488 |
2. Success |
| 489 |
3. Success |
| 490 |
4. Success |
| 491 |
5. Healthcheck reports DSVIRTLE0001 code and related details |
| 492 |
6. Healthcheck reports DSVIRTLE0001 code and related details |
| 493 |
""" |
| 494 |
|
| 495 |
RET_CODE = 'DSVIRTLE0001' |
| 496 |
|
| 497 |
standalone = topology_st.standalone |
| 498 |
standalone.config.set("nsslapd-accesslog-logbuffering", "on") |
| 499 |
|
| 500 |
postal_index_properties = { |
| 501 |
'cn': 'postalcode', |
| 502 |
'nsSystemIndex': 'False', |
| 503 |
'nsIndexType': ['eq', 'sub', 'pres'], |
| 504 |
} |
| 505 |
|
| 506 |
log.info('Add cosPointer, cosTemplate and test entry to default suffix, where virtual attribute is postal code') |
| 507 |
cos_pointer_properties = { |
| 508 |
'cn': 'cosPointer', |
| 509 |
'description': 'cosPointer example', |
| 510 |
'cosTemplateDn': 'cn=cosTemplateExample,ou=People,dc=example,dc=com', |
| 511 |
'cosAttribute': 'postalcode', |
| 512 |
} |
| 513 |
cos_pointer_definitions = CosPointerDefinitions(standalone, DEFAULT_SUFFIX, 'ou=People') |
| 514 |
cos_pointer_definitions.create(properties=cos_pointer_properties) |
| 515 |
|
| 516 |
log.info('Create CoS template') |
| 517 |
cos_template_properties = { |
| 518 |
'cn': 'cosTemplateExample', |
| 519 |
'postalcode': '117' |
| 520 |
} |
| 521 |
cos_templates = CosTemplates(standalone, DEFAULT_SUFFIX, 'ou=People') |
| 522 |
cos_templates.create(properties=cos_template_properties) |
| 523 |
|
| 524 |
log.info('Create an index for postalcode') |
| 525 |
backends = Backends(topology_st.standalone) |
| 526 |
ur_indexes = backends.get('userRoot').get_indexes() |
| 527 |
ur_indexes.create(properties=postal_index_properties) |
| 528 |
|
| 529 |
run_healthcheck_and_flush_log(topology_st, standalone, RET_CODE, json=False) |
| 530 |
run_healthcheck_and_flush_log(topology_st, standalone, RET_CODE, json=True) |
| 531 |
|
| 532 |
|
| 533 |
@pytest.mark.xfail(ds_is_older("1.4.1"), reason="Not implemented") |
| 534 |
@pytest.mark.xfail(ds_is_older("1.4.2.4"), reason="May fail because of bug 1796050") |
| 535 |
def test_healthcheck_low_disk_space(topology_st): |
| 536 |
"""Check if HealthCheck returns DSDSLE0001 code |
| 537 |
|
| 538 |
:id: 144b335d-077e-430c-9c0e-cd6b0f2f73c1 |
| 539 |
:setup: Standalone instance |
| 540 |
:steps: |
| 541 |
1. Create DS instance |
| 542 |
2. Get the free disk space for / |
| 543 |
3. Use fallocate to create a file large enough for the use % be up 90% |
| 544 |
4. Use HealthCheck without --json option |
| 545 |
5. Use HealthCheck with --json option |
| 546 |
:expectedresults: |
| 547 |
1. Success |
| 548 |
2. Success |
| 549 |
3. Success |
| 550 |
4. Healthcheck reports DSDSLE0001 code and related details |
| 551 |
5. Healthcheck reports DSDSLE0001 code and related details |
| 552 |
""" |
| 553 |
|
| 554 |
RET_CODE = 'DSDSLE0001' |
| 555 |
|
| 556 |
standalone = topology_st.standalone |
| 557 |
standalone.config.set("nsslapd-accesslog-logbuffering", "on") |
| 558 |
file = '{}/foo'.format(standalone.ds_paths.log_dir) |
| 559 |
|
| 560 |
log.info('Count the disk space to allocate') |
| 561 |
total_size = int(re.findall(r'\d+', str(os.statvfs(standalone.ds_paths.log_dir)))[2]) * 4096 |
| 562 |
avail_size = round(int(re.findall(r'\d+', str(os.statvfs(standalone.ds_paths.log_dir)))[3]) * 4096) |
| 563 |
used_size = total_size - avail_size |
| 564 |
count_total_percent = total_size * 0.92 |
| 565 |
final_value = count_total_percent - used_size |
| 566 |
|
| 567 |
log.info('Create a file large enough for the use % be up 90%') |
| 568 |
subprocess.call(['fallocate', '-l', str(round(final_value)), file]) |
| 569 |
|
| 570 |
run_healthcheck_and_flush_log(topology_st, standalone, RET_CODE, json=False) |
| 571 |
run_healthcheck_and_flush_log(topology_st, standalone, RET_CODE, json=True) |
| 572 |
|
| 573 |
log.info('Remove created file') |
| 574 |
os.remove(file) |
| 575 |
|
| 576 |
|
| 577 |
@pytest.mark.flaky(max_runs=2, min_passes=1) |
| 578 |
@pytest.mark.xfail(ds_is_older("1.4.3.8"), reason="Not implemented") |
| 579 |
def test_healthcheck_notes_unindexed_search(topology_st, setup_ldif): |
| 580 |
"""Check if HealthCheck returns DSLOGNOTES0001 code |
| 581 |
|
| 582 |
:id: b25f7027-d43f-4ec2-ac49-9c9bb285df1d |
| 583 |
:setup: Standalone instance |
| 584 |
:steps: |
| 585 |
1. Create DS instance |
| 586 |
2. Set nsslapd-accesslog-logbuffering to off |
| 587 |
3. Import users from created ldif file |
| 588 |
4. Use HealthCheck without --json option |
| 589 |
5. Use HealthCheck with --json option |
| 590 |
:expectedresults: |
| 591 |
1. Success |
| 592 |
2. Success |
| 593 |
3. Success |
| 594 |
4. Healthcheck reports DSLOGNOTES0001 |
| 595 |
5. Healthcheck reports DSLOGNOTES0001 |
| 596 |
""" |
| 597 |
|
| 598 |
RET_CODE = 'DSLOGNOTES0001' |
| 599 |
|
| 600 |
standalone = topology_st.standalone |
| 601 |
|
| 602 |
log.info('Delete the previous access logs') |
| 603 |
standalone.deleteAccessLogs() |
| 604 |
|
| 605 |
log.info('Set nsslapd-accesslog-logbuffering to off') |
| 606 |
standalone.config.set("nsslapd-accesslog-logbuffering", "off") |
| 607 |
db_cfg = DatabaseConfig(standalone) |
| 608 |
db_cfg.set([('nsslapd-idlistscanlimit', '100')]) |
| 609 |
|
| 610 |
log.info('Stopping the server and running offline import...') |
| 611 |
stop_and_flush(standalone) |
| 612 |
assert standalone.ldif2db(bename=DEFAULT_BENAME, suffixes=[DEFAULT_SUFFIX], encrypt=None, excludeSuffixes=None, |
| 613 |
import_file=import_ldif) |
| 614 |
standalone.start() |
| 615 |
|
| 616 |
log.info('Use filters to reproduce "notes=A" in access log') |
| 617 |
accounts = Accounts(standalone, DEFAULT_SUFFIX) |
| 618 |
accounts.filter('(uid=test*)') |
| 619 |
sleep(1) |
| 620 |
|
| 621 |
log.info('Check that access log contains "notes=A"') |
| 622 |
assert standalone.ds_access_log.match(r'.*notes=A.*') |
| 623 |
|
| 624 |
standalone.config.set("nsslapd-accesslog-logbuffering", "on") |
| 625 |
|
| 626 |
stop_and_flush(standalone) |
| 627 |
try: |
| 628 |
run_healthcheck_and_flush_log(topology_st, standalone, RET_CODE, json=False) |
| 629 |
run_healthcheck_and_flush_log(topology_st, standalone, RET_CODE, json=True) |
| 630 |
finally: |
| 631 |
if not standalone.status(): |
| 632 |
standalone.start() |
| 633 |
run_healthcheck_and_flush_log(topology_st, standalone, RET_CODE, json=False) |
| 634 |
run_healthcheck_and_flush_log(topology_st, standalone, RET_CODE, json=True) |
| 635 |
|
| 636 |
|
| 637 |
@pytest.mark.xfail(ds_is_older("1.4.3.8"), reason="Not implemented") |
| 638 |
def test_healthcheck_notes_unknown_attribute(topology_st, setup_ldif): |
| 639 |
"""Check if HealthCheck returns DSLOGNOTES0002 code |
| 640 |
|
| 641 |
:id: 71ccd1d7-3c71-416b-9d2a-27f9f6633101 |
| 642 |
:setup: Standalone instance |
| 643 |
:steps: |
| 644 |
1. Create DS instance |
| 645 |
2. Set nsslapd-accesslog-logbuffering to off |
| 646 |
3. Import users from created ldif file |
| 647 |
4. Use HealthCheck without --json option |
| 648 |
5. Use HealthCheck with --json option |
| 649 |
:expectedresults: |
| 650 |
1. Success |
| 651 |
2. Success |
| 652 |
3. Success |
| 653 |
4. Healthcheck reports DSLOGNOTES0002 |
| 654 |
5. Healthcheck reports DSLOGNOTES0002 |
| 655 |
""" |
| 656 |
|
| 657 |
RET_CODE = 'DSLOGNOTES0002' |
| 658 |
|
| 659 |
standalone = topology_st.standalone |
| 660 |
|
| 661 |
log.info('Delete the previous access logs') |
| 662 |
topology_st.standalone.deleteAccessLogs() |
| 663 |
|
| 664 |
log.info('Set nsslapd-accesslog-logbuffering to off') |
| 665 |
standalone.config.set("nsslapd-accesslog-logbuffering", "off") |
| 666 |
db_cfg = DatabaseConfig(standalone) |
| 667 |
db_cfg.set([('nsslapd-idlistscanlimit', '100')]) |
| 668 |
|
| 669 |
log.info('Stopping the server and running offline import...') |
| 670 |
standalone.stop() |
| 671 |
assert standalone.ldif2db(bename=DEFAULT_BENAME, suffixes=[DEFAULT_SUFFIX], encrypt=None, excludeSuffixes=None, |
| 672 |
import_file=import_ldif) |
| 673 |
standalone.start() |
| 674 |
|
| 675 |
log.info('Use filters to reproduce "notes=F" in access log') |
| 676 |
accounts = Accounts(standalone, DEFAULT_SUFFIX) |
| 677 |
accounts.filter('(unknown=test)') |
| 678 |
sleep(1) |
| 679 |
|
| 680 |
log.info('Check that access log contains "notes=F"') |
| 681 |
assert standalone.ds_access_log.match(r'.*notes=F.*') |
| 682 |
|
| 683 |
standalone.config.set("nsslapd-accesslog-logbuffering", "on") |
| 684 |
stop_and_flush(standalone) |
| 685 |
try: |
| 686 |
run_healthcheck_and_flush_log(topology_st, standalone, RET_CODE, json=False) |
| 687 |
run_healthcheck_and_flush_log(topology_st, standalone, RET_CODE, json=True) |
| 688 |
finally: |
| 689 |
if not standalone.status(): |
| 690 |
standalone.start() |
| 691 |
run_healthcheck_and_flush_log(topology_st, standalone, RET_CODE, json=False) |
| 692 |
run_healthcheck_and_flush_log(topology_st, standalone, RET_CODE, json=True) |
| 693 |
|
| 694 |
|
| 695 |
def test_healthcheck_unauth_binds(topology_st): |
| 696 |
"""Check if HealthCheck returns DSCLE0003 code when unauthorized binds are |
| 697 |
allowed |
| 698 |
|
| 699 |
:id: 13b88a3b-0dc5-4ce9-9fbf-058ad072339b |
| 700 |
:setup: Standalone instance |
| 701 |
:steps: |
| 702 |
1. Create DS instance |
| 703 |
2. Set nsslapd-allow-unauthenticated-binds to on |
| 704 |
3. Use HealthCheck without --json option |
| 705 |
4. Use HealthCheck with --json option |
| 706 |
:expectedresults: |
| 707 |
1. Success |
| 708 |
2. Success |
| 709 |
3. Healthcheck reports DSCLE0003 |
| 710 |
4. Healthcheck reports DSCLE0003 |
| 711 |
""" |
| 712 |
|
| 713 |
RET_CODE = 'DSCLE0003' |
| 714 |
|
| 715 |
inst = topology_st.standalone |
| 716 |
inst.config.set("nsslapd-accesslog-logbuffering", "on") |
| 717 |
|
| 718 |
log.info('nsslapd-allow-unauthenticated-binds to on') |
| 719 |
inst.config.set("nsslapd-allow-unauthenticated-binds", "on") |
| 720 |
|
| 721 |
stop_and_flush(inst) |
| 722 |
try: |
| 723 |
run_healthcheck_and_flush_log(topology_st, inst, RET_CODE, json=False) |
| 724 |
run_healthcheck_and_flush_log(topology_st, inst, RET_CODE, json=True) |
| 725 |
finally: |
| 726 |
if not inst.status(): |
| 727 |
inst.start() |
| 728 |
run_healthcheck_and_flush_log(topology_st, inst, RET_CODE, json=False) |
| 729 |
run_healthcheck_and_flush_log(topology_st, inst, RET_CODE, json=True) |
| 730 |
|
| 731 |
# reset setting |
| 732 |
log.info('Reset nsslapd-allow-unauthenticated-binds to off') |
| 733 |
inst.config.set("nsslapd-allow-unauthenticated-binds", "off") |
| 734 |
|
| 735 |
|
| 736 |
def test_healthcheck_accesslog_buffering(topology_st): |
| 737 |
"""Check if HealthCheck returns DSCLE0004 code when acccess log buffering |
| 738 |
is disabled |
| 739 |
|
| 740 |
:id: 5a6512fd-1c7b-4557-9278-45150423148b |
| 741 |
:setup: Standalone instance |
| 742 |
:steps: |
| 743 |
1. Create DS instance |
| 744 |
2. Set nsslapd-accesslog-logbuffering to off |
| 745 |
3. Use HealthCheck without --json option |
| 746 |
4. Use HealthCheck with --json option |
| 747 |
:expectedresults: |
| 748 |
1. Success |
| 749 |
2. Success |
| 750 |
3. Healthcheck reports DSCLE0004 |
| 751 |
4. Healthcheck reports DSCLE0004 |
| 752 |
""" |
| 753 |
|
| 754 |
RET_CODE = 'DSCLE0004' |
| 755 |
|
| 756 |
inst = topology_st.standalone |
| 757 |
|
| 758 |
log.info('nsslapd-accesslog-logbuffering to off') |
| 759 |
inst.config.set("nsslapd-accesslog-logbuffering", "off") |
| 760 |
|
| 761 |
stop_and_flush(inst) |
| 762 |
try: |
| 763 |
run_healthcheck_and_flush_log(topology_st, inst, RET_CODE, json=False) |
| 764 |
run_healthcheck_and_flush_log(topology_st, inst, RET_CODE, json=True) |
| 765 |
finally: |
| 766 |
if not inst.status(): |
| 767 |
inst.start() |
| 768 |
run_healthcheck_and_flush_log(topology_st, inst, RET_CODE, json=False) |
| 769 |
run_healthcheck_and_flush_log(topology_st, inst, RET_CODE, json=True) |
| 770 |
|
| 771 |
# reset setting |
| 772 |
log.info('Reset nsslapd-accesslog-logbuffering to on') |
| 773 |
inst.config.set("nsslapd-accesslog-logbuffering", "on") |
| 774 |
|
| 775 |
|
| 776 |
def test_healthcheck_securitylog_buffering(topology_st): |
| 777 |
"""Check if HealthCheck returns DSCLE0005 code when security log buffering |
| 778 |
is disabled |
| 779 |
|
| 780 |
:id: 9b84287a-e022-4bdc-8c65-2276b37371b5 |
| 781 |
:setup: Standalone instance |
| 782 |
:steps: |
| 783 |
1. Create DS instance |
| 784 |
2. Set nsslapd-securitylog-logbuffering to off |
| 785 |
3. Use HealthCheck without --json option |
| 786 |
4. Use HealthCheck with --json option |
| 787 |
:expectedresults: |
| 788 |
1. Success |
| 789 |
2. Success |
| 790 |
3. Healthcheck reports DSCLE0005 |
| 791 |
4. Healthcheck reports DSCLE0005 |
| 792 |
""" |
| 793 |
|
| 794 |
RET_CODE = 'DSCLE0005' |
| 795 |
|
| 796 |
inst = topology_st.standalone |
| 797 |
inst.config.set("nsslapd-accesslog-logbuffering", "on") |
| 798 |
|
| 799 |
log.info('nsslapd-securitylog-logbuffering to off') |
| 800 |
inst.config.set('nsslapd-securitylog-logging-enabled', 'on') |
| 801 |
inst.config.set("nsslapd-securitylog-logbuffering", "off") |
| 802 |
|
| 803 |
stop_and_flush(inst) |
| 804 |
try: |
| 805 |
run_healthcheck_and_flush_log(topology_st, inst, RET_CODE, json=False) |
| 806 |
run_healthcheck_and_flush_log(topology_st, inst, RET_CODE, json=True) |
| 807 |
finally: |
| 808 |
if not inst.status(): |
| 809 |
inst.start() |
| 810 |
run_healthcheck_and_flush_log(topology_st, inst, RET_CODE, json=False) |
| 811 |
run_healthcheck_and_flush_log(topology_st, inst, RET_CODE, json=True) |
| 812 |
|
| 813 |
# reset setting |
| 814 |
log.info('Reset nnsslapd-securitylog-logbuffering to on') |
| 815 |
inst.config.set("nsslapd-securitylog-logbuffering", "on") |
| 816 |
|
| 817 |
|
| 818 |
def test_healthcheck_auditlog_buffering(topology_st): |
| 819 |
"""Check if HealthCheck returns DSCLE0006 code when audit log buffering |
| 820 |
is disabled |
| 821 |
|
| 822 |
:id: f030c9f3-0ce7-4156-ba70-81ef3ac82867 |
| 823 |
:setup: Standalone instance |
| 824 |
:steps: |
| 825 |
1. Create DS instance |
| 826 |
2. Set nsslapd-auditlog-logbuffering to off |
| 827 |
3. Use HealthCheck without --json option |
| 828 |
4. Use HealthCheck with --json option |
| 829 |
:expectedresults: |
| 830 |
1. Success |
| 831 |
2. Success |
| 832 |
3. Healthcheck reports DSCLE0006 |
| 833 |
4. Healthcheck reports DSCLE0006 |
| 834 |
""" |
| 835 |
|
| 836 |
RET_CODE = 'DSCLE0006' |
| 837 |
|
| 838 |
inst = topology_st.standalone |
| 839 |
inst.config.set("nsslapd-accesslog-logbuffering", "on") |
| 840 |
enabled = inst.config.get_attr_val_utf8('nsslapd-auditlog-logging-enabled') |
| 841 |
|
| 842 |
log.info('nsslapd-auditlog-logbuffering to off') |
| 843 |
inst.config.set('nsslapd-auditlog-logging-enabled', 'on') |
| 844 |
inst.config.set('nsslapd-auditlog-logbuffering', 'off') |
| 845 |
|
| 846 |
stop_and_flush(inst) |
| 847 |
try: |
| 848 |
run_healthcheck_and_flush_log(topology_st, inst, RET_CODE, json=False) |
| 849 |
run_healthcheck_and_flush_log(topology_st, inst, RET_CODE, json=True) |
| 850 |
finally: |
| 851 |
if not inst.status(): |
| 852 |
inst.start() |
| 853 |
run_healthcheck_and_flush_log(topology_st, inst, RET_CODE, json=False) |
| 854 |
run_healthcheck_and_flush_log(topology_st, inst, RET_CODE, json=True) |
| 855 |
|
| 856 |
# reset setting |
| 857 |
log.info('Reset nnsslapd-auditlog-logbuffering to on') |
| 858 |
inst.config.set('nsslapd-auditlog-logbuffering', 'on') |
| 859 |
inst.config.set('nsslapd-auditlog-logging-enabled', enabled) |
| 860 |
|
| 861 |
|
| 862 |
if __name__ == '__main__': |
| 863 |
# Run isolated |
| 864 |
# -s for DEBUG mode |
| 865 |
CURRENT_FILE = os.path.realpath(__file__) |