| 1 |
# --- BEGIN COPYRIGHT BLOCK --- |
| 2 |
# Copyright (C) 2020 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 |
from decimal import * |
| 10 |
import os |
| 11 |
import time |
| 12 |
import logging |
| 13 |
import pytest |
| 14 |
import shutil |
| 15 |
from lib389.rootdse import RootDSE |
| 16 |
import subprocess |
| 17 |
from lib389.backend import Backend |
| 18 |
from lib389.mappingTree import MappingTrees |
| 19 |
from lib389.idm.domain import Domain |
| 20 |
from lib389.configurations.sample import create_base_domain |
| 21 |
from lib389._mapped_object import DSLdapObject |
| 22 |
from test389.topologies import topology_st |
| 23 |
from lib389.plugins import AutoMembershipPlugin, ReferentialIntegrityPlugin, AutoMembershipDefinitions, MemberOfPlugin |
| 24 |
from lib389.idm.user import UserAccounts, UserAccount |
| 25 |
from lib389.idm.group import Groups |
| 26 |
from lib389.idm.organizationalunit import OrganizationalUnits |
| 27 |
from lib389._constants import DEFAULT_SUFFIX, DN_DM, LOG_ACCESS_LEVEL, PASSWORD, ErrorLog |
| 28 |
from lib389.dirsrv_log import DirsrvAccessJSONLog |
| 29 |
from lib389.utils import ds_is_older, ds_is_newer |
| 30 |
from lib389.config import RSA |
| 31 |
from lib389.dseldif import DSEldif |
| 32 |
import ldap |
| 33 |
import glob |
| 34 |
import re |
| 35 |
|
| 36 |
pytestmark = pytest.mark.tier1 |
| 37 |
|
| 38 |
logging.getLogger(__name__).setLevel(logging.DEBUG) |
| 39 |
log = logging.getLogger(__name__) |
| 40 |
|
| 41 |
PLUGIN_LOGGING = 'nsslapd-plugin-logging' |
| 42 |
USER1_DN = 'uid=user1,' + DEFAULT_SUFFIX |
| 43 |
THREAD_POOL_OP_TAGS = { |
| 44 |
ldap.RES_BIND: "BIND", |
| 45 |
ldap.RES_SEARCH_RESULT: "SEARCH", |
| 46 |
ldap.RES_MODIFY: "MOD", |
| 47 |
ldap.RES_ADD: "ADD", |
| 48 |
ldap.RES_DELETE: "DEL", |
| 49 |
ldap.RES_EXTENDED: "EXTOP", |
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
def add_users(topology_st, users_num): |
| 54 |
users = UserAccounts(topology_st, DEFAULT_SUFFIX) |
| 55 |
log.info('Adding %d users' % users_num) |
| 56 |
for i in range(0, users_num): |
| 57 |
uid = 1000 + i |
| 58 |
users.create(properties={ |
| 59 |
'uid': 'testuser%d' % uid, |
| 60 |
'cn': 'testuser%d' % uid, |
| 61 |
'sn': 'user', |
| 62 |
'uidNumber': '%d' % uid, |
| 63 |
'gidNumber': '%d' % uid, |
| 64 |
'homeDirectory': '/home/testuser%d' % uid |
| 65 |
}) |
| 66 |
|
| 67 |
|
| 68 |
def search_users(topology_st): |
| 69 |
users = UserAccounts(topology_st, DEFAULT_SUFFIX) |
| 70 |
entries = users.list() |
| 71 |
# We just assert we got some data ... |
| 72 |
assert len(entries) > 0 |
| 73 |
|
| 74 |
|
| 75 |
def delete_obj(obj): |
| 76 |
if obj.exists(): |
| 77 |
obj.delete() |
| 78 |
|
| 79 |
|
| 80 |
def add_group_and_perform_user_operations(topology_st): |
| 81 |
topo = topology_st.standalone |
| 82 |
|
| 83 |
# Add the automember group |
| 84 |
groups = Groups(topo, DEFAULT_SUFFIX) |
| 85 |
group = groups.create(properties={'cn': 'group'}) |
| 86 |
|
| 87 |
ous = OrganizationalUnits(topo, DEFAULT_SUFFIX) |
| 88 |
branch1 = ous.create(properties={'ou': 'branch1'}) |
| 89 |
|
| 90 |
# Add the automember config entry |
| 91 |
am_configs = AutoMembershipDefinitions(topo) |
| 92 |
am_config = am_configs.create(properties={'cn': 'config', |
| 93 |
'autoMemberScope': branch1.dn, |
| 94 |
'autoMemberFilter': 'objectclass=top', |
| 95 |
'autoMemberDefaultGroup': group.dn, |
| 96 |
'autoMemberGroupingAttr': 'member:dn'}) |
| 97 |
|
| 98 |
# Add a user that should get added to the group |
| 99 |
users = UserAccounts(topo, DEFAULT_SUFFIX, rdn='ou={}'.format(branch1.rdn)) |
| 100 |
test_user = users.create_test_user(uid=777) |
| 101 |
|
| 102 |
# Check if created user is group member |
| 103 |
assert test_user.dn in group.list_members() |
| 104 |
|
| 105 |
log.info('Renaming user') |
| 106 |
test_user.rename('uid=new_test_user_777', newsuperior=DEFAULT_SUFFIX) |
| 107 |
|
| 108 |
log.info('Delete the user') |
| 109 |
delete_obj(test_user) |
| 110 |
|
| 111 |
log.info('Delete automember entry, org. unit and group for the next test') |
| 112 |
delete_obj(am_config) |
| 113 |
delete_obj(branch1) |
| 114 |
delete_obj(group) |
| 115 |
|
| 116 |
|
| 117 |
@pytest.fixture(scope="module") |
| 118 |
def enable_plugins(topology_st): |
| 119 |
topo = topology_st.standalone |
| 120 |
|
| 121 |
log.info("Enable automember plugin") |
| 122 |
plugin = AutoMembershipPlugin(topo) |
| 123 |
plugin.enable() |
| 124 |
|
| 125 |
log.info('Enable Referential Integrity plugin') |
| 126 |
plugin = ReferentialIntegrityPlugin(topo) |
| 127 |
plugin.enable() |
| 128 |
|
| 129 |
log.info('Set nsslapd-plugin-logging to on') |
| 130 |
topo.config.set(PLUGIN_LOGGING, 'ON') |
| 131 |
|
| 132 |
log.info('Restart the server') |
| 133 |
topo.restart() |
| 134 |
|
| 135 |
|
| 136 |
def add_user_log_level(topology_st, loglevel, request): |
| 137 |
topo = topology_st.standalone |
| 138 |
default_log_level = topo.config.get_attr_val_utf8(LOG_ACCESS_LEVEL) |
| 139 |
log.info(f'Configure access log level to {loglevel}') |
| 140 |
topo.config.set(LOG_ACCESS_LEVEL, str(loglevel)) |
| 141 |
add_group_and_perform_user_operations(topology_st) |
| 142 |
|
| 143 |
def fin(): |
| 144 |
topo.config.set(LOG_ACCESS_LEVEL, default_log_level) |
| 145 |
log.info('Delete the previous access logs for the next test') |
| 146 |
topo.deleteAccessLogs() |
| 147 |
request.addfinalizer(fin) |
| 148 |
|
| 149 |
|
| 150 |
@pytest.fixture(scope="function") |
| 151 |
def add_user_log_level_260(topology_st, enable_plugins, request): |
| 152 |
access_log_level = 4 + 256 |
| 153 |
add_user_log_level(topology_st, access_log_level, request) |
| 154 |
|
| 155 |
|
| 156 |
@pytest.fixture(scope="function") |
| 157 |
def add_user_log_level_516(topology_st, enable_plugins, request): |
| 158 |
access_log_level = 4 + 512 |
| 159 |
add_user_log_level(topology_st, access_log_level, request) |
| 160 |
|
| 161 |
|
| 162 |
@pytest.fixture(scope="function") |
| 163 |
def add_user_log_level_131076(topology_st, enable_plugins, request): |
| 164 |
access_log_level = 4 + 131072 |
| 165 |
add_user_log_level(topology_st, access_log_level, request) |
| 166 |
|
| 167 |
|
| 168 |
@pytest.fixture(scope="function") |
| 169 |
def clean_access_logs(topology_st, request): |
| 170 |
def _clean_access_logs(): |
| 171 |
topo = topology_st.standalone |
| 172 |
log.info("Stopping the instance") |
| 173 |
topo.stop() |
| 174 |
log.info("Deleting the access logs") |
| 175 |
topo.deleteAccessLogs() |
| 176 |
log.info("Starting the instance") |
| 177 |
topo.start() |
| 178 |
|
| 179 |
request.addfinalizer(_clean_access_logs) |
| 180 |
|
| 181 |
return clean_access_logs |
| 182 |
|
| 183 |
@pytest.fixture(scope="function") |
| 184 |
def remove_users(topology_st, request): |
| 185 |
def _remove_users(): |
| 186 |
topo = topology_st.standalone |
| 187 |
users = UserAccounts(topo, DEFAULT_SUFFIX) |
| 188 |
entries = users.list() |
| 189 |
assert len(entries) > 0 |
| 190 |
|
| 191 |
log.info("Removing all added users") |
| 192 |
for entry in entries: |
| 193 |
delete_obj(entry) |
| 194 |
|
| 195 |
request.addfinalizer(_remove_users) |
| 196 |
|
| 197 |
|
| 198 |
def set_audit_log_config_values(topology_st, request, enabled, logsize): |
| 199 |
topo = topology_st.standalone |
| 200 |
|
| 201 |
topo.config.set('nsslapd-auditlog-logging-enabled', enabled) |
| 202 |
topo.config.set('nsslapd-auditlog-maxlogsize', logsize) |
| 203 |
|
| 204 |
def fin(): |
| 205 |
topo.start() |
| 206 |
log.info('Setting audit log config back to default values') |
| 207 |
topo.config.set('nsslapd-auditlog-logging-enabled', 'off') |
| 208 |
topo.config.set('nsslapd-auditlog-maxlogsize', '100') |
| 209 |
|
| 210 |
request.addfinalizer(fin) |
| 211 |
|
| 212 |
|
| 213 |
@pytest.fixture(scope="function") |
| 214 |
def set_audit_log_config_values_to_rotate(topology_st, request): |
| 215 |
set_audit_log_config_values(topology_st, request, 'on', '1') |
| 216 |
|
| 217 |
|
| 218 |
@pytest.fixture(scope="function") |
| 219 |
def disable_access_log_buffering(topology_st, request): |
| 220 |
log.info('Disable access log buffering') |
| 221 |
topology_st.standalone.config.set('nsslapd-accesslog-logbuffering', 'off') |
| 222 |
def fin(): |
| 223 |
log.info('Enable access log buffering') |
| 224 |
topology_st.standalone.config.set('nsslapd-accesslog-logbuffering', 'on') |
| 225 |
|
| 226 |
request.addfinalizer(fin) |
| 227 |
|
| 228 |
return disable_access_log_buffering |
| 229 |
|
| 230 |
|
| 231 |
def create_backend(inst, rdn, suffix): |
| 232 |
# We only support dc= in this test. |
| 233 |
assert suffix.startswith('dc=') |
| 234 |
be1 = Backend(inst) |
| 235 |
be1.create(properties={ |
| 236 |
'cn': rdn, |
| 237 |
'nsslapd-suffix': suffix, |
| 238 |
}, |
| 239 |
create_mapping_tree=False |
| 240 |
) |
| 241 |
|
| 242 |
# Now we temporarily make the MT for this node so we can add the base entry. |
| 243 |
mts = MappingTrees(inst) |
| 244 |
mt = mts.create(properties={ |
| 245 |
'cn': suffix, |
| 246 |
'nsslapd-state': 'backend', |
| 247 |
'nsslapd-backend': rdn, |
| 248 |
}) |
| 249 |
|
| 250 |
# Create the domain entry |
| 251 |
create_base_domain(inst, suffix) |
| 252 |
# Now delete the mt |
| 253 |
mt.delete() |
| 254 |
|
| 255 |
return be1 |
| 256 |
|
| 257 |
|
| 258 |
def test_log_plugin_on(topology_st, remove_users): |
| 259 |
"""Check access logs for millisecond |
| 260 |
|
| 261 |
:id: 65ae4e2a-295f-4222-8d69-12124bc7a872 |
| 262 |
|
| 263 |
:setup: Standalone instance |
| 264 |
|
| 265 |
:steps: |
| 266 |
1. To generate big logs, add 100 test users |
| 267 |
2. Search users to generate more access logs |
| 268 |
3. Restart server |
| 269 |
4. Parse the logs to check the milliseconds got recorded in logs |
| 270 |
|
| 271 |
:expectedresults: |
| 272 |
1. Add operation should be successful |
| 273 |
2. Search operation should be successful |
| 274 |
3. Server should be restarted successfully |
| 275 |
4. There should be milliseconds added in the access logs |
| 276 |
""" |
| 277 |
|
| 278 |
log.info('Bug 1273549 - Check access logs for millisecond, when attribute is ON') |
| 279 |
log.info('perform any ldap operation, which will trigger the logs') |
| 280 |
add_users(topology_st.standalone, 10) |
| 281 |
search_users(topology_st.standalone) |
| 282 |
|
| 283 |
log.info('Restart the server to flush the logs') |
| 284 |
topology_st.standalone.restart(timeout=10) |
| 285 |
|
| 286 |
log.info('parse the access logs') |
| 287 |
access_log_lines = topology_st.standalone.ds_access_log.readlines() |
| 288 |
assert len(access_log_lines) > 0 |
| 289 |
assert topology_st.standalone.ds_access_log.match(r'^\[.+\d{9}.+\].+') |
| 290 |
|
| 291 |
|
| 292 |
@pytest.mark.xfail(ds_is_older('1.4.0'), reason="May fail on 1.3.x because of bug 1358706") |
| 293 |
def test_internal_log_server_level_0(topology_st, clean_access_logs, disable_access_log_buffering): |
| 294 |
"""Tests server-initiated internal operations |
| 295 |
|
| 296 |
:id: 798d06fe-92e8-4648-af66-21349c20638e |
| 297 |
:setup: Standalone instance |
| 298 |
:steps: |
| 299 |
1. Set nsslapd-plugin-logging to on |
| 300 |
2. Configure access log level to only 0 |
| 301 |
3. Check the access logs. |
| 302 |
:expectedresults: |
| 303 |
1. Operation should be successful |
| 304 |
2. Operation should be successful |
| 305 |
3. Access log should not contain internal operations log formats |
| 306 |
""" |
| 307 |
|
| 308 |
topo = topology_st.standalone |
| 309 |
default_log_level = topo.config.get_attr_val_utf8(LOG_ACCESS_LEVEL) |
| 310 |
|
| 311 |
log.info('Set nsslapd-plugin-logging to on') |
| 312 |
topo.config.set(PLUGIN_LOGGING, 'ON') |
| 313 |
|
| 314 |
log.info('Configure access log level to 0') |
| 315 |
access_log_level = '0' |
| 316 |
topo.config.set(LOG_ACCESS_LEVEL, access_log_level) |
| 317 |
|
| 318 |
log.info('Restart the server to flush the logs') |
| 319 |
topo.restart() |
| 320 |
|
| 321 |
# These comments contain lines we are trying to find without regex (the op numbers are just examples) |
| 322 |
log.info("Check if access log does not contain internal log of MOD operation") |
| 323 |
# (Internal) op=2(2)(1) SRCH base="cn=config |
| 324 |
assert not topo.ds_access_log.match(r'.*\(Internal\) op=[0-9]+\([0-9]+\)\([0-9]+\) SRCH base="cn=config.*') |
| 325 |
# (Internal) op=2(2)(1) RESULT err=0 tag=48 nentries=1 |
| 326 |
assert not topo.ds_access_log.match(r'.*\(Internal\) op=[0-9]+\([0-9]+\)\([0-9]+\) RESULT err=0 tag=48 nentries=1.*') |
| 327 |
|
| 328 |
log.info("Check if the other internal operations are not present") |
| 329 |
# conn=Internal(0) op=0 |
| 330 |
assert not topo.ds_access_log.match(r'.*conn=Internal\([0-9]+\) op=[0-9]+\([0-9]+\)\([0-9]+\).*') |
| 331 |
|
| 332 |
topo.config.set(LOG_ACCESS_LEVEL, default_log_level) |
| 333 |
|
| 334 |
|
| 335 |
@pytest.mark.xfail(ds_is_older('1.4.0'), reason="May fail on 1.3.x because of bug 1358706") |
| 336 |
def test_internal_log_server_level_4(topology_st, clean_access_logs, disable_access_log_buffering): |
| 337 |
"""Tests server-initiated internal operations |
| 338 |
|
| 339 |
:id: a3500e47-d941-4575-b399-e3f4b49bc4b6 |
| 340 |
:setup: Standalone instance |
| 341 |
:steps: |
| 342 |
1. Set nsslapd-plugin-logging to on |
| 343 |
2. Configure access log level to only 4 |
| 344 |
3. Check the access logs, it should contain info about MOD operation of cn=config and other |
| 345 |
internal operations should have the conn field set to Internal |
| 346 |
and all values inside parenthesis set to 0. |
| 347 |
:expectedresults: |
| 348 |
1. Operation should be successful |
| 349 |
2. Operation should be successful |
| 350 |
3. Access log should contain correct internal log formats with cn=config modification: |
| 351 |
"(Internal) op=2(1)(1)" |
| 352 |
"conn=Internal(0)" |
| 353 |
""" |
| 354 |
|
| 355 |
topo = topology_st.standalone |
| 356 |
default_log_level = topo.config.get_attr_val_utf8(LOG_ACCESS_LEVEL) |
| 357 |
|
| 358 |
log.info('Set nsslapd-plugin-logging to on') |
| 359 |
topo.config.set(PLUGIN_LOGGING, 'ON') |
| 360 |
|
| 361 |
log.info('Configure access log level to 4') |
| 362 |
access_log_level = '4' |
| 363 |
topo.config.set(LOG_ACCESS_LEVEL, access_log_level) |
| 364 |
|
| 365 |
log.info('Restart the server to flush the logs') |
| 366 |
topo.restart() |
| 367 |
|
| 368 |
# After 947ee67 log dynamic has changed slightly |
| 369 |
# Do another MOD to trigger the internal search |
| 370 |
topo.config.set(LOG_ACCESS_LEVEL, access_log_level) |
| 371 |
|
| 372 |
try: |
| 373 |
# These comments contain lines we are trying to find without regex (the op numbers are just examples) |
| 374 |
log.info("Check if access log contains internal MOD operation in correct format") |
| 375 |
# (Internal) op=2(2)(1) SRCH base="cn=config |
| 376 |
assert topo.ds_access_log.match(r'.*\(Internal\) op=[0-9]+\([0-9]+\)\([0-9]+\) SRCH base="cn=config.*') |
| 377 |
# (Internal) op=2(2)(1) RESULT err=0 tag=48 nentries= |
| 378 |
assert topo.ds_access_log.match(r'.*\(Internal\) op=[0-9]+\([0-9]+\)\([0-9]+\) RESULT err=0 tag=48 nentries=.*') |
| 379 |
|
| 380 |
log.info("Check if the other internal operations have the correct format") |
| 381 |
# conn=Internal(0) op=0 |
| 382 |
assert topo.ds_access_log.match(r'.*conn=Internal\([0-9]+\) op=[0-9]+\([0-9]+\)\([0-9]+\).*') |
| 383 |
finally: |
| 384 |
topo.config.set(LOG_ACCESS_LEVEL, default_log_level) |
| 385 |
|
| 386 |
|
| 387 |
@pytest.mark.xfail(ds_is_older('1.4.0'), reason="May fail on 1.3.x because of bug 1358706") |
| 388 |
def test_internal_log_level_260(topology_st, add_user_log_level_260, disable_access_log_buffering): |
| 389 |
"""Tests client initiated operations when automember plugin is enabled |
| 390 |
|
| 391 |
:id: e68a303e-c037-42b2-a5a0-fbea27c338a9 |
| 392 |
:setup: Standalone instance with internal operation |
| 393 |
logging on and nsslapd-plugin-logging to on |
| 394 |
:steps: |
| 395 |
1. Configure access log level to 260 (4 + 256) |
| 396 |
2. Set nsslapd-plugin-logging to on |
| 397 |
3. Enable Referential Integrity and automember plugins |
| 398 |
4. Restart the server |
| 399 |
5. Add a test group |
| 400 |
6. Add a test user and add it as member of the test group |
| 401 |
7. Rename the test user |
| 402 |
8. Delete the test user |
| 403 |
9. Check the access logs for nested internal operation logs |
| 404 |
:expectedresults: |
| 405 |
1. Operation should be successful |
| 406 |
2. Operation should be successful |
| 407 |
3. Operation should be successful |
| 408 |
4. Operation should be successful |
| 409 |
5. Operation should be successful |
| 410 |
6. Operation should be successful |
| 411 |
7. Operation should be successful |
| 412 |
8. Operation should be successful |
| 413 |
9. Access log should contain internal info about operations of the user |
| 414 |
""" |
| 415 |
|
| 416 |
topo = topology_st.standalone |
| 417 |
|
| 418 |
log.info('Restart the server to flush the logs') |
| 419 |
topo.restart() |
| 420 |
|
| 421 |
# These comments contain lines we are trying to find without regex (the op numbers are just examples) |
| 422 |
log.info("Check the access logs for ADD operation of the user") |
| 423 |
# op=10 ADD dn="uid=test_user_777,ou=topology_st, branch1,dc=example,dc=com" |
| 424 |
assert topo.ds_access_log.match(r'.*op=[0-9]+ ADD dn="uid=test_user_777,ou=branch1,dc=example,dc=com".*') |
| 425 |
# (Internal) op=10(1)(1) MOD dn="cn=group,ou=Groups,dc=example,dc=com" |
| 426 |
assert topo.ds_access_log.match(r'.*\(Internal\) op=[0-9]+\([0-9]+\)\([0-9]+\) ' |
| 427 |
r'MOD dn="cn=group,ou=Groups,dc=example,dc=com".*') |
| 428 |
# (Internal) op=10(1)(2) SRCH base="cn=group,ou=Groups,dc=example,dc=com" |
| 429 |
assert topo.ds_access_log.match(r'.*\(Internal\) op=[0-9]+\([0-9]+\)\([0-9]+\) SRCH base="cn=group,' |
| 430 |
r'ou=Groups,dc=example,dc=com".*') |
| 431 |
# (Internal) op=10(1)(2) RESULT err=0 tag=48 nentries=1 |
| 432 |
assert topo.ds_access_log.match(r'.*\(Internal\) op=[0-9]+\([0-9]+\)\([0-9]+\) RESULT err=0 tag=48 nentries=1*') |
| 433 |
# (Internal) op=10(1)(1) RESULT err=0 tag=48 |
| 434 |
assert topo.ds_access_log.match(r'.*\(Internal\) op=[0-9]+\([0-9]+\)\([0-9]+\) RESULT err=0 tag=48.*') |
| 435 |
# op=10 RESULT err=0 tag=105 |
| 436 |
assert topo.ds_access_log.match(r'.*op=[0-9]+ RESULT err=0 tag=105.*') |
| 437 |
|
| 438 |
log.info("Check the access logs for MOD operation of the user") |
| 439 |
# op=12 MODRDN dn="uid=test_user_777,ou=branch1,dc=example,dc=com" ' |
| 440 |
# 'newrdn="uid=new_test_user_777" newsuperior="dc=example,dc=com" |
| 441 |
assert topo.ds_access_log.match(r'.*op=[0-9]+ MODRDN dn="uid=test_user_777,ou=branch1,dc=example,dc=com" ' |
| 442 |
'newrdn="uid=new_test_user_777" newsuperior="dc=example,dc=com".*') |
| 443 |
if ds_is_older(('1.4.3.9', '1.4.4.3')): |
| 444 |
# (Internal) op=12(1)(1) SRCH base="uid=test_user_777, ou=branch1,dc=example,dc=com" |
| 445 |
assert topo.ds_access_log.match(r'.*\(Internal\) op=[0-9]+\([0-9]+\)\([0-9]+\) SRCH base="uid=test_user_777,' |
| 446 |
'ou=branch1,dc=example,dc=com".*') |
| 447 |
# (Internal) op=12(1)(1) RESULT err=0 tag=48 nentries=1 |
| 448 |
assert topo.ds_access_log.match(r'.*\(Internal\) op=[0-9]+\([0-9]+\)\([0-9]+\) RESULT err=0 tag=48 nentries=1.*') |
| 449 |
# op=12 RESULT err=0 tag=109 |
| 450 |
assert topo.ds_access_log.match(r'.*op=[0-9]+ RESULT err=0 tag=109.*') |
| 451 |
|
| 452 |
log.info("Check the access logs for DEL operation of the user") |
| 453 |
# op=15 DEL dn="uid=new_test_user_777,dc=example,dc=com" |
| 454 |
assert topo.ds_access_log.match(r'.*op=[0-9]+ DEL dn="uid=new_test_user_777,dc=example,dc=com".*') |
| 455 |
if ds_is_older(('1.4.3.9', '1.4.4.3')): |
| 456 |
# (Internal) op=15(1)(1) SRCH base="uid=new_test_user_777, dc=example,dc=com" |
| 457 |
assert topo.ds_access_log.match(r'.*\(Internal\) op=[0-9]+\([0-9]+\)\([0-9]+\) SRCH base="uid=new_test_user_777,' |
| 458 |
'dc=example,dc=com".*') |
| 459 |
# (Internal) op=15(1)(1) RESULT err=0 tag=48 nentries=1 |
| 460 |
assert topo.ds_access_log.match(r'.*\(Internal\) op=[0-9]+\([0-9]+\)\([0-9]+\) RESULT err=0 tag=48 nentries=1.*') |
| 461 |
# op=15 RESULT err=0 tag=107 |
| 462 |
assert topo.ds_access_log.match(r'.*op=[0-9]+ RESULT err=0 tag=107.*') |
| 463 |
|
| 464 |
log.info("Check if the other internal operations have the correct format") |
| 465 |
# conn=Internal(0) op=0 |
| 466 |
assert topo.ds_access_log.match(r'.*conn=Internal\([0-9]+\) op=[0-9]+\([0-9]+\)\([0-9]+\).*') |
| 467 |
|
| 468 |
|
| 469 |
@pytest.mark.xfail(ds_is_older('1.4.0'), reason="May fail on 1.3.x because of bug 1358706") |
| 470 |
def test_internal_log_level_131076(topology_st, add_user_log_level_131076, disable_access_log_buffering): |
| 471 |
"""Tests client-initiated operations while referential integrity plugin is enabled |
| 472 |
|
| 473 |
:id: 44836ac9-dabd-4a8c-abd5-ecd7c2509739 |
| 474 |
:setup: Standalone instance |
| 475 |
Configure access log level to - 131072 + 4 |
| 476 |
Set nsslapd-plugin-logging to on |
| 477 |
:steps: |
| 478 |
1. Configure access log level to 131076 |
| 479 |
2. Set nsslapd-plugin-logging to on |
| 480 |
3. Enable Referential Integrity and automember plugins |
| 481 |
4. Restart the server |
| 482 |
5. Add a test group |
| 483 |
6. Add a test user and add it as member of the test group |
| 484 |
7. Rename the test user |
| 485 |
8. Delete the test user |
| 486 |
9. Check the access logs for nested internal operation logs |
| 487 |
:expectedresults: |
| 488 |
1. Operation should be successful |
| 489 |
2. Operation should be successful |
| 490 |
3. Operation should be successful |
| 491 |
4. Operation should be successful |
| 492 |
5. Operation should be successful |
| 493 |
6. Operation should be successful |
| 494 |
7. Operation should be successful |
| 495 |
8. Operation should be successful |
| 496 |
9. Access log should contain internal info about operations of the user |
| 497 |
""" |
| 498 |
|
| 499 |
topo = topology_st.standalone |
| 500 |
|
| 501 |
log.info('Restart the server to flush the logs') |
| 502 |
topo.restart() |
| 503 |
|
| 504 |
# These comments contain lines we are trying to find without regex (the op numbers are just examples) |
| 505 |
log.info("Check the access logs for ADD operation of the user") |
| 506 |
# op=10 ADD dn="uid=test_user_777,ou=branch1,dc=example,dc=com" |
| 507 |
assert not topo.ds_access_log.match(r'.*op=[0-9]+ ADD dn="uid=test_user_777,ou=branch1,dc=example,dc=com".*') |
| 508 |
# (Internal) op=10(1)(1) MOD dn="cn=group,ou=Groups,dc=example,dc=com" |
| 509 |
assert topo.ds_access_log.match(r'.*\(Internal\) op=[0-9]+\([0-9]+\)\([0-9]+\) ' |
| 510 |
r'MOD dn="cn=group,ou=Groups,dc=example,dc=com".*') |
| 511 |
# (Internal) op=10(1)(2) SRCH base="cn=group,ou=Groups,dc=example,dc=com" |
| 512 |
assert topo.ds_access_log.match(r'.*\(Internal\) op=[0-9]+\([0-9]+\)\([0-9]+\) ' |
| 513 |
r'SRCH base="cn=group,ou=Groups,dc=example,dc=com".*') |
| 514 |
# (Internal) op=10(1)(2) RESULT err=0 tag=48 nentries=1*') |
| 515 |
assert topo.ds_access_log.match(r'.*\(Internal\) op=[0-9]+\([0-9]+\)\([0-9]+\) RESULT err=0 tag=48 nentries=1*') |
| 516 |
# (Internal) op=10(1)(1) RESULT err=0 tag=48 |
| 517 |
assert topo.ds_access_log.match(r'.*\(Internal\) op=[0-9]+\([0-9]+\)\([0-9]+\) RESULT err=0 tag=48.*') |
| 518 |
# op=10 RESULT err=0 tag=105 |
| 519 |
assert not topo.ds_access_log.match(r'.*op=[0-9]+ RESULT err=0 tag=105.*') |
| 520 |
|
| 521 |
log.info("Check the access logs for MOD operation of the user") |
| 522 |
# op=12 MODRDN dn="uid=test_user_777,ou=branch1,dc=example,dc=com" ' |
| 523 |
# 'newrdn="uid=new_test_user_777" newsuperior="dc=example,dc=com" |
| 524 |
assert not topo.ds_access_log.match(r'.*op=[0-9]+ MODRDN dn="uid=test_user_777,ou=branch1,dc=example,dc=com" ' |
| 525 |
'newrdn="uid=new_test_user_777" newsuperior="dc=example,dc=com".*') |
| 526 |
if ds_is_older(('1.4.3.9', '1.4.4.3')): |
| 527 |
# (Internal) op=12(1)(1) SRCH base="uid=test_user_777, ou=branch1,dc=example,dc=com" |
| 528 |
assert topo.ds_access_log.match(r'.*\(Internal\) op=[0-9]+\([0-9]+\)\([0-9]+\) SRCH base="uid=test_user_777,' |
| 529 |
'ou=branch1,dc=example,dc=com".*') |
| 530 |
# (Internal) op=12(1)(1) RESULT err=0 tag=48 nentries=1 |
| 531 |
assert topo.ds_access_log.match(r'.*\(Internal\) op=[0-9]+\([0-9]+\)\([0-9]+\) RESULT err=0 tag=48 nentries=1.*') |
| 532 |
# op=12 RESULT err=0 tag=109 |
| 533 |
assert not topo.ds_access_log.match(r'.*op=[0-9]+ RESULT err=0 tag=109.*') |
| 534 |
|
| 535 |
log.info("Check the access logs for DEL operation of the user") |
| 536 |
# op=15 DEL dn="uid=new_test_user_777,dc=example,dc=com" |
| 537 |
assert not topo.ds_access_log.match(r'.*op=[0-9]+ DEL dn="uid=new_test_user_777,dc=example,dc=com".*') |
| 538 |
if ds_is_older(('1.4.3.9', '1.4.4.3')): |
| 539 |
# (Internal) op=15(1)(1) SRCH base="uid=new_test_user_777, dc=example,dc=com" |
| 540 |
assert topo.ds_access_log.match(r'.*\(Internal\) op=[0-9]+\([0-9]+\)\([0-9]+\) SRCH base="uid=new_test_user_777,' |
| 541 |
'dc=example,dc=com".*') |
| 542 |
# (Internal) op=15(1)(1) RESULT err=0 tag=48 nentries=1 |
| 543 |
assert topo.ds_access_log.match(r'.*\(Internal\) op=[0-9]+\([0-9]+\)\([0-9]+\) RESULT err=0 tag=48 nentries=1.*') |
| 544 |
# op=15 RESULT err=0 tag=107 |
| 545 |
assert not topo.ds_access_log.match(r'.*op=[0-9]+ RESULT err=0 tag=107.*') |
| 546 |
|
| 547 |
log.info("Check if the other internal operations have the correct format") |
| 548 |
# conn=Internal(0) op=0 |
| 549 |
assert topo.ds_access_log.match(r'.*conn=Internal\([0-9]+\) op=[0-9]+\([0-9]+\)\([0-9]+\).*') |
| 550 |
|
| 551 |
|
| 552 |
@pytest.mark.xfail(ds_is_older('1.4.0'), reason="May fail on 1.3.x because of bug 1358706") |
| 553 |
def test_internal_log_level_516(topology_st, add_user_log_level_516, disable_access_log_buffering): |
| 554 |
"""Tests client initiated operations when referential integrity plugin is enabled |
| 555 |
|
| 556 |
:id: bee1d681-763d-4fa5-aca2-569cf93f8b71 |
| 557 |
:setup: Standalone instance |
| 558 |
Configure access log level to - 512+4 |
| 559 |
Set nsslapd-plugin-logging to on |
| 560 |
:steps: |
| 561 |
1. Configure access log level to 516 |
| 562 |
2. Set nsslapd-plugin-logging to on |
| 563 |
3. Enable Referential Integrity and automember plugins |
| 564 |
4. Restart the server |
| 565 |
5. Add a test group |
| 566 |
6. Add a test user and add it as member of the test group |
| 567 |
7. Rename the test user |
| 568 |
8. Delete the test user |
| 569 |
9. Check the access logs for nested internal operation logs |
| 570 |
:expectedresults: |
| 571 |
1. Operation should be successful |
| 572 |
2. Operation should be successful |
| 573 |
3. Operation should be successful |
| 574 |
4. Operation should be successful |
| 575 |
5. Operation should be successful |
| 576 |
6. Operation should be successful |
| 577 |
7. Operation should be successful |
| 578 |
8. Operation should be successful |
| 579 |
9. Access log should contain internal info about operations of the user |
| 580 |
""" |
| 581 |
|
| 582 |
topo = topology_st.standalone |
| 583 |
|
| 584 |
log.info('Restart the server to flush the logs') |
| 585 |
topo.restart() |
| 586 |
|
| 587 |
# These comments contain lines we are trying to find without regex (the op numbers are just examples) |
| 588 |
log.info("Check the access logs for ADD operation of the user") |
| 589 |
# op=10 ADD dn="uid=test_user_777,ou=branch1,dc=example,dc=com" |
| 590 |
assert not topo.ds_access_log.match(r'.*op=[0-9]+ ADD dn="uid=test_user_777,ou=branch1,dc=example,dc=com".*') |
| 591 |
# (Internal) op=10(1)(1) MOD dn="cn=group,ou=Groups,dc=example,dc=com" |
| 592 |
assert topo.ds_access_log.match(r'.*\(Internal\) op=[0-9]+\([0-9]+\)\([0-9]+\) ' |
| 593 |
r'MOD dn="cn=group,ou=Groups,dc=example,dc=com".*') |
| 594 |
# (Internal) op=10(1)(2) SRCH base="cn=group,ou=Groups,dc=example,dc=com" |
| 595 |
assert topo.ds_access_log.match(r'.*\(Internal\) op=[0-9]+\([0-9]+\)\([0-9]+\) ' |
| 596 |
r'SRCH base="cn=group,ou=Groups,dc=example,dc=com".*') |
| 597 |
# (Internal) op=10(1)(2) ENTRY dn="cn=group,ou=Groups,dc=example,dc=com" |
| 598 |
assert topo.ds_access_log.match(r'.*\(Internal\) op=[0-9]+\([0-9]+\)\([0-9]+\) ' |
| 599 |
r'ENTRY dn="cn=group,ou=Groups,dc=example,dc=com".*') |
| 600 |
# (Internal) op=10(1)(2) RESULT err=0 tag=48 nentries=1*') |
| 601 |
assert topo.ds_access_log.match(r'.*\(Internal\) op=[0-9]+\([0-9]+\)\([0-9]+\) RESULT err=0 tag=48 nentries=1*') |
| 602 |
# (Internal) op=10(1)(1) RESULT err=0 tag=48 |
| 603 |
assert topo.ds_access_log.match(r'.*\(Internal\) op=[0-9]+\([0-9]+\)\([0-9]+\) RESULT err=0 tag=48.*') |
| 604 |
|
| 605 |
log.info("Check the access logs for MOD operation of the user") |
| 606 |
# op=12 MODRDN dn="uid=test_user_777,ou=branch1,dc=example,dc=com" ' |
| 607 |
# 'newrdn="uid=new_test_user_777" newsuperior="dc=example,dc=com" |
| 608 |
assert not topo.ds_access_log.match(r'.*op=[0-9]+ MODRDN dn="uid=test_user_777,ou=branch1,dc=example,dc=com" ' |
| 609 |
'newrdn="uid=new_test_user_777" newsuperior="dc=example,dc=com".*') |
| 610 |
if ds_is_older(('1.4.3.9', '1.4.4.3')): |
| 611 |
# Internal) op=12(1)(1) SRCH base="uid=test_user_777, ou=branch1,dc=example,dc=com" |
| 612 |
assert topo.ds_access_log.match(r'.*\(Internal\) op=[0-9]+\([0-9]+\)\([0-9]+\) SRCH base="uid=test_user_777,' |
| 613 |
'ou=branch1,dc=example,dc=com".*') |
| 614 |
# (Internal) op=12(1)(1) ENTRY dn="uid=test_user_777, ou=branch1,dc=example,dc=com" |
| 615 |
assert topo.ds_access_log.match(r'.*\(Internal\) op=[0-9]+\([0-9]+\)\([0-9]+\) ENTRY dn="uid=test_user_777,' |
| 616 |
'ou=branch1,dc=example,dc=com".*') |
| 617 |
# (Internal) op=12(1)(1) RESULT err=0 tag=48 nentries=1 |
| 618 |
assert topo.ds_access_log.match(r'.*\(Internal\) op=[0-9]+\([0-9]+\)\([0-9]+\) RESULT err=0 tag=48 nentries=1.*') |
| 619 |
# op=12 RESULT err=0 tag=48 |
| 620 |
assert not topo.ds_access_log.match(r'.*op=[0-9]+ RESULT err=0 tag=48.*') |
| 621 |
|
| 622 |
log.info("Check the access logs for DEL operation of the user") |
| 623 |
# op=15 DEL dn="uid=new_test_user_777,dc=example,dc=com" |
| 624 |
assert not topo.ds_access_log.match(r'.*op=[0-9]+ DEL dn="uid=new_test_user_777,dc=example,dc=com".*') |
| 625 |
if ds_is_older(('1.4.3.9', '1.4.4.3')): |
| 626 |
# (Internal) op=15(1)(1) SRCH base="uid=new_test_user_777, dc=example,dc=com" |
| 627 |
assert topo.ds_access_log.match(r'.*\(Internal\) op=[0-9]+\([0-9]+\)\([0-9]+\) SRCH base="uid=new_test_user_777,' |
| 628 |
'dc=example,dc=com".*') |
| 629 |
# (Internal) op=15(1)(1) ENTRY dn="uid=new_test_user_777, dc=example,dc=com" |
| 630 |
assert topo.ds_access_log.match(r'.*\(Internal\) op=[0-9]+\([0-9]+\)\([0-9]+\) ENTRY dn="uid=new_test_user_777,' |
| 631 |
'dc=example,dc=com".*') |
| 632 |
# (Internal) op=15(1)(1) RESULT err=0 tag=48 nentries=1 |
| 633 |
assert topo.ds_access_log.match(r'.*\(Internal\) op=[0-9]+\([0-9]+\)\([0-9]+\) RESULT err=0 tag=48 nentries=1.*') |
| 634 |
# op=15 RESULT err=0 tag=107 |
| 635 |
assert not topo.ds_access_log.match(r'.*op=[0-9]+ RESULT err=0 tag=107.*') |
| 636 |
|
| 637 |
log.info("Check if the other internal operations have the correct format") |
| 638 |
# conn=Internal(0) op=0 |
| 639 |
assert topo.ds_access_log.match(r'.*conn=Internal\([0-9]+\) op=[0-9]+\([0-9]+\)\([0-9]+\).*') |
| 640 |
|
| 641 |
|
| 642 |
@pytest.mark.skipif(ds_is_older('1.4.2.0'), reason="Not implemented") |
| 643 |
def test_access_log_truncated_search_message(topology_st, clean_access_logs): |
| 644 |
"""Tests that the access log message is properly truncated when the message is too long |
| 645 |
|
| 646 |
:id: 0a9af37d-3311-4a2f-ac0a-9a1c631aaf27 |
| 647 |
:setup: Standalone instance |
| 648 |
:steps: |
| 649 |
1. Make a search with a 2048+ characters basedn, filter and attribute list |
| 650 |
2. Check the access log has the message and it's truncated |
| 651 |
:expectedresults: |
| 652 |
1. Operation should be successful |
| 653 |
2. Access log should contain truncated basedn, filter and attribute list |
| 654 |
""" |
| 655 |
|
| 656 |
topo = topology_st.standalone |
| 657 |
|
| 658 |
large_str_base = "".join("cn=test," for _ in range(512)) |
| 659 |
large_str_filter = "".join("(cn=test)" for _ in range(512)) |
| 660 |
users = UserAccounts(topo, f'{large_str_base}dc=ending') |
| 661 |
users._list_attrlist = [f'cn{i}' for i in range(512)] |
| 662 |
log.info("Make a search") |
| 663 |
users.filter(f'(|(objectclass=tester){large_str_filter}(cn=ending))') |
| 664 |
|
| 665 |
log.info('Restart the server to flush the logs') |
| 666 |
topo.restart() |
| 667 |
|
| 668 |
assert topo.ds_access_log.match(r'.*cn=test,cn=test,.*') |
| 669 |
assert topo.ds_access_log.match(r'.*objectClass=tester.*') |
| 670 |
assert topo.ds_access_log.match(r'.*cn10.*') |
| 671 |
assert not topo.ds_access_log.match(r'.*dc=ending.*') |
| 672 |
assert not topo.ds_access_log.match(r'.*cn=ending.*') |
| 673 |
assert not topo.ds_access_log.match(r'.*cn500.*') |
| 674 |
|
| 675 |
|
| 676 |
@pytest.mark.skipif(ds_is_newer("1.4.3"), reason="rsearch was removed") |
| 677 |
@pytest.mark.xfail(ds_is_older('1.4.2.0'), reason="May fail because of bug 1732053") |
| 678 |
def test_etime_at_border_of_second(topology_st, clean_access_logs): |
| 679 |
"""Test that the etime reported in the access log doesn't contain wrong nsec value |
| 680 |
|
| 681 |
:id: 622be191-235b-4e1f-b581-2627fb10e494 |
| 682 |
:setup: Standalone instance |
| 683 |
:steps: |
| 684 |
1. Run rsearch |
| 685 |
2. Check access logs |
| 686 |
:expectedresults: |
| 687 |
1. Success |
| 688 |
2. No etime with 0.199xxx (everything should be few ms) |
| 689 |
""" |
| 690 |
topo = topology_st.standalone |
| 691 |
|
| 692 |
prog = os.path.join(topo.ds_paths.bin_dir, 'rsearch') |
| 693 |
|
| 694 |
cmd = [prog] |
| 695 |
|
| 696 |
# base search |
| 697 |
cmd.extend(['-s', DN_CONFIG]) |
| 698 |
|
| 699 |
# scope of the search |
| 700 |
cmd.extend(['-S', '0']) |
| 701 |
|
| 702 |
# host / port |
| 703 |
cmd.extend(['-h', HOST_STANDALONE]) |
| 704 |
cmd.extend(['-p', str(PORT_STANDALONE)]) |
| 705 |
|
| 706 |
# bound as DM to make it faster |
| 707 |
cmd.extend(['-D', DN_DM]) |
| 708 |
cmd.extend(['-w', PASSWORD]) |
| 709 |
|
| 710 |
# filter |
| 711 |
cmd.extend(['-f', "(cn=config)"]) |
| 712 |
|
| 713 |
# 2 samples SRCH |
| 714 |
cmd.extend(['-C', "2"]) |
| 715 |
|
| 716 |
output = subprocess.check_output(cmd) |
| 717 |
topo.stop() |
| 718 |
|
| 719 |
# No etime with 0.199xxx (everything should be few ms) |
| 720 |
invalid_etime = topo.ds_access_log.match(r'.*etime=0\.19.*') |
| 721 |
if invalid_etime: |
| 722 |
for i in range(len(invalid_etime)): |
| 723 |
log.error('It remains invalid or weird etime: %s' % invalid_etime[i]) |
| 724 |
assert not invalid_etime |
| 725 |
|
| 726 |
|
| 727 |
@pytest.mark.flaky(max_runs=2, min_passes=1) |
| 728 |
@pytest.mark.skipif(ds_is_older('1.3.10.1', '1.4.1'), reason="Fail because of bug 1749236") |
| 729 |
def test_etime_order_of_magnitude(topology_st, clean_access_logs, remove_users, disable_access_log_buffering): |
| 730 |
"""Test that the etime reported in the access log has a correct order of magnitude |
| 731 |
|
| 732 |
:id: e815cfa0-8136-4932-b50f-c3dfac34b0e6 |
| 733 |
:setup: Standalone instance |
| 734 |
:steps: |
| 735 |
1. Unset log buffering for the access log |
| 736 |
2. Delete potential existing access logs |
| 737 |
3. Add users |
| 738 |
4. Search users |
| 739 |
5. Restart the server to flush the logs |
| 740 |
6. Parse the access log looking for the SRCH operation log |
| 741 |
7. From the SRCH string get the start time and op number of the operation |
| 742 |
8. From the op num find the associated RESULT string in the access log |
| 743 |
9. From the RESULT string get the end time and the etime for the operation |
| 744 |
10. Calculate the ratio between the calculated elapsed time (end time - start time) and the logged etime |
| 745 |
:expectedresults: |
| 746 |
1. access log buffering is off |
| 747 |
2. Previously existing access logs are deleted |
| 748 |
3. Users are successfully added |
| 749 |
4. Search operation is successful |
| 750 |
5. Server is restarted and logs are flushed |
| 751 |
6. SRCH operation log string is catched |
| 752 |
7. start time and op number are collected |
| 753 |
8. RESULT string is catched from the access log |
| 754 |
9. end time and etime are collected |
| 755 |
10. ratio between calculated elapsed time and logged etime is less or equal to 1 |
| 756 |
""" |
| 757 |
|
| 758 |
DSLdapObject(topology_st.standalone, DEFAULT_SUFFIX) |
| 759 |
|
| 760 |
log.info('add_users') |
| 761 |
add_users(topology_st.standalone, 30) |
| 762 |
|
| 763 |
log.info ('search users') |
| 764 |
search_users(topology_st.standalone) |
| 765 |
|
| 766 |
log.info('parse the access logs to get the SRCH string') |
| 767 |
# Here we are looking at the whole string logged for the search request with base ou=People,dc=example,dc=com |
| 768 |
search_str = str(topology_st.standalone.ds_access_log.match(r'.*SRCH base="ou=People,dc=example,dc=com.*'))[1:-1] |
| 769 |
assert len(search_str) > 0 |
| 770 |
|
| 771 |
# the search_str returned looks like : |
| 772 |
# [23/Apr/2020:06:06:14.360857624 -0400] conn=1 op=93 SRCH base="ou=People,dc=example,dc=com" scope=2 filter="(&(objectClass=account)(objectClass=posixaccount)(objectClass=inetOrgPerson)(objectClass=organizationalPerson))" attrs="distinguishedName" |
| 773 |
|
| 774 |
log.info('get the operation start time from the SRCH string') |
| 775 |
# Here we are getting the sec.nanosec part of the date, '14.360857624' in the example above |
| 776 |
start_time = (search_str.split()[0]).split(':')[3] |
| 777 |
|
| 778 |
log.info('get the OP number from the SRCH string') |
| 779 |
# Here we are getting the op number, 'op=93' in the above example |
| 780 |
op_num = search_str.split()[3] |
| 781 |
|
| 782 |
log.info('get the RESULT string matching the SRCH OP number') |
| 783 |
# Here we are looking at the RESULT string for the above search op, 'op=93' in this example |
| 784 |
result_str = str(topology_st.standalone.ds_access_log.match(r'.*{} RESULT*'.format(op_num)))[1:-1] |
| 785 |
assert len(result_str) > 0 |
| 786 |
|
| 787 |
# The result_str returned looks like : |
| 788 |
# For ds older than 1.4.3.8: [23/Apr/2020:06:06:14.366429900 -0400] conn=1 op=93 RESULT err=0 tag=101 nentries=30 etime=0.005723017 |
| 789 |
# For ds newer than 1.4.3.8: [21/Oct/2020:09:27:50.095209871 -0400] conn=1 op=96 RESULT err=0 tag=101 nentries=30 wtime=0.000412584 optime=0.005428971 etime=0.005836077 |
| 790 |
|
| 791 |
log.info('get the operation end time from the RESULT string') |
| 792 |
# Here we are getting the sec.nanosec part of the date, '14.366429900' in the above example |
| 793 |
end_time = (result_str.split()[0]).split(':')[3] |
| 794 |
|
| 795 |
log.info('get the logged etime for the operation from the RESULT string') |
| 796 |
# Here we are getting the etime value, '0.005723017' in the example above |
| 797 |
if ds_is_older('1.4.3.8'): |
| 798 |
etime = result_str.split()[8].split('=')[1][:-3] |
| 799 |
else: |
| 800 |
etime = result_str.split()[10].split('=')[1][:-3] |
| 801 |
|
| 802 |
log.info('Calculate the ratio between logged etime for the operation and elapsed time from its start time to its end time - should be around 1') |
| 803 |
etime_ratio = (Decimal(end_time) - Decimal(start_time)) // Decimal(etime) |
| 804 |
assert etime_ratio <= 1 |
| 805 |
|
| 806 |
|
| 807 |
@pytest.mark.skipif(ds_is_older('1.4.3.8'), reason="Fail because of bug 1850275") |
| 808 |
def test_optime_and_wtime_keywords(topology_st, clean_access_logs, remove_users, disable_access_log_buffering): |
| 809 |
"""Test that the new optime and wtime keywords are present in the access log and have correct values |
| 810 |
|
| 811 |
:id: dfb4a49d-1cfc-400e-ba43-c107f58d62cf |
| 812 |
:customerscenario: True |
| 813 |
:setup: Standalone instance |
| 814 |
:steps: |
| 815 |
1. Unset log buffering for the access log |
| 816 |
2. Delete potential existing access logs |
| 817 |
3. Add users |
| 818 |
4. Search users |
| 819 |
5. Parse the access log looking for the SRCH operation log |
| 820 |
6. From the SRCH string get the op number of the operation |
| 821 |
7. From the op num find the associated RESULT string in the access log |
| 822 |
8. Search for the wtime optime keywords in the RESULT string |
| 823 |
9. From the RESULT string get the wtime, optime and etime values for the operation |
| 824 |
:expectedresults: |
| 825 |
1. access log buffering is off |
| 826 |
2. Previously existing access logs are deleted |
| 827 |
3. Users are successfully added |
| 828 |
4. Search operation is successful |
| 829 |
5. SRCH operation log string is catched |
| 830 |
6. op number is collected |
| 831 |
7. RESULT string is catched from the access log |
| 832 |
8. wtime and optime keywords are collected |
| 833 |
9. wtime, optime and etime values are collected |
| 834 |
""" |
| 835 |
|
| 836 |
log.info('add_users') |
| 837 |
add_users(topology_st.standalone, 30) |
| 838 |
|
| 839 |
log.info ('search users') |
| 840 |
search_users(topology_st.standalone) |
| 841 |
|
| 842 |
log.info('parse the access logs to get the SRCH string') |
| 843 |
# Here we are looking at the whole string logged for the search request with base ou=People,dc=example,dc=com |
| 844 |
search_str = str(topology_st.standalone.ds_access_log.match(r'.*SRCH base="ou=People,dc=example,dc=com.*'))[1:-1] |
| 845 |
assert len(search_str) > 0 |
| 846 |
|
| 847 |
# the search_str returned looks like : |
| 848 |
# [22/Oct/2020:09:47:11.951316798 -0400] conn=1 op=96 SRCH base="ou=People,dc=example,dc=com" scope=2 filter="(&(objectClass=account)(objectClass=posixaccount)(objectClass=inetOrgPerson)(objectClass=organizationalPerson))" attrs="distinguishedName" |
| 849 |
|
| 850 |
log.info('get the OP number from the SRCH string') |
| 851 |
# Here we are getting the op number, 'op=96' in the above example |
| 852 |
op_num = search_str.split()[3] |
| 853 |
|
| 854 |
log.info('get the RESULT string matching the SRCH op number') |
| 855 |
# Here we are looking at the RESULT string for the above search op, 'op=96' in this example |
| 856 |
result_str = str(topology_st.standalone.ds_access_log.match(r'.*{} RESULT*'.format(op_num)))[1:-1] |
| 857 |
assert len(result_str) > 0 |
| 858 |
|
| 859 |
# The result_str returned looks like : |
| 860 |
# [22/Oct/2020:09:47:11.963276018 -0400] conn=1 op=96 RESULT err=0 tag=101 nentries=30 wtime=0.000180294 optime=0.011966632 etime=0.012141311 |
| 861 |
log.info('Search for the wtime keyword in the RESULT string') |
| 862 |
assert re.search('wtime', result_str) |
| 863 |
|
| 864 |
log.info('get the wtime value from the RESULT string') |
| 865 |
wtime_value = result_str.split()[8].split('=')[1][:-3] |
| 866 |
|
| 867 |
log.info('Search for the optime keyword in the RESULT string') |
| 868 |
assert re.search('optime', result_str) |
| 869 |
|
| 870 |
log.info('get the optime value from the RESULT string') |
| 871 |
optime_value = result_str.split()[9].split('=')[1][:-3] |
| 872 |
|
| 873 |
log.info('get the etime value from the RESULT string') |
| 874 |
etime_value = result_str.split()[10].split('=')[1][:-3] |
| 875 |
|
| 876 |
log.info('Perform a compare operation') |
| 877 |
topology_st.standalone.compare_s('uid=testuser1000,ou=people,dc=example,dc=com','uid', 'testuser1000') |
| 878 |
ops = topology_st.standalone.ds_access_log.match('.*CMP dn="uid=testuser1000,ou=people,dc=example,dc=com"') |
| 879 |
|
| 880 |
log.info('get the wtime and optime values from the RESULT string') |
| 881 |
ops_value = topology_st.standalone.ds_access_log.parse_line(ops[0]) |
| 882 |
value = topology_st.standalone.ds_access_log.match(f'.*op={ops_value["op"]} RESULT') |
| 883 |
time_value = topology_st.standalone.ds_access_log.parse_line(value[0]) |
| 884 |
wtime = time_value['rem'].split()[3].split('=')[1] |
| 885 |
optime = time_value['rem'].split()[4].split('=')[1] |
| 886 |
|
| 887 |
log.info('Check that compare operation is not generating negative values for wtime and optime') |
| 888 |
if (Decimal(wtime) > 0) and (Decimal(optime) > 0): |
| 889 |
assert True |
| 890 |
else: |
| 891 |
log.info('wtime and optime values are negatives') |
| 892 |
assert False |
| 893 |
|
| 894 |
|
| 895 |
@pytest.mark.xfail(ds_is_older('1.3.10.1'), reason="May fail because of bug 1662461") |
| 896 |
def test_log_base_dn_when_invalid_attr_request(topology_st, disable_access_log_buffering): |
| 897 |
"""Test that DS correctly logs the base dn when a search with invalid attribute request is performed |
| 898 |
|
| 899 |
:id: 859de962-c261-4ffb-8705-97bceab1ba2c |
| 900 |
:setup: Standalone instance |
| 901 |
:steps: |
| 902 |
1. Disable the accesslog-logbuffering config parameter |
| 903 |
2. Delete the previous access log |
| 904 |
3. Perform a base search on the DEFAULT_SUFFIX, using ten empty attribute requests |
| 905 |
4. Check the access log file for 'invalid attribute request' |
| 906 |
5. Check the access log file for 'SRCH base="\(null\)"' |
| 907 |
6. Check the access log file for 'SRCH base="DEFAULT_SUFFIX"' |
| 908 |
:expectedresults: |
| 909 |
1. Operations are visible in the access log in real time |
| 910 |
2. Fresh new access log is created |
| 911 |
3. The search operation raises a Protocol error |
| 912 |
4. The access log should have an 'invalid attribute request' message |
| 913 |
5. The access log should not have "\(null\)" as value for the Search base dn |
| 914 |
6. The access log should have the value of DEFAULT_SUFFIX as Search base dn |
| 915 |
""" |
| 916 |
|
| 917 |
entry = DSLdapObject(topology_st.standalone, DEFAULT_SUFFIX) |
| 918 |
|
| 919 |
log.info('delete the previous access logs to get a fresh new one') |
| 920 |
topology_st.standalone.deleteAccessLogs() |
| 921 |
|
| 922 |
log.info("Search the default suffix, with invalid '\"\" \"\"' attribute request") |
| 923 |
log.info("A Protocol error exception should be raised, see https://github.com/389ds/389-ds-base/issues/3028") |
| 924 |
# A ldap.PROTOCOL_ERROR exception is expected after 10 empty values |
| 925 |
with pytest.raises(ldap.PROTOCOL_ERROR): |
| 926 |
assert entry.get_attrs_vals_utf8(['', '', '', '', '', '', '', '', '', '', '']) |
| 927 |
|
| 928 |
# Search for appropriate messages in the access log |
| 929 |
log.info('Check the access logs for correct messages') |
| 930 |
# We should find the 'invalid attribute request' information |
| 931 |
assert topology_st.standalone.ds_access_log.match(r'.*invalid attribute request.*') |
| 932 |
# We should not find a "(null)" base dn mention |
| 933 |
assert not topology_st.standalone.ds_access_log.match(r'.*SRCH base="\(null\)".*') |
| 934 |
# We should find the base dn for the search |
| 935 |
assert topology_st.standalone.ds_access_log.match(r'.*SRCH base="{}".*'.format(DEFAULT_SUFFIX)) |
| 936 |
|
| 937 |
|
| 938 |
@pytest.mark.xfail(ds_is_older('1.3.8', '1.4.2'), reason="May fail because of bug 1676948") |
| 939 |
def test_audit_log_rotate_and_check_string(topology_st, clean_access_logs, set_audit_log_config_values_to_rotate): |
| 940 |
"""Version string should be logged only once at the top of audit log |
| 941 |
after it is rotated. |
| 942 |
|
| 943 |
:id: 14dffb22-2f9c-11e9-8a03-54e1ad30572c |
| 944 |
|
| 945 |
:customerscenario: True |
| 946 |
|
| 947 |
:setup: Standalone instance |
| 948 |
|
| 949 |
:steps: |
| 950 |
1. Set nsslapd-auditlog-logging-enabled: on |
| 951 |
2. Set nsslapd-auditlog-maxlogsize: 1 |
| 952 |
3. Do modifications to the entry, until audit log file is rotated |
| 953 |
4. Check audit logs |
| 954 |
|
| 955 |
:expectedresults: |
| 956 |
1. Attribute nsslapd-auditlog-logging-enabled should be set to on |
| 957 |
2. Attribute nsslapd-auditlog-maxlogsize should be set to 1 |
| 958 |
3. Audit file should grow till 1MB and then should be rotated |
| 959 |
4. Audit file log should contain version string only once at the top |
| 960 |
""" |
| 961 |
|
| 962 |
standalone = topology_st.standalone |
| 963 |
search_ds = '389-Directory' |
| 964 |
|
| 965 |
users = UserAccounts(standalone, DEFAULT_SUFFIX) |
| 966 |
user = users.create(properties={ |
| 967 |
'uid': 'test_audit_log', |
| 968 |
'cn': 'test', |
| 969 |
'sn': 'user', |
| 970 |
'uidNumber': '1000', |
| 971 |
'gidNumber': '1000', |
| 972 |
'homeDirectory': '/home/test', |
| 973 |
}) |
| 974 |
|
| 975 |
log.info('Doing modifications to rotate audit log') |
| 976 |
audit_log = standalone.ds_paths.audit_log |
| 977 |
while len(glob.glob(audit_log + '*')) == 2: |
| 978 |
user.replace('description', 'test'*100) |
| 979 |
|
| 980 |
log.info('Doing one more modification just in case') |
| 981 |
user.replace('description', 'test2'*100) |
| 982 |
|
| 983 |
standalone.stop() |
| 984 |
|
| 985 |
count = 0 |
| 986 |
with open(audit_log) as f: |
| 987 |
log.info('Check that DS string is present on first line') |
| 988 |
assert search_ds in f.readline() |
| 989 |
f.seek(0) |
| 990 |
|
| 991 |
log.info('Check that DS string is present only once') |
| 992 |
for line in f.readlines(): |
| 993 |
if search_ds in line: |
| 994 |
count += 1 |
| 995 |
assert count == 1 |
| 996 |
|
| 997 |
|
| 998 |
def test_enable_external_libs_debug_log(topology_st): |
| 999 |
"""Check that OpenLDAP logs are successfully enabled and disabled |
| 1000 |
|
| 1001 |
:id: b04646e3-9a5e-45ae-ad81-2882c1daf23e |
| 1002 |
:setup: Standalone instance |
| 1003 |
:steps: 1. Create a user to bind on |
| 1004 |
2. Set nsslapd-external-libs-debug-enabled to "on" |
| 1005 |
3. Clean the error log |
| 1006 |
4. Bind as the user to generate OpenLDAP output |
| 1007 |
5. Restart the servers to flush the logs |
| 1008 |
6. Check the error log for OpenLDAP debug log |
| 1009 |
7. Set nsslapd-external-libs-debug-enabled to "on" |
| 1010 |
8. Clean the error log |
| 1011 |
9. Bind as the user to generate OpenLDAP output |
| 1012 |
10. Restart the servers to flush the logs |
| 1013 |
11. Check the error log for OpenLDAP debug log |
| 1014 |
:expectedresults: 1. Success |
| 1015 |
2. Success |
| 1016 |
3. Success |
| 1017 |
4. Success |
| 1018 |
5. Success |
| 1019 |
6. Logs are present |
| 1020 |
7. Success |
| 1021 |
8. Success |
| 1022 |
9. Success |
| 1023 |
10. Success |
| 1024 |
11. No logs are present |
| 1025 |
""" |
| 1026 |
|
| 1027 |
standalone = topology_st.standalone |
| 1028 |
|
| 1029 |
log.info('Create a user to bind on') |
| 1030 |
users = UserAccounts(standalone, DEFAULT_SUFFIX) |
| 1031 |
user = users.ensure_state(properties={ |
| 1032 |
'uid': 'test_audit_log', |
| 1033 |
'cn': 'test', |
| 1034 |
'sn': 'user', |
| 1035 |
'uidNumber': '1000', |
| 1036 |
'gidNumber': '1000', |
| 1037 |
'homeDirectory': '/home/test', |
| 1038 |
'userPassword': PASSWORD |
| 1039 |
}) |
| 1040 |
|
| 1041 |
log.info('Set nsslapd-external-libs-debug-enabled to "on"') |
| 1042 |
standalone.config.set('nsslapd-external-libs-debug-enabled', 'on') |
| 1043 |
|
| 1044 |
log.info('Clean the error log') |
| 1045 |
standalone.deleteErrorLogs() |
| 1046 |
|
| 1047 |
log.info('Bind as the user to generate OpenLDAP output') |
| 1048 |
user.bind(PASSWORD) |
| 1049 |
|
| 1050 |
log.info('Restart the servers to flush the logs') |
| 1051 |
standalone.restart() |
| 1052 |
|
| 1053 |
log.info('Check the error log for OpenLDAP debug log') |
| 1054 |
assert standalone.ds_error_log.match('.*libldap/libber.*') |
| 1055 |
|
| 1056 |
log.info('Set nsslapd-external-libs-debug-enabled to "off"') |
| 1057 |
standalone.config.set('nsslapd-external-libs-debug-enabled', 'off') |
| 1058 |
|
| 1059 |
log.info('Clean the error log') |
| 1060 |
standalone.deleteErrorLogs() |
| 1061 |
|
| 1062 |
log.info('Bind as the user to generate OpenLDAP output') |
| 1063 |
user.bind(PASSWORD) |
| 1064 |
|
| 1065 |
log.info('Restart the servers to flush the logs') |
| 1066 |
standalone.restart() |
| 1067 |
|
| 1068 |
log.info('Check the error log for OpenLDAP debug log') |
| 1069 |
assert not standalone.ds_error_log.match('.*libldap/libber.*') |
| 1070 |
|
| 1071 |
|
| 1072 |
@pytest.mark.skipif(ds_is_older('1.4.3'), reason="Might fail because of bug 1895460") |
| 1073 |
def test_cert_personality_log_help(topology_st, request): |
| 1074 |
"""Test changing the nsSSLPersonalitySSL attribute will raise help message in log |
| 1075 |
|
| 1076 |
:id: d6f17f64-d784-438e-89b6-8595bdf6defb |
| 1077 |
:customerscenario: True |
| 1078 |
:setup: Standalone |
| 1079 |
:steps: |
| 1080 |
1. Create instance |
| 1081 |
2. Change nsSSLPersonalitySSL to wrong certificate nickname |
| 1082 |
3. Check there is a help message in error log |
| 1083 |
:expectedresults: |
| 1084 |
1. Success |
| 1085 |
2. Success |
| 1086 |
3. Success |
| 1087 |
""" |
| 1088 |
|
| 1089 |
WRONG_NICK = 'otherNick' |
| 1090 |
standalone = topology_st.standalone |
| 1091 |
standalone.enable_tls() |
| 1092 |
|
| 1093 |
log.info('Change nsSSLPersonalitySSL to wrong certificate nickname') |
| 1094 |
config_RSA = RSA(standalone) |
| 1095 |
config_RSA.set('nsSSLPersonalitySSL', WRONG_NICK) |
| 1096 |
|
| 1097 |
with pytest.raises(subprocess.CalledProcessError): |
| 1098 |
standalone.restart() |
| 1099 |
|
| 1100 |
assert standalone.ds_error_log.match(r".*Please, make sure that nsSSLPersonalitySSL value " |
| 1101 |
r"is correctly set to the certificate from NSS database " |
| 1102 |
r"\(currently, nsSSLPersonalitySSL attribute " |
| 1103 |
r"is set to '{}'\)\..*".format(WRONG_NICK)) |
| 1104 |
def fin(): |
| 1105 |
log.info('Restore certificate nickname') |
| 1106 |
dse_ldif = DSEldif(standalone) |
| 1107 |
dse_ldif.replace("cn=RSA,cn=encryption,cn=config", "nsSSLPersonalitySSL", "Server-Cert") |
| 1108 |
|
| 1109 |
request.addfinalizer(fin) |
| 1110 |
|
| 1111 |
def test_stat_index(topology_st, request): |
| 1112 |
"""Testing nsslapd-statlog-level with indexing statistics |
| 1113 |
|
| 1114 |
:id: fcabab05-f000-468c-8eb4-02ce3c39c902 |
| 1115 |
:setup: Standalone instance |
| 1116 |
:steps: |
| 1117 |
1. Check that nsslapd-statlog-level is 0 (default) |
| 1118 |
2. Create 20 users with 'cn' starting with 'user\_' |
| 1119 |
3. Check there is no statistic record in the access log with ADD |
| 1120 |
4. Check there is no statistic record in the access log with SRCH |
| 1121 |
5. Set nsslapd-statlog-level=LDAP_STAT_READ_INDEX (0x1) to get |
| 1122 |
statistics when reading indexes |
| 1123 |
6. Check there is statistic records in access log with SRCH |
| 1124 |
:expectedresults: |
| 1125 |
1. This should pass |
| 1126 |
2. This should pass |
| 1127 |
3. This should pass |
| 1128 |
4. This should pass |
| 1129 |
5. This should pass |
| 1130 |
6. This should pass |
| 1131 |
""" |
| 1132 |
topology_st.standalone.start() |
| 1133 |
|
| 1134 |
# Step 1 |
| 1135 |
log.info("Assert nsslapd-statlog-level is by default 0") |
| 1136 |
assert topology_st.standalone.config.get_attr_val_int("nsslapd-statlog-level") == 0 |
| 1137 |
|
| 1138 |
# Step 2 |
| 1139 |
users = UserAccounts(topology_st.standalone, DEFAULT_SUFFIX) |
| 1140 |
users_set = [] |
| 1141 |
log.info('Adding 20 users') |
| 1142 |
for i in range(20): |
| 1143 |
name = 'user_%d' % i |
| 1144 |
last_user = users.create(properties={ |
| 1145 |
'uid': name, |
| 1146 |
'sn': name, |
| 1147 |
'cn': name, |
| 1148 |
'uidNumber': '1000', |
| 1149 |
'gidNumber': '1000', |
| 1150 |
'homeDirectory': '/home/%s' % name, |
| 1151 |
'mail': '%[email protected]' % name, |
| 1152 |
'userpassword': 'pass%s' % name, |
| 1153 |
}) |
| 1154 |
users_set.append(last_user) |
| 1155 |
|
| 1156 |
# Step 3 |
| 1157 |
assert not topology_st.standalone.ds_access_log.match('.*STAT read index.*') |
| 1158 |
|
| 1159 |
# Step 4 |
| 1160 |
entries = topology_st.standalone.search_s(DEFAULT_SUFFIX, ldap.SCOPE_SUBTREE, "cn=user_*") |
| 1161 |
assert not topology_st.standalone.ds_access_log.match('.*STAT read index.*') |
| 1162 |
|
| 1163 |
# Step 5 |
| 1164 |
log.info("Set nsslapd-statlog-level: 1 to enable indexing statistics") |
| 1165 |
topology_st.standalone.config.set("nsslapd-statlog-level", "1") |
| 1166 |
|
| 1167 |
# Step 6 |
| 1168 |
entries = topology_st.standalone.search_s(DEFAULT_SUFFIX, ldap.SCOPE_SUBTREE, "cn=user_*") |
| 1169 |
topology_st.standalone.stop() |
| 1170 |
assert topology_st.standalone.ds_access_log.match('.*STAT read index.*') |
| 1171 |
assert topology_st.standalone.ds_access_log.match('.*STAT read index: attribute.*') |
| 1172 |
assert topology_st.standalone.ds_access_log.match('.*STAT read index: duration.*') |
| 1173 |
topology_st.standalone.start() |
| 1174 |
|
| 1175 |
def fin(): |
| 1176 |
log.info('Deleting users') |
| 1177 |
for user in users_set: |
| 1178 |
user.delete() |
| 1179 |
topology_st.standalone.config.set("nsslapd-statlog-level", "0") |
| 1180 |
|
| 1181 |
request.addfinalizer(fin) |
| 1182 |
|
| 1183 |
def test_stat_internal_op(topology_st, request): |
| 1184 |
"""Check that statistics can also be collected for internal operations |
| 1185 |
|
| 1186 |
:id: 19f393bd-5866-425a-af7a-4dade06d5c77 |
| 1187 |
:setup: Standalone Instance |
| 1188 |
:steps: |
| 1189 |
1. Check that nsslapd-statlog-level is 0 (default) |
| 1190 |
2. Enable memberof plugins |
| 1191 |
3. Create a user |
| 1192 |
4. Remove access log (to only detect new records) |
| 1193 |
5. Enable statistic logging nsslapd-statlog-level=1 |
| 1194 |
6. Check that on direct SRCH there is no 'Internal' Stat records |
| 1195 |
7. Remove access log (to only detect new records) |
| 1196 |
8. Add group with the user, so memberof triggers internal search |
| 1197 |
and check it exists 'Internal' Stat records |
| 1198 |
:expectedresults: |
| 1199 |
1. Success |
| 1200 |
2. Success |
| 1201 |
3. Success |
| 1202 |
4. Success |
| 1203 |
5. Success |
| 1204 |
6. Success |
| 1205 |
7. Success |
| 1206 |
8. Success |
| 1207 |
""" |
| 1208 |
|
| 1209 |
inst = topology_st.standalone |
| 1210 |
|
| 1211 |
# Step 1 |
| 1212 |
log.info("Assert nsslapd-statlog-level is by default 0") |
| 1213 |
assert topology_st.standalone.config.get_attr_val_int("nsslapd-statlog-level") == 0 |
| 1214 |
|
| 1215 |
# Step 2 |
| 1216 |
memberof = MemberOfPlugin(inst) |
| 1217 |
memberof.enable() |
| 1218 |
inst.restart() |
| 1219 |
|
| 1220 |
# Step 3 Add setup entries |
| 1221 |
users = UserAccounts(inst, DEFAULT_SUFFIX, rdn=None) |
| 1222 |
user = users.create(properties={'uid': 'test_1', |
| 1223 |
'cn': 'test_1', |
| 1224 |
'sn': 'test_1', |
| 1225 |
'description': 'member', |
| 1226 |
'uidNumber': '1000', |
| 1227 |
'gidNumber': '2000', |
| 1228 |
'homeDirectory': '/home/testuser'}) |
| 1229 |
# Step 4 reset accesslog |
| 1230 |
topology_st.standalone.stop() |
| 1231 |
lpath = topology_st.standalone.ds_access_log._get_log_path() |
| 1232 |
os.unlink(lpath) |
| 1233 |
topology_st.standalone.start() |
| 1234 |
|
| 1235 |
# Step 5 enable statistics |
| 1236 |
log.info("Set nsslapd-statlog-level: 1 to enable indexing statistics") |
| 1237 |
topology_st.standalone.config.set("nsslapd-statlog-level", "1") |
| 1238 |
|
| 1239 |
# Step 6 for direct SRCH only non internal STAT records |
| 1240 |
entries = topology_st.standalone.search_s(DEFAULT_SUFFIX, ldap.SCOPE_SUBTREE, "uid=test_1") |
| 1241 |
topology_st.standalone.stop() |
| 1242 |
assert topology_st.standalone.ds_access_log.match('.*STAT read index.*') |
| 1243 |
assert topology_st.standalone.ds_access_log.match('.*STAT read index: attribute.*') |
| 1244 |
assert topology_st.standalone.ds_access_log.match('.*STAT read index: duration.*') |
| 1245 |
assert not topology_st.standalone.ds_access_log.match('.*Internal.*STAT.*') |
| 1246 |
topology_st.standalone.start() |
| 1247 |
|
| 1248 |
# Step 7 reset accesslog |
| 1249 |
topology_st.standalone.stop() |
| 1250 |
lpath = topology_st.standalone.ds_access_log._get_log_path() |
| 1251 |
os.unlink(lpath) |
| 1252 |
topology_st.standalone.start() |
| 1253 |
|
| 1254 |
# Step 8 trigger internal searches and check internal stat records |
| 1255 |
groups = Groups(inst, DEFAULT_SUFFIX, rdn=None) |
| 1256 |
group = groups.create(properties={'cn': 'mygroup', |
| 1257 |
'member': 'uid=test_1,%s' % DEFAULT_SUFFIX, |
| 1258 |
'description': 'group'}) |
| 1259 |
topology_st.standalone.restart() |
| 1260 |
assert topology_st.standalone.ds_access_log.match('.*Internal.*STAT read index.*') |
| 1261 |
assert topology_st.standalone.ds_access_log.match('.*Internal.*STAT read index: attribute.*') |
| 1262 |
assert topology_st.standalone.ds_access_log.match('.*Internal.*STAT read index: duration.*') |
| 1263 |
|
| 1264 |
def fin(): |
| 1265 |
log.info('Deleting user/group') |
| 1266 |
user.delete() |
| 1267 |
group.delete() |
| 1268 |
|
| 1269 |
request.addfinalizer(fin) |
| 1270 |
|
| 1271 |
|
| 1272 |
@pytest.fixture |
| 1273 |
def thread_pool_log_setup(topology_st, request): |
| 1274 |
"""Standalone instance with unbuffered plain-text access log, statlog off |
| 1275 |
and a clean access log on disk. |
| 1276 |
""" |
| 1277 |
inst = topology_st.standalone |
| 1278 |
inst.config.replace("nsslapd-accesslog-logbuffering", "off") |
| 1279 |
inst.config.replace("nsslapd-accesslog-log-format", "default") |
| 1280 |
inst.config.replace("nsslapd-statlog-level", "0") |
| 1281 |
inst.deleteAccessLogs(restart=True) |
| 1282 |
|
| 1283 |
def fin(): |
| 1284 |
inst.config.replace("nsslapd-statlog-level", "0") |
| 1285 |
inst.config.replace("nsslapd-accesslog-log-format", "default") |
| 1286 |
for u in UserAccounts(inst, DEFAULT_SUFFIX).filter('(uid=pool_*)'): |
| 1287 |
try: |
| 1288 |
u.delete() |
| 1289 |
except Exception: |
| 1290 |
pass |
| 1291 |
request.addfinalizer(fin) |
| 1292 |
return inst |
| 1293 |
|
| 1294 |
|
| 1295 |
def _exercise_all_op_types(inst, tag): |
| 1296 |
"""Drive one of each externally-initiated op type so each produces a |
| 1297 |
RESULT: BIND, ADD, SEARCH, MOD, EXTOP (WhoAmI), DEL. `tag` keeps uids |
| 1298 |
unique across invocations. |
| 1299 |
""" |
| 1300 |
users = UserAccounts(inst, DEFAULT_SUFFIX) |
| 1301 |
uid = f'pool_{tag}' |
| 1302 |
inst.simple_bind_s(DN_DM, PASSWORD) |
| 1303 |
user = users.create(properties={ |
| 1304 |
'uid': uid, 'sn': uid, 'cn': uid, |
| 1305 |
'uidNumber': '7001', 'gidNumber': '7000', |
| 1306 |
'homeDirectory': f'/home/{uid}', |
| 1307 |
}) |
| 1308 |
inst.search_s(DEFAULT_SUFFIX, ldap.SCOPE_SUBTREE, f'uid={uid}') |
| 1309 |
user.replace('description', 'pool-test') |
| 1310 |
inst.whoami_s() |
| 1311 |
user.delete() |
| 1312 |
|
| 1313 |
|
| 1314 |
def test_stat_thread_pool_off_by_default(thread_pool_log_setup): |
| 1315 |
"""Default nsslapd-statlog-level=0 emits no thread pool stats on RESULT. |
| 1316 |
|
| 1317 |
:id: 8e289662-ccb7-4647-be81-a637750a5e13 |
| 1318 |
:setup: Standalone instance, statlog-level=0 |
| 1319 |
:steps: |
| 1320 |
1. Confirm nsslapd-statlog-level is 0 |
| 1321 |
2. Exercise one of each externally-initiated op type |
| 1322 |
3. No RESULT line carries wbusy= |
| 1323 |
:expectedresults: |
| 1324 |
1. Success |
| 1325 |
2. Success |
| 1326 |
3. Success |
| 1327 |
""" |
| 1328 |
inst = thread_pool_log_setup |
| 1329 |
assert inst.config.get_attr_val_int("nsslapd-statlog-level") == 0 |
| 1330 |
_exercise_all_op_types(inst, 'default') |
| 1331 |
time.sleep(1) |
| 1332 |
assert not inst.ds_access_log.match(r'.*RESULT.*wbusy=.*') |
| 1333 |
|
| 1334 |
|
| 1335 |
def test_stat_thread_pool_runtime_toggle(thread_pool_log_setup): |
| 1336 |
"""Pool stats turn on with level=2 and back off with level=0 at runtime. |
| 1337 |
|
| 1338 |
:id: cd22210b-56d1-4ab1-83c2-1c560cd86494 |
| 1339 |
:setup: Standalone instance |
| 1340 |
:steps: |
| 1341 |
1. Runtime-set level=2 and exercise ops - RESULT lines carry pool stats |
| 1342 |
2. Runtime-set level=0, clear the access log, exercise ops again - |
| 1343 |
no RESULT line carries pool stats |
| 1344 |
:expectedresults: |
| 1345 |
1. Success |
| 1346 |
2. Success |
| 1347 |
""" |
| 1348 |
inst = thread_pool_log_setup |
| 1349 |
|
| 1350 |
inst.config.replace("nsslapd-statlog-level", "2") |
| 1351 |
_exercise_all_op_types(inst, 'on') |
| 1352 |
time.sleep(1) |
| 1353 |
assert inst.ds_access_log.match(r'.*RESULT.*wbusy=.*') |
| 1354 |
|
| 1355 |
inst.config.replace("nsslapd-statlog-level", "0") |
| 1356 |
inst.deleteAccessLogs(restart=True) |
| 1357 |
_exercise_all_op_types(inst, 'off') |
| 1358 |
time.sleep(1) |
| 1359 |
assert not inst.ds_access_log.match(r'.*RESULT.*wbusy=.*') |
| 1360 |
|
| 1361 |
|
| 1362 |
def test_stat_thread_pool_plain_text(thread_pool_log_setup): |
| 1363 |
"""Plain-text RESULT for every external op type carries pool stats. |
| 1364 |
|
| 1365 |
:id: 6c59a8cb-6bfa-4955-8fff-83bca66d4033 |
| 1366 |
:setup: Standalone instance, statlog-level=2, default (text) format |
| 1367 |
:steps: |
| 1368 |
1. Runtime-set level=2 |
| 1369 |
2. Exercise BIND/ADD/SEARCH/MOD/EXTOP/DEL |
| 1370 |
3. For each op tag a RESULT line contains wbusy=N/M wqdepth=N |
| 1371 |
:expectedresults: |
| 1372 |
1. Success |
| 1373 |
2. Success |
| 1374 |
3. Success |
| 1375 |
""" |
| 1376 |
inst = thread_pool_log_setup |
| 1377 |
inst.config.replace("nsslapd-statlog-level", "2") |
| 1378 |
_exercise_all_op_types(inst, 'plain') |
| 1379 |
time.sleep(1) |
| 1380 |
|
| 1381 |
for op_tag, op_name in THREAD_POOL_OP_TAGS.items(): |
| 1382 |
assert inst.ds_access_log.match( |
| 1383 |
rf'.*RESULT .* tag={op_tag} .*wbusy=[0-9]+/[0-9]+ ' |
| 1384 |
rf'wqdepth=[0-9]+.*'), \ |
| 1385 |
f"no plain-text RESULT with pool stats for {op_name} (tag={op_tag})" |
| 1386 |
|
| 1387 |
|
| 1388 |
def test_stat_thread_pool_json(thread_pool_log_setup): |
| 1389 |
"""JSON RESULT event for every external op type carries wbusy/wmax/wqdepth. |
| 1390 |
|
| 1391 |
:id: fb87f936-fdba-4f63-ae68-588396cd6086 |
| 1392 |
:setup: Standalone instance, statlog-level=2, JSON access log |
| 1393 |
:steps: |
| 1394 |
1. Runtime-switch access log format to JSON and set level=2 |
| 1395 |
2. Exercise all op types |
| 1396 |
3. Every op tag has a RESULT event with wbusy, wmax and wqdepth of |
| 1397 |
integer type and sane values |
| 1398 |
:expectedresults: |
| 1399 |
1. Success |
| 1400 |
2. Success |
| 1401 |
3. Success |
| 1402 |
""" |
| 1403 |
inst = thread_pool_log_setup |
| 1404 |
inst.config.replace("nsslapd-accesslog-log-format", "json") |
| 1405 |
inst.config.replace("nsslapd-statlog-level", "2") |
| 1406 |
_exercise_all_op_types(inst, 'json') |
| 1407 |
time.sleep(1) |
| 1408 |
|
| 1409 |
seen_tags = set() |
| 1410 |
json_log = DirsrvAccessJSONLog(inst) |
| 1411 |
for line in json_log.readlines(): |
| 1412 |
event = json_log.parse_line(line) |
| 1413 |
if event is None or 'header' in event: |
| 1414 |
continue |
| 1415 |
if event.get('operation') != 'RESULT': |
| 1416 |
continue |
| 1417 |
if 'wbusy' not in event: |
| 1418 |
continue |
| 1419 |
|
| 1420 |
assert 'wmax' in event |
| 1421 |
assert 'wqdepth' in event |
| 1422 |
assert isinstance(event['wbusy'], int) |
| 1423 |
assert isinstance(event['wmax'], int) |
| 1424 |
assert isinstance(event['wqdepth'], int) |
| 1425 |
assert event['wbusy'] >= 0 |
| 1426 |
assert event['wmax'] > 0 |
| 1427 |
assert event['wqdepth'] >= 0 |
| 1428 |
assert event['wbusy'] <= event['wmax'], \ |
| 1429 |
f"wbusy {event['wbusy']} exceeds wmax {event['wmax']}" |
| 1430 |
|
| 1431 |
tag = event.get('tag') |
| 1432 |
if isinstance(tag, int): |
| 1433 |
seen_tags.add(tag) |
| 1434 |
|
| 1435 |
for op_tag, op_name in THREAD_POOL_OP_TAGS.items(): |
| 1436 |
assert op_tag in seen_tags, \ |
| 1437 |
f"no JSON RESULT with wbusy/wmax/wqdepth for {op_name} (tag={op_tag})" |
| 1438 |
|
| 1439 |
|
| 1440 |
def test_stat_thread_pool_coexists_with_index(thread_pool_log_setup): |
| 1441 |
"""Level=3 emits both STAT index lines and RESULT pool stats. |
| 1442 |
|
| 1443 |
:id: 8b4f2e2d-5a3a-4b8f-a15d-6b8e6b19f0e3 |
| 1444 |
:setup: Standalone instance, statlog-level=3 |
| 1445 |
:steps: |
| 1446 |
1. Runtime-set level=3 |
| 1447 |
2. Exercise ops so index reads and RESULT lines are both produced |
| 1448 |
3. The log contains both STAT read index lines and RESULT pool stats |
| 1449 |
:expectedresults: |
| 1450 |
1. Success |
| 1451 |
2. Success |
| 1452 |
3. Success |
| 1453 |
""" |
| 1454 |
inst = thread_pool_log_setup |
| 1455 |
inst.config.replace("nsslapd-statlog-level", "3") |
| 1456 |
_exercise_all_op_types(inst, 'both') |
| 1457 |
time.sleep(1) |
| 1458 |
assert inst.ds_access_log.match(r'.*STAT read index.*') |
| 1459 |
assert inst.ds_access_log.match( |
| 1460 |
r'.*RESULT.*wbusy=[0-9]+/[0-9]+.*wqdepth=[0-9]+.*') |
| 1461 |
|
| 1462 |
|
| 1463 |
@pytest.mark.parametrize("value", ["0", "1", "2", "3", "255"]) |
| 1464 |
def test_statlog_level_accepts_valid(thread_pool_log_setup, value): |
| 1465 |
"""nsslapd-statlog-level accepts valid non-negative integer flag values. |
| 1466 |
|
| 1467 |
:id: 7a5dbcec-ab26-4bc0-9e5c-2651bd198a45 |
| 1468 |
:parametrized: yes |
| 1469 |
:setup: Standalone instance |
| 1470 |
:steps: |
| 1471 |
1. Replace nsslapd-statlog-level with the value |
| 1472 |
2. Re-read the attribute and confirm it matches |
| 1473 |
:expectedresults: |
| 1474 |
1. Success |
| 1475 |
2. Success |
| 1476 |
""" |
| 1477 |
inst = thread_pool_log_setup |
| 1478 |
inst.config.replace("nsslapd-statlog-level", value) |
| 1479 |
assert inst.config.get_attr_val_int("nsslapd-statlog-level") == int(value) |
| 1480 |
|
| 1481 |
|
| 1482 |
@pytest.mark.parametrize("bad", ["-1", "abc", "2abc", "9999999999999999999999"]) |
| 1483 |
def test_statlog_level_rejects_invalid(thread_pool_log_setup, bad): |
| 1484 |
"""nsslapd-statlog-level rejects non-numeric, negative, trailing-garbage |
| 1485 |
and overflow values, and the stored value is not changed. |
| 1486 |
|
| 1487 |
:id: 6722c48b-21d0-4f03-8501-b7f0d0aaef15 |
| 1488 |
:parametrized: yes |
| 1489 |
:setup: Standalone instance, statlog-level set to 2 |
| 1490 |
:steps: |
| 1491 |
1. Replace nsslapd-statlog-level with "2" (known-good baseline) |
| 1492 |
2. Attempt to replace with an invalid value |
| 1493 |
3. Confirm the value is still 2 |
| 1494 |
:expectedresults: |
| 1495 |
1. Success |
| 1496 |
2. ldap.OPERATIONS_ERROR is raised |
| 1497 |
3. Success |
| 1498 |
""" |
| 1499 |
inst = thread_pool_log_setup |
| 1500 |
inst.config.replace("nsslapd-statlog-level", "2") |
| 1501 |
with pytest.raises(ldap.OPERATIONS_ERROR): |
| 1502 |
inst.config.replace("nsslapd-statlog-level", bad) |
| 1503 |
assert inst.config.get_attr_val_int("nsslapd-statlog-level") == 2 |
| 1504 |
|
| 1505 |
|
| 1506 |
def test_statlog_level_reset_via_mod_delete(thread_pool_log_setup): |
| 1507 |
"""mod_delete of nsslapd-statlog-level resets the value to the default (0). |
| 1508 |
|
| 1509 |
:id: e0c32937-1adb-48a6-8c7c-92cd371c4146 |
| 1510 |
:setup: Standalone instance |
| 1511 |
:steps: |
| 1512 |
1. Set nsslapd-statlog-level to 2 |
| 1513 |
2. Issue a mod_delete on nsslapd-statlog-level |
| 1514 |
3. Confirm the value has been reset to 0 |
| 1515 |
4. Confirm RESULT lines no longer carry pool stats |
| 1516 |
:expectedresults: |
| 1517 |
1. Success |
| 1518 |
2. Success |
| 1519 |
3. Success |
| 1520 |
4. Success |
| 1521 |
""" |
| 1522 |
inst = thread_pool_log_setup |
| 1523 |
inst.config.replace("nsslapd-statlog-level", "2") |
| 1524 |
assert inst.config.get_attr_val_int("nsslapd-statlog-level") == 2 |
| 1525 |
|
| 1526 |
inst.config.remove_all("nsslapd-statlog-level") |
| 1527 |
assert inst.config.get_attr_val_int("nsslapd-statlog-level") == 0 |
| 1528 |
|
| 1529 |
inst.deleteAccessLogs(restart=True) |
| 1530 |
_exercise_all_op_types(inst, 'after_reset') |
| 1531 |
time.sleep(1) |
| 1532 |
assert not inst.ds_access_log.match(r'.*RESULT.*wbusy=.*') |
| 1533 |
|
| 1534 |
|
| 1535 |
def test_statlog_level_persists_across_restart(thread_pool_log_setup): |
| 1536 |
"""nsslapd-statlog-level survives a server restart and continues to |
| 1537 |
drive the thread-pool stat output. |
| 1538 |
|
| 1539 |
:id: 75f6ca47-7b6a-4509-a725-f61ebac9a777 |
| 1540 |
:setup: Standalone instance |
| 1541 |
:steps: |
| 1542 |
1. Set nsslapd-statlog-level to 2 and restart the server |
| 1543 |
2. Confirm the attribute is still 2 |
| 1544 |
3. Exercise ops and confirm RESULT lines still carry pool stats |
| 1545 |
:expectedresults: |
| 1546 |
1. Success |
| 1547 |
2. Success |
| 1548 |
3. Success |
| 1549 |
""" |
| 1550 |
inst = thread_pool_log_setup |
| 1551 |
inst.config.replace("nsslapd-statlog-level", "2") |
| 1552 |
inst.restart() |
| 1553 |
assert inst.config.get_attr_val_int("nsslapd-statlog-level") == 2 |
| 1554 |
|
| 1555 |
inst.deleteAccessLogs(restart=True) |
| 1556 |
_exercise_all_op_types(inst, 'restart') |
| 1557 |
time.sleep(1) |
| 1558 |
assert inst.ds_access_log.match( |
| 1559 |
r'.*RESULT.*wbusy=[0-9]+/[0-9]+.*wqdepth=[0-9]+.*') |
| 1560 |
|
| 1561 |
|
| 1562 |
def test_referral_check(topology_st, request): |
| 1563 |
"""Check that referral detection mechanism works |
| 1564 |
|
| 1565 |
:id: ff9b4247-d1fd-4edc-ba74-6ad61e65c0a4 |
| 1566 |
:setup: Standalone Instance |
| 1567 |
:steps: |
| 1568 |
1. Set nsslapd-referral-check-period=7 to accelerate test |
| 1569 |
2. Add a test entry |
| 1570 |
3. Remove error log file |
| 1571 |
4. Check that no referral entry exist |
| 1572 |
5. Create a referral entry |
| 1573 |
6. Check that the server detects the referral |
| 1574 |
7. Delete the referral entry |
| 1575 |
8. Check that the server detects the deletion of the referral |
| 1576 |
:expectedresults: |
| 1577 |
1. Success |
| 1578 |
2. Success |
| 1579 |
3. Success |
| 1580 |
4. Success |
| 1581 |
5. Success |
| 1582 |
6. Success |
| 1583 |
7. Success |
| 1584 |
8. Success |
| 1585 |
""" |
| 1586 |
|
| 1587 |
inst = topology_st.standalone |
| 1588 |
|
| 1589 |
# Step 1 reduce nsslapd-referral-check-period to accelerate test |
| 1590 |
REFERRAL_CHECK=7 |
| 1591 |
topology_st.standalone.config.set("nsslapd-referral-check-period", str(REFERRAL_CHECK)) |
| 1592 |
topology_st.standalone.restart() |
| 1593 |
|
| 1594 |
# Step 2 Add a test entry |
| 1595 |
users = UserAccounts(inst, DEFAULT_SUFFIX, rdn=None) |
| 1596 |
user = users.create(properties={'uid': 'test_1', |
| 1597 |
'cn': 'test_1', |
| 1598 |
'sn': 'test_1', |
| 1599 |
'description': 'member', |
| 1600 |
'uidNumber': '1000', |
| 1601 |
'gidNumber': '2000', |
| 1602 |
'homeDirectory': '/home/testuser'}) |
| 1603 |
|
| 1604 |
# Step 3 Remove error log file |
| 1605 |
topology_st.standalone.stop() |
| 1606 |
lpath = topology_st.standalone.ds_error_log._get_log_path() |
| 1607 |
os.unlink(lpath) |
| 1608 |
topology_st.standalone.start() |
| 1609 |
|
| 1610 |
# Step 4 Check that no referral entry is found (on regular deployment) |
| 1611 |
entries = topology_st.standalone.search_s(DEFAULT_SUFFIX, ldap.SCOPE_SUBTREE, "uid=test_1") |
| 1612 |
time.sleep(REFERRAL_CHECK + 1) |
| 1613 |
assert not topology_st.standalone.ds_error_log.match('.*slapd_daemon - New referral entries are detected.*') |
| 1614 |
|
| 1615 |
# Step 5 Create a referral entry |
| 1616 |
REFERRAL_DN = "cn=my_ref,%s" % DEFAULT_SUFFIX |
| 1617 |
properties = ({'cn': 'my_ref', |
| 1618 |
'uid': 'my_ref', |
| 1619 |
'sn': 'my_ref', |
| 1620 |
'uidNumber': '1000', |
| 1621 |
'gidNumber': '2000', |
| 1622 |
'homeDirectory': '/home/testuser', |
| 1623 |
'description': 'referral entry', |
| 1624 |
'objectclass': "top referral extensibleObject".split(), |
| 1625 |
'ref': 'ref: ldap://remote/%s' % REFERRAL_DN}) |
| 1626 |
referral = UserAccount(inst, REFERRAL_DN) |
| 1627 |
referral.create(properties=properties) |
| 1628 |
|
| 1629 |
# Step 6 Check that the server detected the referral |
| 1630 |
time.sleep(REFERRAL_CHECK + 1) |
| 1631 |
assert topology_st.standalone.ds_error_log.match('.*slapd_daemon - New referral entries are detected under %s.*' % DEFAULT_SUFFIX) |
| 1632 |
assert not topology_st.standalone.ds_error_log.match('.*slapd_daemon - No more referral entry under %s' % DEFAULT_SUFFIX) |
| 1633 |
|
| 1634 |
# Step 7 Delete the referral entry |
| 1635 |
referral.delete() |
| 1636 |
|
| 1637 |
# Step 8 Check that the server detected the deletion of the referral |
| 1638 |
time.sleep(REFERRAL_CHECK + 1) |
| 1639 |
assert topology_st.standalone.ds_error_log.match('.*slapd_daemon - No more referral entry under %s' % DEFAULT_SUFFIX) |
| 1640 |
|
| 1641 |
def fin(): |
| 1642 |
log.info('Deleting user/referral') |
| 1643 |
try: |
| 1644 |
user.delete() |
| 1645 |
referral.delete() |
| 1646 |
except: |
| 1647 |
pass |
| 1648 |
|
| 1649 |
request.addfinalizer(fin) |
| 1650 |
|
| 1651 |
|
| 1652 |
def test_missing_backend_suffix(topology_st, request): |
| 1653 |
"""Test that the server does not crash if a backend has no suffix |
| 1654 |
|
| 1655 |
:id: 427c9780-4875-4a94-a3e4-afa11be7d1a9 |
| 1656 |
:setup: Standalone instance |
| 1657 |
:steps: |
| 1658 |
1. Stop the instance |
| 1659 |
2. remove 'nsslapd-suffix' from the backend (userRoot) |
| 1660 |
3. start the instance |
| 1661 |
4. Check it started successfully with SRCH on rootDSE |
| 1662 |
:expectedresults: |
| 1663 |
all steps succeeds |
| 1664 |
""" |
| 1665 |
topology_st.standalone.stop() |
| 1666 |
dse_ldif = topology_st.standalone.confdir + '/dse.ldif' |
| 1667 |
shutil.copy(dse_ldif, dse_ldif + '.correct') |
| 1668 |
os.system('sed -e "/nsslapd-suffix/d" %s > %s' % (dse_ldif + '.correct', dse_ldif)) |
| 1669 |
topology_st.standalone.start() |
| 1670 |
rdse = RootDSE(topology_st.standalone) |
| 1671 |
|
| 1672 |
def fin(): |
| 1673 |
log.info('Restore dse.ldif') |
| 1674 |
topology_st.standalone.stop() |
| 1675 |
shutil.copy(dse_ldif + '.correct', dse_ldif) |
| 1676 |
topology_st.standalone.start() |
| 1677 |
|
| 1678 |
request.addfinalizer(fin) |
| 1679 |
|
| 1680 |
|
| 1681 |
def test_errorlog_buffering(topology_st, request): |
| 1682 |
"""Test log buffering works as expected when on or off |
| 1683 |
|
| 1684 |
:id: 324ec5ed-c8ec-49fe-ab20-8c8cbfedca41 |
| 1685 |
:setup: Standalone Instance |
| 1686 |
:steps: |
| 1687 |
1. Set buffering on |
| 1688 |
2. Reset logs and restart the server |
| 1689 |
3. Check for logging that should be buffered (not found) |
| 1690 |
4. Disable buffering |
| 1691 |
5. Reset logs and restart the server |
| 1692 |
6. Check for logging that should be found |
| 1693 |
:expectedresults: |
| 1694 |
1. Success |
| 1695 |
2. Success |
| 1696 |
3. Success |
| 1697 |
4. Success |
| 1698 |
5. Success |
| 1699 |
6. Success |
| 1700 |
""" |
| 1701 |
|
| 1702 |
# Configure instance |
| 1703 |
inst = topology_st.standalone |
| 1704 |
inst.config.replace('nsslapd-errorlog-logbuffering', 'on') |
| 1705 |
inst.deleteErrorLogs(restart=True) |
| 1706 |
|
| 1707 |
time.sleep(1) |
| 1708 |
assert not inst.ds_error_log.match(".*slapd_daemon - slapd started.*") |
| 1709 |
|
| 1710 |
inst.config.replace('nsslapd-errorlog-logbuffering', 'off') |
| 1711 |
inst.deleteErrorLogs(restart=True) |
| 1712 |
|
| 1713 |
time.sleep(1) |
| 1714 |
assert inst.ds_error_log.match(".*slapd_daemon - slapd started.*") |
| 1715 |
|
| 1716 |
|
| 1717 |
def test_no_repeated_disconnect_messages(topology_st): |
| 1718 |
"""Test that there are no repeated "Not setting conn 0 to be disconnected: socket is invalid" messages on restart |
| 1719 |
|
| 1720 |
:id: 72b5e1ce-2db8-458f-b2cd-0a0b6525f51f |
| 1721 |
:setup: Standalone Instance |
| 1722 |
:steps: |
| 1723 |
1. Set error log level to CONNECTION |
| 1724 |
2. Clear existing error logs |
| 1725 |
3. Restart the server with 30 second timeout |
| 1726 |
4. Check error log for repeated disconnect messages |
| 1727 |
5. Verify there are no more than 10 occurrences of the disconnect message |
| 1728 |
:expectedresults: |
| 1729 |
1. Error log level should be set successfully |
| 1730 |
2. Error logs should be cleared |
| 1731 |
3. Server should restart successfully within 30 seconds |
| 1732 |
4. Error log should be accessible |
| 1733 |
5. There should be no more than 10 repeated disconnect messages |
| 1734 |
""" |
| 1735 |
|
| 1736 |
inst = topology_st.standalone |
| 1737 |
|
| 1738 |
log.info('Set error log level to CONNECTION') |
| 1739 |
inst.config.loglevel([ErrorLog.CONNECT]) |
| 1740 |
current_level = inst.config.get_attr_val_int('nsslapd-errorlog-level') |
| 1741 |
log.info(f'Error log level set to: {current_level}') |
| 1742 |
|
| 1743 |
log.info('Clear existing error logs') |
| 1744 |
inst.deleteErrorLogs() |
| 1745 |
|
| 1746 |
log.info('Restart the server with 30 second timeout') |
| 1747 |
inst.restart(timeout=30) |
| 1748 |
|
| 1749 |
log.info('Check error log for repeated disconnect messages') |
| 1750 |
disconnect_message = "Not setting conn 0 to be disconnected: socket is invalid" |
| 1751 |
|
| 1752 |
# Count occurrences of the disconnect message |
| 1753 |
error_log_lines = inst.ds_error_log.readlines() |
| 1754 |
disconnect_count = 0 |
| 1755 |
|
| 1756 |
for line in error_log_lines: |
| 1757 |
if disconnect_message in line: |
| 1758 |
disconnect_count += 1 |
| 1759 |
|
| 1760 |
log.info(f'Found {disconnect_count} occurrences of disconnect message') |
| 1761 |
|
| 1762 |
log.info('Verify there are no more than 10 occurrences') |
| 1763 |
assert disconnect_count <= 10, f"Found {disconnect_count} repeated disconnect messages, expected <= 10" |
| 1764 |
|
| 1765 |
|
| 1766 |
if __name__ == '__main__': |
| 1767 |
# Run isolated |
| 1768 |
# -s for DEBUG mode |
| 1769 |
CURRENT_FILE = os.path.realpath(__file__) |
| 1770 |
pytest.main("-s %s" % CURRENT_FILE) |