| 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 |
|
| 10 |
import logging |
| 11 |
import pytest |
| 12 |
import os |
| 13 |
import ldap |
| 14 |
from lib389 import DirSrv, pid_from_file |
| 15 |
from lib389.dseldif import DSEldif |
| 16 |
from lib389.tasks import * |
| 17 |
from lib389.dbgen import dbgen_users |
| 18 |
from test389.topologies import topology_m2, topology_st as topo |
| 19 |
from lib389.utils import * |
| 20 |
from lib389._constants import DN_CONFIG, DEFAULT_SUFFIX, DEFAULT_BENAME, DN_DM, PW_DM |
| 21 |
from lib389._mapped_object import DSLdapObjects |
| 22 |
from lib389.agreement import Agreements |
| 23 |
from lib389.cli_base import FakeArgs |
| 24 |
from lib389.cli_conf.backend import db_config_set |
| 25 |
from lib389.idm.user import UserAccounts, TEST_USER_PROPERTIES |
| 26 |
from lib389.idm.group import Groups |
| 27 |
from lib389.instance.setup import SetupDs |
| 28 |
from lib389.config import LDBMConfig, BDB_LDBMConfig, Config |
| 29 |
from lib389.cos import CosPointerDefinitions, CosTemplates |
| 30 |
from lib389.backend import Backends, DatabaseConfig |
| 31 |
from lib389.monitor import MonitorLDBM, Monitor |
| 32 |
from lib389.plugins import ReferentialIntegrityPlugin |
| 33 |
from lib389.replica import BootstrapReplicationManager, Replicas |
| 34 |
from lib389.passwd import password_generate |
| 35 |
|
| 36 |
pytestmark = pytest.mark.tier0 |
| 37 |
|
| 38 |
USER_DN = 'uid=test_user,%s' % DEFAULT_SUFFIX |
| 39 |
PSTACK_CMD = '/usr/bin/pstack' |
| 40 |
|
| 41 |
logging.getLogger(__name__).setLevel(logging.INFO) |
| 42 |
log = logging.getLogger(__name__) |
| 43 |
|
| 44 |
DEBUGGING = os.getenv("DEBUGGING", default=False) |
| 45 |
|
| 46 |
@pytest.fixture(scope="module") |
| 47 |
def big_file(): |
| 48 |
TEMP_BIG_FILE = '' |
| 49 |
# 1024*1024=1048576 |
| 50 |
# B for 1 MiB |
| 51 |
# Big for 3 MiB |
| 52 |
for x in range(1048576): |
| 53 |
TEMP_BIG_FILE += '+' |
| 54 |
|
| 55 |
return TEMP_BIG_FILE |
| 56 |
|
| 57 |
|
| 58 |
@pytest.mark.skipif(ds_is_older('1.4.3.16'), reason="This config setting exists in 1.4.3.16 and higher") |
| 59 |
def test_nagle_default_value(topo): |
| 60 |
"""Test that nsslapd-nagle attribute is off by default |
| 61 |
|
| 62 |
:id: 00361f5d-d638-4d39-8231-66fa52637203 |
| 63 |
:setup: Standalone instance |
| 64 |
:steps: |
| 65 |
1. Create instance |
| 66 |
2. Check the value of nsslapd-nagle |
| 67 |
:expectedresults: |
| 68 |
1. Success |
| 69 |
2. The value of nsslapd-nagle should be off |
| 70 |
""" |
| 71 |
|
| 72 |
log.info('Check the value of nsslapd-nagle attribute is off by default') |
| 73 |
assert topo.standalone.config.get_attr_val_utf8('nsslapd-nagle') == 'off' |
| 74 |
|
| 75 |
|
| 76 |
# Same effective default and dse/ldap logic as the former ticket 48214 test |
| 77 |
_NSSLAPD_MAXBERSIZE_DEFAULT = 2097152 |
| 78 |
_MAXBERSIZE_DSE = 'nsslapd-maxbersize' |
| 79 |
|
| 80 |
|
| 81 |
def _dse_maxbersize_int(inst): |
| 82 |
"""Read nsslapd-maxbersize from dse.ldif. Return -1 if the attr is not present.""" |
| 83 |
dse = DSEldif(inst) |
| 84 |
val = dse.get(DN_CONFIG, _MAXBERSIZE_DSE, single=True, lower=True) |
| 85 |
if val is None: |
| 86 |
return -1 |
| 87 |
return int(val) |
| 88 |
|
| 89 |
|
| 90 |
def _check_max_ber_size(inst, defaultvalue): |
| 91 |
log.info('Check Max Ber Size (nsslapd-maxbersize)') |
| 92 |
dseval = _dse_maxbersize_int(inst) |
| 93 |
isdefault = True |
| 94 |
if dseval < 0: |
| 95 |
log.info('No nsslapd-maxbersize in dse.ldif') |
| 96 |
elif dseval == 0: |
| 97 |
log.info('nsslapd-maxbersize in dse: 0') |
| 98 |
else: |
| 99 |
isdefault = False |
| 100 |
log.info(f'nsslapd-maxbersize in dse: {dseval}') |
| 101 |
|
| 102 |
try: |
| 103 |
searchedsize = inst.config.get_attr_val_utf8('nsslapd-maxbersize') |
| 104 |
log.info(f'LDAP nsslapd-maxbersize: {searchedsize}') |
| 105 |
except ldap.LDAPError as e: |
| 106 |
log.error(f'Failed to get nsslapd-maxbersize from LDAP: {e}') |
| 107 |
assert False |
| 108 |
|
| 109 |
if isdefault: |
| 110 |
log.info(f'Assert effective default {searchedsize} vs {defaultvalue}') |
| 111 |
assert int(searchedsize) == defaultvalue |
| 112 |
|
| 113 |
|
| 114 |
def test_nsslapd_maxbersize_ldapread(topo): |
| 115 |
"""LDAP on cn=config exposes the effective nsslapd-maxbersize |
| 116 |
|
| 117 |
nsslapd-maxbersize in dse/ldap was reported as 0 instead of the in-effect value |
| 118 |
(e.g. 2097152 when not set, or 0/10000 when set). |
| 119 |
|
| 120 |
:id: 1d8275b2-c2dc-4fa5-ac99-6863144822ec |
| 121 |
:setup: Standalone instance |
| 122 |
:steps: |
| 123 |
1. Out of the box, compare dse.ldif vs LDAP |
| 124 |
2. Set nsslapd-maxbersize: 0, check again |
| 125 |
3. Set nsslapd-maxbersize: 10000, check dse and LDAP |
| 126 |
:expectedresults: |
| 127 |
1. When dse has no nsslapd-maxbersize, LDAP value is 2097152 |
| 128 |
2. When dse is 0, effective default still reported as 2097152 on LDAP |
| 129 |
3. When dse is 10000, the non-default code path is exercised (no 2097152 assert) |
| 130 |
""" |
| 131 |
inst = topo.standalone |
| 132 |
inst.simple_bind_s(DN_DM, PW_DM) |
| 133 |
|
| 134 |
orig_value = _dse_maxbersize_int(inst) |
| 135 |
|
| 136 |
try: |
| 137 |
log.info('Out of the box: nsslapd-maxbersize') |
| 138 |
_check_max_ber_size(inst, _NSSLAPD_MAXBERSIZE_DEFAULT) |
| 139 |
|
| 140 |
log.info('nsslapd-maxbersize: 0 in LDAP') |
| 141 |
inst.config.replace(_MAXBERSIZE_DSE, '0') |
| 142 |
_check_max_ber_size(inst, _NSSLAPD_MAXBERSIZE_DEFAULT) |
| 143 |
|
| 144 |
log.info('nsslapd-maxbersize: 10000 in LDAP') |
| 145 |
inst.config.replace(_MAXBERSIZE_DSE, '10000') |
| 146 |
_check_max_ber_size(inst, _NSSLAPD_MAXBERSIZE_DEFAULT) |
| 147 |
|
| 148 |
# return maxbersize to default value |
| 149 |
finally: |
| 150 |
try: |
| 151 |
inst.config.replace(_MAXBERSIZE_DSE, str(orig_value)) |
| 152 |
except Exception as e: |
| 153 |
log.error(f"Failed to return maxbersize to default value: {e}, replacing with 0") |
| 154 |
inst.config.replace(_MAXBERSIZE_DSE, '0') |
| 155 |
inst.restart() |
| 156 |
|
| 157 |
|
| 158 |
def test_maxbersize_repl(topology_m2, big_file): |
| 159 |
"""maxbersize is ignored in the replicated operations. |
| 160 |
|
| 161 |
:id: ad57de60-7d56-4323-bbca-5556e5cdb126 |
| 162 |
:setup: MMR with two suppliers, test user, |
| 163 |
1 MiB big value for any attribute |
| 164 |
:steps: |
| 165 |
1. Set maxbersize attribute to a small value (20KiB) on supplier2 |
| 166 |
2. Add the big value to supplier2 |
| 167 |
3. Add the big value to supplier1 |
| 168 |
4. Check if the big value was successfully replicated to supplier2 |
| 169 |
:expectedresults: |
| 170 |
1. maxbersize should be successfully set |
| 171 |
2. Adding the big value to supplier2 failed |
| 172 |
3. Adding the big value to supplier1 succeed |
| 173 |
4. The big value is successfully replicated to supplier2 |
| 174 |
""" |
| 175 |
|
| 176 |
users_m1 = UserAccounts(topology_m2.ms["supplier1"], DEFAULT_SUFFIX) |
| 177 |
users_m2 = UserAccounts(topology_m2.ms["supplier2"], DEFAULT_SUFFIX) |
| 178 |
|
| 179 |
user_m1 = users_m1.create(properties=TEST_USER_PROPERTIES) |
| 180 |
time.sleep(2) |
| 181 |
user_m2 = users_m2.get(dn=user_m1.dn) |
| 182 |
|
| 183 |
log.info("Set nsslapd-maxbersize: 20K to supplier2") |
| 184 |
topology_m2.ms["supplier2"].config.set('nsslapd-maxbersize', '20480') |
| 185 |
|
| 186 |
topology_m2.ms["supplier2"].restart() |
| 187 |
|
| 188 |
log.info('Try to add attribute with a big value to supplier2 - expect to FAIL') |
| 189 |
with pytest.raises(ldap.SERVER_DOWN): |
| 190 |
user_m2.add('jpegphoto', big_file) |
| 191 |
|
| 192 |
topology_m2.ms["supplier2"].restart() |
| 193 |
topology_m2.ms["supplier1"].restart() |
| 194 |
|
| 195 |
log.info('Try to add attribute with a big value to supplier1 - expect to PASS') |
| 196 |
user_m1.add('jpegphoto', big_file) |
| 197 |
|
| 198 |
time.sleep(2) |
| 199 |
|
| 200 |
log.info('Check if a big value was successfully added to supplier1') |
| 201 |
|
| 202 |
photo_m1 = user_m1.get_attr_vals('jpegphoto') |
| 203 |
|
| 204 |
log.info('Check if a big value was successfully replicated to supplier2') |
| 205 |
photo_m2 = user_m2.get_attr_vals('jpegphoto') |
| 206 |
nbtries = 0; |
| 207 |
while photo_m2 != photo_m1 and nbtries < 10: |
| 208 |
nbtries = nbtries + 1 |
| 209 |
photo_m2 = user_m2.get_attr_vals('jpegphoto') |
| 210 |
assert photo_m2 == photo_m1 |
| 211 |
|
| 212 |
def test_config_listen_backport_size(topology_m2): |
| 213 |
"""Check that nsslapd-listen-backlog-size acted as expected |
| 214 |
|
| 215 |
:id: a4385d58-a6ab-491e-a604-6df0e8ed91cd |
| 216 |
:setup: MMR with two suppliers |
| 217 |
:steps: |
| 218 |
1. Search for nsslapd-listen-backlog-size |
| 219 |
2. Set nsslapd-listen-backlog-size to a positive value |
| 220 |
3. Set nsslapd-listen-backlog-size to a negative value |
| 221 |
4. Set nsslapd-listen-backlog-size to an invalid value |
| 222 |
5. Set nsslapd-listen-backlog-size back to a default value |
| 223 |
:expectedresults: |
| 224 |
1. Search should be successful |
| 225 |
2. nsslapd-listen-backlog-size should be successfully set |
| 226 |
3. nsslapd-listen-backlog-size should be successfully set |
| 227 |
4. Modification with an invalid value should throw an error |
| 228 |
5. nsslapd-listen-backlog-size should be successfully set |
| 229 |
""" |
| 230 |
|
| 231 |
default_val = topology_m2.ms["supplier1"].config.get_attr_val_bytes('nsslapd-listen-backlog-size') |
| 232 |
|
| 233 |
topology_m2.ms["supplier1"].config.replace('nsslapd-listen-backlog-size', '256') |
| 234 |
|
| 235 |
topology_m2.ms["supplier1"].config.replace('nsslapd-listen-backlog-size', '-1') |
| 236 |
|
| 237 |
with pytest.raises(ldap.LDAPError): |
| 238 |
topology_m2.ms["supplier1"].config.replace('nsslapd-listen-backlog-size', 'ZZ') |
| 239 |
|
| 240 |
topology_m2.ms["supplier1"].config.replace('nsslapd-listen-backlog-size', default_val) |
| 241 |
|
| 242 |
|
| 243 |
@pytest.mark.skipif(get_default_db_lib() == "mdb", reason="Not supported over mdb") |
| 244 |
def test_config_deadlock_policy(topology_m2): |
| 245 |
"""Check that nsslapd-db-deadlock-policy acted as expected |
| 246 |
|
| 247 |
:id: a24e25fd-bc15-47fa-b018-372f6a2ec59c |
| 248 |
:setup: MMR with two suppliers |
| 249 |
:steps: |
| 250 |
1. Search for nsslapd-db-deadlock-policy and check if |
| 251 |
it contains a default value |
| 252 |
2. Set nsslapd-db-deadlock-policy to a positive value |
| 253 |
3. Set nsslapd-db-deadlock-policy to a negative value |
| 254 |
4. Set nsslapd-db-deadlock-policy to an invalid value |
| 255 |
5. Set nsslapd-db-deadlock-policy back to a default value |
| 256 |
:expectedresults: |
| 257 |
1. Search should be a successful and should contain a default value |
| 258 |
2. nsslapd-db-deadlock-policy should be successfully set |
| 259 |
3. nsslapd-db-deadlock-policy should be successfully set |
| 260 |
4. Modification with an invalid value should throw an error |
| 261 |
5. nsslapd-db-deadlock-policy should be successfully set |
| 262 |
""" |
| 263 |
|
| 264 |
default_val = b'9' |
| 265 |
|
| 266 |
ldbmconfig = LDBMConfig(topology_m2.ms["supplier1"]) |
| 267 |
bdbconfig = BDB_LDBMConfig(topology_m2.ms["supplier1"]) |
| 268 |
|
| 269 |
if ds_is_older('1.4.2'): |
| 270 |
deadlock_policy = ldbmconfig.get_attr_val_bytes('nsslapd-db-deadlock-policy') |
| 271 |
else: |
| 272 |
deadlock_policy = bdbconfig.get_attr_val_bytes('nsslapd-db-deadlock-policy') |
| 273 |
|
| 274 |
assert deadlock_policy == default_val |
| 275 |
|
| 276 |
# Try a range of valid values |
| 277 |
for val in (b'0', b'5', b'9'): |
| 278 |
ldbmconfig.replace('nsslapd-db-deadlock-policy', val) |
| 279 |
if ds_is_older('1.4.2'): |
| 280 |
deadlock_policy = ldbmconfig.get_attr_val_bytes('nsslapd-db-deadlock-policy') |
| 281 |
else: |
| 282 |
deadlock_policy = bdbconfig.get_attr_val_bytes('nsslapd-db-deadlock-policy') |
| 283 |
|
| 284 |
assert deadlock_policy == val |
| 285 |
|
| 286 |
# Try a range of invalid values |
| 287 |
for val in ('-1', '10'): |
| 288 |
with pytest.raises(ldap.LDAPError): |
| 289 |
ldbmconfig.replace('nsslapd-db-deadlock-policy', val) |
| 290 |
|
| 291 |
# Cleanup - undo what we've done |
| 292 |
ldbmconfig.replace('nsslapd-db-deadlock-policy', deadlock_policy) |
| 293 |
|
| 294 |
|
| 295 |
def test_defaultnamingcontext(topo): |
| 296 |
"""Tests configuration attribute defaultNamingContext in the rootdse |
| 297 |
|
| 298 |
:id: de9a21d3-00f9-4c6d-bb40-56aa1ba36578 |
| 299 |
:setup: Standalone instance |
| 300 |
:steps: |
| 301 |
1. Check the attribute nsslapd-defaultnamingcontext is present in cn=config |
| 302 |
2. Delete nsslapd-defaultnamingcontext attribute |
| 303 |
3. Add new valid Suffix and modify nsslapd-defaultnamingcontext with new suffix |
| 304 |
4. Add new invalid value at runtime to nsslapd-defaultnamingcontext |
| 305 |
5. Modify nsslapd-defaultnamingcontext with blank value |
| 306 |
6. Add new suffix when nsslapd-defaultnamingcontext is empty |
| 307 |
7. Check the value of the nsslapd-defaultnamingcontext automatically have the new suffix |
| 308 |
8. Adding new suffix when nsslapd-defaultnamingcontext is not empty |
| 309 |
9. Check the value of the nsslapd-defaultnamingcontext has not changed |
| 310 |
10. Remove the newly added suffix and check the values of the attribute is not changed |
| 311 |
11. Remove the original suffix which is currently nsslapd-defaultnamingcontext |
| 312 |
12. Check nsslapd-defaultnamingcontext become empty. |
| 313 |
:expectedresults: |
| 314 |
1. This should be successful |
| 315 |
2. It should give 'server unwilling to perform' error |
| 316 |
3. It should be successful |
| 317 |
4. It should give 'no such object' error |
| 318 |
5. It should be successful |
| 319 |
6. Add should be successful |
| 320 |
7. nsslapd-defaultnamingcontext should have new suffix |
| 321 |
8. Add should be successful |
| 322 |
9. defaultnamingcontext should not change |
| 323 |
10. Remove should be successful and defaultnamingcontext should not change |
| 324 |
11. Removal should be successful |
| 325 |
12. nsslapd-defaultnamingcontext should be empty |
| 326 |
""" |
| 327 |
|
| 328 |
backends = Backends(topo.standalone) |
| 329 |
test_suffix1 = 'dc=test1,dc=com' |
| 330 |
test_db1 = 'test1_db' |
| 331 |
test_suffix2 = 'dc=test2,dc=com' |
| 332 |
test_db2 = 'test2_db' |
| 333 |
test_suffix3 = 'dc=test3,dc=com' |
| 334 |
test_db3 = 'test3_db' |
| 335 |
|
| 336 |
log.info("Check the attribute nsslapd-defaultnamingcontext is present in cn=config") |
| 337 |
assert topo.standalone.config.present('nsslapd-defaultnamingcontext') |
| 338 |
|
| 339 |
log.info("Delete nsslapd-defaultnamingcontext attribute") |
| 340 |
with pytest.raises(ldap.UNWILLING_TO_PERFORM): |
| 341 |
topo.standalone.config.remove_all('nsslapd-defaultnamingcontext') |
| 342 |
|
| 343 |
b1 = backends.create(properties={'cn': test_db1, |
| 344 |
'nsslapd-suffix': test_suffix1}) |
| 345 |
|
| 346 |
log.info("modify nsslapd-defaultnamingcontext with new suffix") |
| 347 |
topo.standalone.config.replace('nsslapd-defaultnamingcontext', test_suffix1) |
| 348 |
|
| 349 |
log.info("Add new invalid value at runtime to nsslapd-defaultnamingcontext") |
| 350 |
with pytest.raises(ldap.NO_SUCH_OBJECT): |
| 351 |
topo.standalone.config.replace('nsslapd-defaultnamingcontext', 'some_invalid_value') |
| 352 |
|
| 353 |
log.info("Modify nsslapd-defaultnamingcontext with blank value") |
| 354 |
topo.standalone.config.replace('nsslapd-defaultnamingcontext', ' ') |
| 355 |
|
| 356 |
log.info("Add new suffix when nsslapd-defaultnamingcontext is empty") |
| 357 |
b2 = backends.create(properties={'cn': test_db2, |
| 358 |
'nsslapd-suffix': test_suffix2}) |
| 359 |
|
| 360 |
log.info("Check the value of the nsslapd-defaultnamingcontext automatically have the new suffix") |
| 361 |
assert topo.standalone.config.get_attr_val_utf8('nsslapd-defaultnamingcontext') == test_suffix2 |
| 362 |
|
| 363 |
log.info("Adding new suffix when nsslapd-defaultnamingcontext is not empty") |
| 364 |
b3 = backends.create(properties={'cn': test_db3, |
| 365 |
'nsslapd-suffix': test_suffix3}) |
| 366 |
|
| 367 |
log.info("Check the value of the nsslapd-defaultnamingcontext has not changed") |
| 368 |
assert topo.standalone.config.get_attr_val_utf8('nsslapd-defaultnamingcontext') == test_suffix2 |
| 369 |
|
| 370 |
log.info("Remove the newly added suffix and check the values of the attribute is not changed") |
| 371 |
b3.delete() |
| 372 |
assert topo.standalone.config.get_attr_val_utf8('nsslapd-defaultnamingcontext') == test_suffix2 |
| 373 |
|
| 374 |
log.info("Remove all the suffix at the end") |
| 375 |
b1.delete() |
| 376 |
b2.delete() |
| 377 |
|
| 378 |
|
| 379 |
def test_allow_add_delete_config_attributes(topo): |
| 380 |
"""Tests configuration attributes are allowed to add and delete |
| 381 |
|
| 382 |
:id: d9a3f264-4111-406b-9900-a70e5403458a |
| 383 |
:setup: Standalone instance |
| 384 |
:steps: |
| 385 |
1. Add a new valid attribute at runtime to cn=config |
| 386 |
2. Check if the new valid attribute is present |
| 387 |
3. Delete nsslapd-listenhost to restore the default value |
| 388 |
4. Restart the server |
| 389 |
5. Check nsslapd-listenhost is present with default value |
| 390 |
6. Add new invalid attribute at runtime to cn=config |
| 391 |
7. Make sure the invalid attribute is not added |
| 392 |
:expectedresults: |
| 393 |
1. This should be successful |
| 394 |
2. This should be successful |
| 395 |
3. This should be successful |
| 396 |
4. This should be successful |
| 397 |
5. This should be successful |
| 398 |
6. It should give 'server unwilling to perform' error |
| 399 |
7. Invalid attribute should not be added |
| 400 |
""" |
| 401 |
default_listenhost = topo.standalone.config.get_attr_val_utf8('nsslapd-listenhost') |
| 402 |
|
| 403 |
log.info("Add a new valid attribute at runtime to cn=config") |
| 404 |
topo.standalone.config.add('nsslapd-listenhost', 'localhost') |
| 405 |
assert topo.standalone.config.present('nsslapd-listenhost', 'localhost') |
| 406 |
|
| 407 |
log.info("Delete nsslapd-listenhost to restore the default value") |
| 408 |
topo.standalone.config.remove('nsslapd-listenhost', 'localhost') |
| 409 |
topo.standalone.restart() |
| 410 |
assert topo.standalone.config.present('nsslapd-listenhost', default_listenhost) |
| 411 |
|
| 412 |
log.info("Add new invalid attribute at runtime to cn=config") |
| 413 |
with pytest.raises(ldap.UNWILLING_TO_PERFORM): |
| 414 |
topo.standalone.config.add('invalid-attribute', 'invalid-value') |
| 415 |
|
| 416 |
log.info("Make sure the invalid attribute is not added") |
| 417 |
assert not topo.standalone.config.present('invalid-attribute', 'invalid-value') |
| 418 |
|
| 419 |
|
| 420 |
def test_ignore_virtual_attrs(topo): |
| 421 |
"""Test nsslapd-ignore-virtual-attrs configuration attribute |
| 422 |
|
| 423 |
:id: 9915d71b-2c71-4ac0-91d7-92655d53541b |
| 424 |
:customerscenario: True |
| 425 |
:setup: Standalone instance |
| 426 |
:steps: |
| 427 |
1. Check the attribute nsslapd-ignore-virtual-attrs is present in cn=config |
| 428 |
2. Check the default value of attribute nsslapd-ignore-virtual-attrs should be ON |
| 429 |
3. Set the valid values i.e. on/ON and off/OFF for nsslapd-ignore-virtual-attrs |
| 430 |
4. Set invalid value for attribute nsslapd-ignore-virtual-attrs |
| 431 |
5. Set nsslapd-ignore-virtual-attrs=off |
| 432 |
6. Add cosPointer, cosTemplate and test entry to default suffix, where virtual attribute is postal code |
| 433 |
7. Test if virtual attribute i.e. postal code shown in test entry while nsslapd-ignore-virtual-attrs: off |
| 434 |
8. Set nsslapd-ignore-virtual-attrs=on |
| 435 |
9. Test if virtual attribute i.e. postal code not shown while nsslapd-ignore-virtual-attrs: on |
| 436 |
:expectedresults: |
| 437 |
1. This should be successful |
| 438 |
2. This should be successful |
| 439 |
3. This should be successful |
| 440 |
4. This should fail |
| 441 |
5. This should be successful |
| 442 |
6. This should be successful |
| 443 |
7. Postal code should be present |
| 444 |
8. This should be successful |
| 445 |
9. Postal code should not be present |
| 446 |
""" |
| 447 |
|
| 448 |
log.info("Check the attribute nsslapd-ignore-virtual-attrs is present in cn=config") |
| 449 |
assert topo.standalone.config.present('nsslapd-ignore-virtual-attrs') |
| 450 |
|
| 451 |
log.info("Check the default value of attribute nsslapd-ignore-virtual-attrs should be ON") |
| 452 |
assert topo.standalone.config.get_attr_val_utf8('nsslapd-ignore-virtual-attrs') == "on" |
| 453 |
|
| 454 |
log.info("Set the valid values i.e. on/ON and off/OFF for nsslapd-ignore-virtual-attrs") |
| 455 |
for attribute_value in ['on', 'off', 'ON', 'OFF']: |
| 456 |
topo.standalone.config.set('nsslapd-ignore-virtual-attrs', attribute_value) |
| 457 |
assert topo.standalone.config.present('nsslapd-ignore-virtual-attrs', attribute_value) |
| 458 |
|
| 459 |
log.info("Set invalid value for attribute nsslapd-ignore-virtual-attrs") |
| 460 |
with pytest.raises(ldap.OPERATIONS_ERROR): |
| 461 |
topo.standalone.config.set('nsslapd-ignore-virtual-attrs', 'invalid_value') |
| 462 |
|
| 463 |
cos_template_properties = { |
| 464 |
'cn': 'cosTemplateExample', |
| 465 |
'postalcode': '117' |
| 466 |
} |
| 467 |
cos_templates = CosTemplates(topo.standalone, DEFAULT_SUFFIX, 'ou=People') |
| 468 |
test_cos_template = cos_templates.create(properties=cos_template_properties) |
| 469 |
|
| 470 |
log.info("Add cosPointer, cosTemplate and test entry to default suffix, where virtual attribute is postal code") |
| 471 |
cos_pointer_properties = { |
| 472 |
'cn': 'cosPointer', |
| 473 |
'description': 'cosPointer example', |
| 474 |
'cosTemplateDn': 'cn=cosTemplateExample,ou=People,dc=example,dc=com', |
| 475 |
'cosAttribute': 'postalcode', |
| 476 |
} |
| 477 |
cos_pointer_definitions = CosPointerDefinitions(topo.standalone, DEFAULT_SUFFIX, 'ou=People') |
| 478 |
test_cos_pointer_definition = cos_pointer_definitions.create(properties=cos_pointer_properties) |
| 479 |
|
| 480 |
test_users = UserAccounts(topo.standalone, DEFAULT_SUFFIX) |
| 481 |
test_user = test_users.create(properties=TEST_USER_PROPERTIES) |
| 482 |
|
| 483 |
log.info("Test if virtual attribute i.e. postal code shown in test entry while nsslapd-ignore-virtual-attrs: off") |
| 484 |
assert test_user.present('postalcode', '117') |
| 485 |
|
| 486 |
log.info("Set nsslapd-ignore-virtual-attrs=on") |
| 487 |
topo.standalone.config.set('nsslapd-ignore-virtual-attrs', 'on') |
| 488 |
|
| 489 |
log.info("Test if virtual attribute i.e. postal code not shown while nsslapd-ignore-virtual-attrs: on") |
| 490 |
assert not test_user.present('postalcode', '117') |
| 491 |
|
| 492 |
def test_ignore_virtual_attrs_after_restart(topo): |
| 493 |
"""Test nsslapd-ignore-virtual-attrs configuration attribute |
| 494 |
The attribute is ON by default. If it set to OFF, it keeps |
| 495 |
its value on restart |
| 496 |
|
| 497 |
:id: ac368649-4fda-473c-9ef8-e0c728b162af |
| 498 |
:customerscenario: True |
| 499 |
:setup: Standalone instance |
| 500 |
:steps: |
| 501 |
1. Check the attribute nsslapd-ignore-virtual-attrs is present in cn=config |
| 502 |
2. Check the default value of attribute nsslapd-ignore-virtual-attrs should be ON |
| 503 |
3. Set nsslapd-ignore-virtual-attrs=off |
| 504 |
4. restart the instance |
| 505 |
5. Check the attribute nsslapd-ignore-virtual-attrs is OFF |
| 506 |
:expectedresults: |
| 507 |
1. This should be successful |
| 508 |
2. This should be successful |
| 509 |
3. This should be successful |
| 510 |
4. This should be successful |
| 511 |
5. This should be successful |
| 512 |
""" |
| 513 |
|
| 514 |
log.info("Check the attribute nsslapd-ignore-virtual-attrs is present in cn=config") |
| 515 |
assert topo.standalone.config.present('nsslapd-ignore-virtual-attrs') |
| 516 |
|
| 517 |
log.info("Check the default value of attribute nsslapd-ignore-virtual-attrs should be ON") |
| 518 |
assert topo.standalone.config.get_attr_val_utf8('nsslapd-ignore-virtual-attrs') == "on" |
| 519 |
|
| 520 |
log.info("Set nsslapd-ignore-virtual-attrs = off") |
| 521 |
topo.standalone.config.set('nsslapd-ignore-virtual-attrs', 'off') |
| 522 |
|
| 523 |
topo.standalone.restart() |
| 524 |
|
| 525 |
log.info("Check the default value of attribute nsslapd-ignore-virtual-attrs should be OFF") |
| 526 |
assert topo.standalone.config.present('nsslapd-ignore-virtual-attrs', 'off') |
| 527 |
|
| 528 |
def test_ndn_cache_enabled(topo): |
| 529 |
"""Check the behavior of the Normalized DN cache when enabled/disabled |
| 530 |
|
| 531 |
:id: 2caa3ec0-cd05-458e-9e21-3b73cf4697ff |
| 532 |
:setup: Standalone instance |
| 533 |
:steps: |
| 534 |
1. Check the attribute nsslapd-ndn-cache-enabled is present in cn=config |
| 535 |
2. Check the attribute nsslapd-ndn-cache-enabled has the default value set as ON |
| 536 |
3. Check the attribute nsslapd-ndn-cache-max-size is present in cn=config |
| 537 |
4. Check the backend monitor output for Normalized DN cache statistics while nsslapd-ndn-cache-enabled is OFF |
| 538 |
5. Set nsslapd-ndn-cache-enabled ON and check the backend monitor output for Normalized DN cache statistics |
| 539 |
6. Set invalid value for nsslapd-ndn-cache-enabled |
| 540 |
7. Set invalid value for nsslapd-ndn-cache-max-size |
| 541 |
:expectedresults: |
| 542 |
1. This should be successful |
| 543 |
2. This should be successful |
| 544 |
3. This should be successful |
| 545 |
4. Backend monitor output should not have NDN cache statistics |
| 546 |
5. Backend monitor output should have NDN cache statistics |
| 547 |
6. This should fail |
| 548 |
7. This should fail |
| 549 |
""" |
| 550 |
log.info("Check the attribute nsslapd-ndn-cache-enabled is present in cn=config") |
| 551 |
assert topo.standalone.config.present('nsslapd-ndn-cache-enabled') |
| 552 |
|
| 553 |
log.info("Check the attribute nsslapd-ndn-cache-enabled has the default value set as ON") |
| 554 |
assert topo.standalone.config.get_attr_val_utf8('nsslapd-ndn-cache-enabled') == 'on' |
| 555 |
|
| 556 |
log.info("Check the attribute nsslapd-ndn-cache-max-size is present in cn=config") |
| 557 |
assert topo.standalone.config.present('nsslapd-ndn-cache-max-size') |
| 558 |
|
| 559 |
backends = Backends(topo.standalone) |
| 560 |
backend = backends.get(DEFAULT_BENAME) |
| 561 |
|
| 562 |
log.info("Ticket#49593 : NDN cache stats should be under the global stats - Implemented in 1.4") |
| 563 |
log.info("Fetch the monitor value according to the ds version") |
| 564 |
if ds_is_older('1.4'): |
| 565 |
monitor = backend.get_monitor() |
| 566 |
else: |
| 567 |
monitor = MonitorLDBM(topo.standalone) |
| 568 |
|
| 569 |
log.info("Check the backend monitor output for Normalized DN cache statistics, " |
| 570 |
"while nsslapd-ndn-cache-enabled is off") |
| 571 |
topo.standalone.config.set('nsslapd-ndn-cache-enabled', 'off') |
| 572 |
topo.standalone.restart() |
| 573 |
assert not monitor.present('normalizedDnCacheHits') |
| 574 |
|
| 575 |
log.info("Check the backend monitor output for Normalized DN cache statistics, " |
| 576 |
"while nsslapd-ndn-cache-enabled is on") |
| 577 |
topo.standalone.config.set('nsslapd-ndn-cache-enabled', 'on') |
| 578 |
topo.standalone.restart() |
| 579 |
assert monitor.present('normalizedDnCacheHits') |
| 580 |
|
| 581 |
log.info("Set invalid value for nsslapd-ndn-cache-enabled") |
| 582 |
with pytest.raises(ldap.OPERATIONS_ERROR): |
| 583 |
topo.standalone.config.set('nsslapd-ndn-cache-enabled', 'invalid_value') |
| 584 |
|
| 585 |
log.info("Set invalid value for nsslapd-ndn-cache-max-size") |
| 586 |
with pytest.raises(ldap.OPERATIONS_ERROR): |
| 587 |
topo.standalone.config.set('nsslapd-ndn-cache-max-size', 'invalid_value') |
| 588 |
|
| 589 |
def test_ndn_cache_max_size(topo): |
| 590 |
"""Test that nsslapd-ndn-cache-max-size correctly sets the cache size |
| 591 |
|
| 592 |
:id: 1618cf36-5979-4826-9995-be0019d64818 |
| 593 |
:setup: Standalone instance |
| 594 |
:steps: |
| 595 |
1. Set cache to 10MB |
| 596 |
2. Verify reported size accounts for entry-based rounding |
| 597 |
3. Populate cache with searches |
| 598 |
4. Verify size doesn't exceed limit |
| 599 |
5. Change to 50MB |
| 600 |
6. Verify new limit is respected |
| 601 |
7. Test minimum value enforcement (1MB) |
| 602 |
:expectedresults: |
| 603 |
1. This should be successful |
| 604 |
2. This should be successful |
| 605 |
3. This should be successful |
| 606 |
4. This should be successful |
| 607 |
5. This should be successful |
| 608 |
6. This should be successful |
| 609 |
7. This should be successful |
| 610 |
""" |
| 611 |
inst = topo.standalone |
| 612 |
config = inst.config |
| 613 |
monitor = MonitorLDBM(inst) |
| 614 |
|
| 615 |
NDN_ENTRY_AVG_SIZE = 168 |
| 616 |
|
| 617 |
log.info("Saving original cache config and enabling cache") |
| 618 |
original_size = config.get_attr_val_utf8('nsslapd-ndn-cache-max-size') |
| 619 |
config.set('nsslapd-ndn-cache-enabled', 'on') |
| 620 |
|
| 621 |
log.info("Setting cache to 10MB") |
| 622 |
config.set('nsslapd-ndn-cache-max-size', '10485760') |
| 623 |
inst.restart() |
| 624 |
|
| 625 |
max_size = int(monitor.get_attr_val_utf8('maxNormalizedDnCacheSize')) |
| 626 |
expected = (10485760 // NDN_ENTRY_AVG_SIZE) * NDN_ENTRY_AVG_SIZE |
| 627 |
log.info(f"Cache max size: {max_size} bytes (expected {expected})") |
| 628 |
assert max_size == expected |
| 629 |
|
| 630 |
log.info("Creating test users and performing searches") |
| 631 |
users = UserAccounts(inst, DEFAULT_SUFFIX) |
| 632 |
test_users = [users.create_test_user(uid=1000 + i) for i in range(20)] |
| 633 |
for user in test_users: |
| 634 |
try: |
| 635 |
user.get_attr_val_utf8('uid') |
| 636 |
except: |
| 637 |
pass |
| 638 |
|
| 639 |
if monitor.present('currentNormalizedDnCacheSize'): |
| 640 |
current = int(monitor.get_attr_val_utf8('currentNormalizedDnCacheSize')) |
| 641 |
log.info(f"Current cache size: {current} bytes (max: {max_size})") |
| 642 |
assert current <= max_size |
| 643 |
|
| 644 |
log.info("Setting cache to 50MB") |
| 645 |
config.set('nsslapd-ndn-cache-max-size', '52428800') |
| 646 |
inst.restart() |
| 647 |
max_size = int(monitor.get_attr_val_utf8('maxNormalizedDnCacheSize')) |
| 648 |
expected = (52428800 // NDN_ENTRY_AVG_SIZE) * NDN_ENTRY_AVG_SIZE |
| 649 |
log.info(f"New cache max size: {max_size} bytes (expected {expected})") |
| 650 |
assert max_size == expected |
| 651 |
|
| 652 |
log.info("Testing minimum value enforcement (setting to 500KB)") |
| 653 |
config.set('nsslapd-ndn-cache-max-size', '500000') |
| 654 |
inst.restart() |
| 655 |
adjusted = int(monitor.get_attr_val_utf8('maxNormalizedDnCacheSize')) |
| 656 |
min_expected = (1048576 // NDN_ENTRY_AVG_SIZE) * NDN_ENTRY_AVG_SIZE |
| 657 |
log.info(f"Adjusted cache size: {adjusted} bytes (min expected: {min_expected})") |
| 658 |
assert adjusted >= min_expected |
| 659 |
|
| 660 |
log.info("Restoring original cache config") |
| 661 |
config.set('nsslapd-ndn-cache-max-size', original_size) |
| 662 |
inst.restart() |
| 663 |
for user in test_users: |
| 664 |
try: |
| 665 |
user.delete() |
| 666 |
except: |
| 667 |
pass |
| 668 |
|
| 669 |
def test_ndn_cache_size_enforcement(topo, request): |
| 670 |
"""Test that nsslapd-ndn-cache-max-size actually enforces the cache size |
| 671 |
|
| 672 |
:id: 08cdcce2-82e2-4f32-b083-e18bbddd06e2 |
| 673 |
:setup: Standalone instance |
| 674 |
:steps: |
| 675 |
1. Set small cache (2MB) |
| 676 |
2. Import many entries |
| 677 |
3. Verify evictions occur |
| 678 |
4. Increase to large cache (200MB) |
| 679 |
5. Verify more entries fit |
| 680 |
:expectedresults: |
| 681 |
1. This should be successful |
| 682 |
2. This should be successful |
| 683 |
3. This should be successful |
| 684 |
4. This should be successful |
| 685 |
5. This should be successful |
| 686 |
""" |
| 687 |
inst = topo.standalone |
| 688 |
config = inst.config |
| 689 |
monitor = MonitorLDBM(inst) |
| 690 |
|
| 691 |
NDN_ENTRY_AVG_SIZE = 168 |
| 692 |
TEST_CACHE_SIZE = 2097152 # 2MB |
| 693 |
|
| 694 |
log.info("Setting up small cache (2MB)") |
| 695 |
original_size = config.get_attr_val_utf8('nsslapd-ndn-cache-max-size') |
| 696 |
config.set('nsslapd-ndn-cache-enabled', 'on') |
| 697 |
config.set('nsslapd-ndn-cache-max-size', str(TEST_CACHE_SIZE)) |
| 698 |
inst.restart() |
| 699 |
|
| 700 |
max_size = int(monitor.get_attr_val_utf8('maxNormalizedDnCacheSize')) |
| 701 |
entry_capacity = max_size // NDN_ENTRY_AVG_SIZE |
| 702 |
expected = (TEST_CACHE_SIZE // NDN_ENTRY_AVG_SIZE) * NDN_ENTRY_AVG_SIZE |
| 703 |
log.info(f"Cache capacity: {entry_capacity} entries ({max_size} bytes)") |
| 704 |
assert max_size == expected |
| 705 |
|
| 706 |
# Generate and import entries (capacity + 1000) |
| 707 |
num_users = entry_capacity + 1000 |
| 708 |
log.info(f"Generating {num_users} test users (cache capacity + 1000)") |
| 709 |
ldif_dir = inst.get_ldif_dir() |
| 710 |
import_ldif = os.path.join(ldif_dir, 'ndn_cache_test.ldif') |
| 711 |
RDN = "ndnTestUser" |
| 712 |
PARENT = f"ou=people,{DEFAULT_SUFFIX}" |
| 713 |
|
| 714 |
dbgen_users(inst, num_users, import_ldif, DEFAULT_SUFFIX, entry_name=RDN, generic=True, parent=PARENT) |
| 715 |
|
| 716 |
log.info("Importing LDIF") |
| 717 |
import_task = ImportTask(inst) |
| 718 |
import_task.import_suffix_from_ldif(ldiffile=import_ldif, suffix=DEFAULT_SUFFIX) |
| 719 |
import_task.wait(timeout=400) |
| 720 |
assert import_task.get_exit_code() == 0 |
| 721 |
inst.restart() |
| 722 |
|
| 723 |
log.info("Performing searches to fill cache") |
| 724 |
entries = inst.search_s(PARENT, ldap.SCOPE_SUBTREE, f"(uid={RDN}*)") |
| 725 |
log.info(f"Found {len(entries)} entries, performing individual DN searches") |
| 726 |
|
| 727 |
for i in range(1, min(num_users, entry_capacity * 2) + 1): |
| 728 |
dn = f"uid={RDN}{str(i).zfill(len(str(num_users)))},{PARENT}" |
| 729 |
try: |
| 730 |
inst.search_s(dn, ldap.SCOPE_BASE, '(objectclass=*)', ['uid']) |
| 731 |
except ldap.NO_SUCH_OBJECT: |
| 732 |
pass |
| 733 |
|
| 734 |
time.sleep(2) |
| 735 |
|
| 736 |
current_count = int(monitor.get_attr_val_utf8('currentNormalizedDnCacheCount')) |
| 737 |
current_size = int(monitor.get_attr_val_utf8('currentNormalizedDnCacheSize')) |
| 738 |
evictions = int(monitor.get_attr_val_utf8('normalizedDnCacheEvictions')) if monitor.present('normalizedDnCacheEvictions') else 0 |
| 739 |
|
| 740 |
log.info(f"Small cache stats: {current_count}/{entry_capacity} entries, {evictions} evictions") |
| 741 |
assert current_count <= entry_capacity |
| 742 |
assert current_size <= max_size |
| 743 |
assert current_size == current_count * NDN_ENTRY_AVG_SIZE |
| 744 |
assert evictions > 0, "Cache should have evicted entries" |
| 745 |
|
| 746 |
small_cache_count = current_count |
| 747 |
|
| 748 |
log.info("Increasing cache to 200MB") |
| 749 |
LARGE_CACHE_SIZE = TEST_CACHE_SIZE * 100 |
| 750 |
config.set('nsslapd-ndn-cache-max-size', str(LARGE_CACHE_SIZE)) |
| 751 |
inst.restart() |
| 752 |
|
| 753 |
large_max_size = int(monitor.get_attr_val_utf8('maxNormalizedDnCacheSize')) |
| 754 |
large_capacity = large_max_size // NDN_ENTRY_AVG_SIZE |
| 755 |
log.info(f"Large cache capacity: {large_capacity} entries") |
| 756 |
assert large_capacity > entry_capacity |
| 757 |
|
| 758 |
log.info("Searching all entries with large cache") |
| 759 |
for i in range(1, num_users + 1): |
| 760 |
dn = f"uid={RDN}{str(i).zfill(len(str(num_users)))},{PARENT}" |
| 761 |
try: |
| 762 |
inst.search_s(dn, ldap.SCOPE_BASE, '(objectclass=*)', ['uid']) |
| 763 |
except ldap.NO_SUCH_OBJECT: |
| 764 |
pass |
| 765 |
|
| 766 |
time.sleep(2) |
| 767 |
|
| 768 |
large_count = int(monitor.get_attr_val_utf8('currentNormalizedDnCacheCount')) |
| 769 |
large_size = int(monitor.get_attr_val_utf8('currentNormalizedDnCacheSize')) |
| 770 |
log.info(f"Large cache stats: {large_count}/{large_capacity} entries (small cache had {small_cache_count})") |
| 771 |
|
| 772 |
assert large_count <= large_capacity |
| 773 |
assert large_size <= large_max_size |
| 774 |
assert large_count >= small_cache_count |
| 775 |
|
| 776 |
log.info("Restoring original cache config") |
| 777 |
config.set('nsslapd-ndn-cache-max-size', original_size) |
| 778 |
inst.restart() |
| 779 |
|
| 780 |
def fin(): |
| 781 |
try: |
| 782 |
config.set('nsslapd-ndn-cache-max-size', original_size) |
| 783 |
inst.restart() |
| 784 |
except: |
| 785 |
pass |
| 786 |
if os.path.exists(import_ldif): |
| 787 |
os.remove(import_ldif) |
| 788 |
|
| 789 |
request.addfinalizer(fin) |
| 790 |
|
| 791 |
def test_require_index(topo): |
| 792 |
"""Validate that unindexed searches are rejected |
| 793 |
|
| 794 |
:id: fb6e31f2-acc2-4e75-a195-5c356faeb803 |
| 795 |
:setup: Standalone instance |
| 796 |
:steps: |
| 797 |
1. Set "nsslapd-require-index" to "on" |
| 798 |
2. Test an unindexed search is rejected |
| 799 |
:expectedresults: |
| 800 |
1. Success |
| 801 |
2. Success |
| 802 |
""" |
| 803 |
|
| 804 |
# Set the config |
| 805 |
be_insts = Backends(topo.standalone).list() |
| 806 |
for be in be_insts: |
| 807 |
if be.get_attr_val_utf8_l('nsslapd-suffix') == DEFAULT_SUFFIX: |
| 808 |
be.set('nsslapd-require-index', 'on') |
| 809 |
|
| 810 |
db_cfg = DatabaseConfig(topo.standalone) |
| 811 |
db_cfg.set([('nsslapd-idlistscanlimit', '100')]) |
| 812 |
|
| 813 |
users = UserAccounts(topo.standalone, DEFAULT_SUFFIX) |
| 814 |
for i in range(101): |
| 815 |
users.create_test_user(uid=i) |
| 816 |
|
| 817 |
# Issue unindexed search,a nd make sure it is rejected |
| 818 |
raw_objects = DSLdapObjects(topo.standalone, basedn=DEFAULT_SUFFIX) |
| 819 |
with pytest.raises(ldap.UNWILLING_TO_PERFORM): |
| 820 |
raw_objects.filter("(description=test*)") |
| 821 |
|
| 822 |
|
| 823 |
|
| 824 |
@pytest.mark.skipif(ds_is_older('1.4.2'), reason="The config setting only exists in 1.4.2 and higher") |
| 825 |
def test_require_internal_index(topo): |
| 826 |
"""Ensure internal operations require indexed attributes |
| 827 |
|
| 828 |
:id: 22b94f30-59e3-4f27-89a1-c4f4be036f7f |
| 829 |
:setup: Standalone instance |
| 830 |
:steps: |
| 831 |
1. Set "nsslapd-require-internalop-index" to "on" |
| 832 |
2. Enable RI plugin, and configure it to use an attribute that is not indexed |
| 833 |
3. Create a user and add it a group |
| 834 |
4. Deleting user should be rejected as the RI plugin issues an unindexed internal search |
| 835 |
:expectedresults: |
| 836 |
1. Success |
| 837 |
2. Success |
| 838 |
3. Success |
| 839 |
4. Success |
| 840 |
""" |
| 841 |
# Set the config |
| 842 |
be_insts = Backends(topo.standalone).list() |
| 843 |
for be in be_insts: |
| 844 |
if be.get_attr_val_utf8_l('nsslapd-suffix') == DEFAULT_SUFFIX: |
| 845 |
be.set('nsslapd-require-index', 'off') |
| 846 |
be.set('nsslapd-require-internalop-index', 'on') |
| 847 |
|
| 848 |
# Configure RI plugin |
| 849 |
rip = ReferentialIntegrityPlugin(topo.standalone) |
| 850 |
rip.set('referint-membership-attr', 'description') |
| 851 |
rip.enable() |
| 852 |
|
| 853 |
# Create a bunch of users |
| 854 |
db_cfg = DatabaseConfig(topo.standalone) |
| 855 |
db_cfg.set([('nsslapd-idlistscanlimit', '100')]) |
| 856 |
users = UserAccounts(topo.standalone, DEFAULT_SUFFIX) |
| 857 |
for i in range(102, 202): |
| 858 |
users.create_test_user(uid=i) |
| 859 |
|
| 860 |
# Create user and group |
| 861 |
user = users.create(properties={ |
| 862 |
'uid': 'indexuser', |
| 863 |
'cn' : 'indexuser', |
| 864 |
'sn' : 'user', |
| 865 |
'uidNumber' : '1010', |
| 866 |
'gidNumber' : '2010', |
| 867 |
'homeDirectory' : '/home/indexuser' |
| 868 |
}) |
| 869 |
groups = Groups(topo.standalone, DEFAULT_SUFFIX) |
| 870 |
group = groups.create(properties={'cn': 'group', |
| 871 |
'member': user.dn}) |
| 872 |
|
| 873 |
# Restart the server |
| 874 |
topo.standalone.restart() |
| 875 |
|
| 876 |
# Deletion of user should be rejected |
| 877 |
with pytest.raises(ldap.UNWILLING_TO_PERFORM): |
| 878 |
user.delete() |
| 879 |
|
| 880 |
|
| 881 |
def get_pstack(pid): |
| 882 |
"""Get a pstack of the pid.""" |
| 883 |
res = subprocess.run((PSTACK_CMD, str(pid)), stdout=subprocess.PIPE, |
| 884 |
stderr=subprocess.STDOUT, encoding='utf-8') |
| 885 |
return str(res.stdout) |
| 886 |
|
| 887 |
def check_number_of_threads(cfgnbthreads, monitor, pid): |
| 888 |
monresults = monitor.get_threads() |
| 889 |
# Add waitingthreads and busythreads |
| 890 |
waiting = int(monresults[3][0]) |
| 891 |
busy = int(monresults[4][0]) |
| 892 |
log.info('Number of threads: configured={cfgnbthreads} waiting={waiting} busy={busy}') |
| 893 |
|
| 894 |
monnbthreads = int(monresults[3][0]) + int(monresults[4][0]); |
| 895 |
assert monnbthreads == cfgnbthreads |
| 896 |
if os.path.isfile(PSTACK_CMD): |
| 897 |
pstackresult = get_pstack(pid) |
| 898 |
assert pstackresult.count('connection_threadmain') == cfgnbthreads |
| 899 |
else: |
| 900 |
log.info('pstack is not installed ==> skipping pstack test.') |
| 901 |
|
| 902 |
def test_changing_threadnumber(topo): |
| 903 |
"""Validate thread number changes in the server configuration |
| 904 |
|
| 905 |
:id: 11bcf426-061c-11ee-8c22-482ae39447e5 |
| 906 |
:setup: Standalone instance |
| 907 |
:steps: |
| 908 |
1. Check that feature is supported |
| 909 |
2 Get nsslapd-threadnumber original value |
| 910 |
3. Change nsslapd-threadnumber to 40 |
| 911 |
4. Check that monitoring and pstack shows the same number than configured number of threads |
| 912 |
5. Create a user and add it a group |
| 913 |
6. Change nsslapd-threadnumber to 10 |
| 914 |
7. Check that monitoring and pstack shows the same number than configured number of threads |
| 915 |
8. Set back the number of threads to the original value |
| 916 |
9. Check that monitoring and pstack shows the same number than configured number of threads |
| 917 |
:expectedresults: |
| 918 |
1. Skip the test if monitoring result does not have the new attributes. |
| 919 |
2. Success |
| 920 |
3. Success |
| 921 |
4. Success |
| 922 |
5. Success |
| 923 |
6. Success |
| 924 |
7. Success |
| 925 |
8. Success |
| 926 |
9. Success |
| 927 |
""" |
| 928 |
inst = topo.standalone |
| 929 |
pid = pid_from_file(inst.pid_file()) |
| 930 |
assert pid != 0 and pid != None |
| 931 |
|
| 932 |
config = Config(inst) |
| 933 |
cfgattr = 'nsslapd-threadnumber' |
| 934 |
cfgnbthreads = config.get_attr_vals_utf8(cfgattr)[0] |
| 935 |
|
| 936 |
monitor = Monitor(inst) |
| 937 |
monresults = monitor.get_threads() |
| 938 |
if len(monresults) < 5: |
| 939 |
pytest.skip("This version does not support dynamic change of nsslapd-threadnumber without restart.") |
| 940 |
|
| 941 |
config.replace(cfgattr, '40'); |
| 942 |
time.sleep(3) |
| 943 |
check_number_of_threads(40, monitor, pid) |
| 944 |
|
| 945 |
config.replace(cfgattr, '10'); |
| 946 |
# No need to wait here (threads are closed before config change result is returned) |
| 947 |
check_number_of_threads(10, monitor, pid) |
| 948 |
|
| 949 |
config.replace(cfgattr, cfgnbthreads); |
| 950 |
time.sleep(3) |
| 951 |
check_number_of_threads(int(cfgnbthreads), monitor, pid) |
| 952 |
|
| 953 |
|
| 954 |
@pytest.fixture(scope="module") |
| 955 |
def create_lmdb_instance(request): |
| 956 |
verbose = log.level > logging.DEBUG |
| 957 |
instname = 'i_lmdb' |
| 958 |
assert SetupDs(verbose=True, log=log).create_from_dict( { |
| 959 |
'general' : {}, |
| 960 |
'slapd' : { |
| 961 |
'instance_name': instname, |
| 962 |
'db_lib': 'mdb', |
| 963 |
'mdb_max_size': '0.5 Gb', |
| 964 |
}, |
| 965 |
'backend-userroot': { |
| 966 |
'sample_entries': 'yes', |
| 967 |
'suffix': DEFAULT_SUFFIX, |
| 968 |
}, |
| 969 |
} ) |
| 970 |
inst = DirSrv(verbose=verbose, external_log=log) |
| 971 |
inst.local_simple_allocate(instname, binddn=DN_DM, password=PW_DM) |
| 972 |
inst.setup_ldapi() |
| 973 |
|
| 974 |
def fin(): |
| 975 |
inst.delete() |
| 976 |
|
| 977 |
request.addfinalizer(fin) |
| 978 |
inst.open() |
| 979 |
return inst |
| 980 |
|
| 981 |
|
| 982 |
def set_and_check(inst, db_config, dsconf_attr, ldap_attr, val): |
| 983 |
val = str(val) |
| 984 |
args = FakeArgs() |
| 985 |
setattr(args, dsconf_attr, val) |
| 986 |
db_config_set(inst, db_config.dn, log, args) |
| 987 |
cfg_vals = db_config.get() |
| 988 |
assert ldap_attr in cfg_vals |
| 989 |
assert cfg_vals[ldap_attr][0] == val |
| 990 |
|
| 991 |
|
| 992 |
def test_lmdb_config(create_lmdb_instance): |
| 993 |
"""Verify LMDB configuration settings in custom instance |
| 994 |
|
| 995 |
:id: bca28086-61cf-11ee-a064-482ae39447e5 |
| 996 |
:setup: Custom instance named 'i_lmdb' having db_lib=mdb and lmdb_size=0.5 |
| 997 |
:steps: |
| 998 |
1. Get dscreate create-template output |
| 999 |
2. Check that 'db_lib' is in output |
| 1000 |
3. Extract 'mdb_max_size' from output and verify it's correct |
| 1001 |
4. Get the database config |
| 1002 |
5. Check that nsslapd-backend-implement is mdb |
| 1003 |
6. Check that nsslapd-mdb-max-size is 536870912 (i.e 0.5Gb) |
| 1004 |
7. Set a value for nsslapd-mdb-max-size and test the value is properly set |
| 1005 |
8. Set a value for nsslapd-mdb-max-readers and test the value is properly set |
| 1006 |
9. Set a value for nsslapd-mdb-max-dbs and test the value is properly set |
| 1007 |
:expectedresults: |
| 1008 |
1. Success |
| 1009 |
2. Success |
| 1010 |
3. Success |
| 1011 |
4. Success |
| 1012 |
5. Success |
| 1013 |
6. Success |
| 1014 |
7. Success |
| 1015 |
8. Success |
| 1016 |
9. Success |
| 1017 |
""" |
| 1018 |
|
| 1019 |
res = subprocess.run(('dscreate', 'create-template'), stdout=subprocess.PIPE, |
| 1020 |
stderr=subprocess.STDOUT, encoding='utf-8') |
| 1021 |
inst = create_lmdb_instance |
| 1022 |
assert 'db_lib' in res.stdout |
| 1023 |
|
| 1024 |
# Extract the mdb_max_size value from the output |
| 1025 |
mdb_max_size_line = next(line for line in res.stdout.splitlines() if 'mdb_max_size =' in line) |
| 1026 |
mdb_max_size_value = mdb_max_size_line.split('=')[1].strip() |
| 1027 |
|
| 1028 |
# Parse the mdb_max_size value to int and back |
| 1029 |
parsed_size = parse_size(mdb_max_size_value) |
| 1030 |
formatted_size = format_size(parsed_size) |
| 1031 |
|
| 1032 |
# Assert the original value and the processed value are the same |
| 1033 |
assert mdb_max_size_value == formatted_size, f"Initial mdb_max_size value {mdb_max_size_value} does not match the formatted size {formatted_size}" |
| 1034 |
|
| 1035 |
db_config = DatabaseConfig(inst) |
| 1036 |
cfg_vals = db_config.get() |
| 1037 |
assert 'nsslapd-backend-implement' in cfg_vals |
| 1038 |
assert cfg_vals['nsslapd-backend-implement'][0] == 'mdb' |
| 1039 |
assert 'nsslapd-mdb-max-size' in cfg_vals |
| 1040 |
assert cfg_vals['nsslapd-mdb-max-size'][0] == '536870912' |
| 1041 |
set_and_check(inst, db_config, 'mdb_max_size', 'nsslapd-mdb-max-size', parse_size('2G')) |
| 1042 |
set_and_check(inst, db_config, 'mdb_max_readers', 'nsslapd-mdb-max-readers', 200) |
| 1043 |
set_and_check(inst, db_config, 'mdb_max_dbs', 'nsslapd-mdb-max-dbs', 200) |
| 1044 |
|
| 1045 |
|
| 1046 |
def test_numlisteners_limit(topo): |
| 1047 |
"""Test higher limit of nsslapd-numlisteners than 4 |
| 1048 |
DS allows a higher value of nsslapd-numlisteners than it's limit of 4 |
| 1049 |
|
| 1050 |
:id: 96869ea9-c7b4-4a4f-85f9-ea1d3f4a63aa |
| 1051 |
:setup: Standalone Instance |
| 1052 |
:steps: |
| 1053 |
1. Check default nsslapd-numlisteners value is 1 |
| 1054 |
2. Set nsslapd-numlisteners value to 4 |
| 1055 |
3. Check nsslapd-numlisteners value is set to 4 |
| 1056 |
4. Check dse.ldif value of nsslapd-numlisteners is set to 4 |
| 1057 |
5. systemctl restart dirsrv@localhost |
| 1058 |
6. Check nsslapd-numlisteners value is 4, after server restart |
| 1059 |
7. Set nsslapd-numlisteners value to greater than the max value (4) |
| 1060 |
8. Check if nsslapd-numlisteners value is still 4 |
| 1061 |
9. Check dse.ldif value of nsslapd-numlisteners is set to 4 |
| 1062 |
:expectedresults: |
| 1063 |
1. nsslapd-numlisteners config value should show 1 by default |
| 1064 |
2. nsslapd-numlisteners value should be successfully set to 4 |
| 1065 |
3. nsslapd-numlisteners is indeed set to 4 |
| 1066 |
4. nsslapd-numlisteners value in localhost dse.ldif file is set to 4 |
| 1067 |
5. restart DS instance is successful |
| 1068 |
6. nsslapd-numlisteners value is still 4 after server restart |
| 1069 |
7. Invalid value is rejected |
| 1070 |
8. nsslapd-numlisteners value is still 4 |
| 1071 |
9. nsslapd-numlisteners value in localhost dse.ldif file is set to 4 |
| 1072 |
""" |
| 1073 |
# Check default value for nsslapd-numlisteners is 1 |
| 1074 |
assert topo.standalone.config.get_attr_val_utf8('nsslapd-numlisteners') == '1' |
| 1075 |
|
| 1076 |
# Set nsslapd-numlisteners value to 4 |
| 1077 |
topo.standalone.config.set('nsslapd-numlisteners', '4') |
| 1078 |
|
| 1079 |
# Check nsslapd-numlisteners value is set to 4 |
| 1080 |
assert topo.standalone.config.get_attr_val_utf8('nsslapd-numlisteners') == '4' |
| 1081 |
|
| 1082 |
# Check instance dse.ldif value is set to 4 |
| 1083 |
inst = topo.standalone |
| 1084 |
dse_ldif = DSEldif(inst) |
| 1085 |
numlisteners = dse_ldif.get(DN_CONFIG, 'nsslapd-numlisteners') |
| 1086 |
assert numlisteners[0] == '4' |
| 1087 |
|
| 1088 |
# Restart instance |
| 1089 |
topo.standalone.restart() |
| 1090 |
|
| 1091 |
# Check nsslapd-numlisteners value is set to 4 |
| 1092 |
assert topo.standalone.config.get_attr_val_utf8('nsslapd-numlisteners') == '4' |
| 1093 |
|
| 1094 |
# Check if nsslapd-numlisteners value is not set more than 4 |
| 1095 |
with pytest.raises(ldap.UNWILLING_TO_PERFORM): |
| 1096 |
assert(not topo.standalone.config.replace('nsslapd-numlisteners', '5')) |
| 1097 |
|
| 1098 |
# Check nsslapd-numlisteners value is set to 4 |
| 1099 |
assert topo.standalone.config.get_attr_val_utf8('nsslapd-numlisteners') == '4' |
| 1100 |
|
| 1101 |
# Check the value of nsslapd-numlisteners in dse.ldif is set to 4 |
| 1102 |
numlisteners = dse_ldif.get(DN_CONFIG, 'nsslapd-numlisteners') |
| 1103 |
assert numlisteners[0] == '4' |
| 1104 |
|
| 1105 |
|
| 1106 |
def bootstrap_replication(inst_from, inst_to, creds): |
| 1107 |
manager = BootstrapReplicationManager(inst_to) |
| 1108 |
rdn_val = 'replication manager' |
| 1109 |
if manager.exists(): |
| 1110 |
manager.delete() |
| 1111 |
manager.create(properties={ |
| 1112 |
'cn': rdn_val, |
| 1113 |
'uid': rdn_val, |
| 1114 |
'userPassword': creds |
| 1115 |
}) |
| 1116 |
for replica in Replicas(inst_to).list(): |
| 1117 |
replica.remove_all('nsDS5ReplicaBindDNGroup') |
| 1118 |
replica.replace('nsDS5ReplicaBindDN', manager.dn) |
| 1119 |
for agmt in Agreements(inst_from).list(): |
| 1120 |
agmt.replace('nsDS5ReplicaBindDN', manager.dn) |
| 1121 |
agmt.replace('nsDS5ReplicaCredentials', creds) |
| 1122 |
|
| 1123 |
|
| 1124 |
@pytest.mark.skipif(get_default_db_lib() != "mdb", reason="This test requires lmdb") |
| 1125 |
def test_lmdb_autotuned_maxdbs(topology_m2, request): |
| 1126 |
"""Verify that after restart, nsslapd-mdb-max-dbs is large enough to add a new backend. |
| 1127 |
|
| 1128 |
:id: 0272d432-9080-11ef-8f40-482ae39447e5 |
| 1129 |
:setup: Two suppliers configuration |
| 1130 |
:steps: |
| 1131 |
1. loop 20 times |
| 1132 |
3. In 1 loop: restart instance |
| 1133 |
3. In 1 loop: add a new backend |
| 1134 |
4. In 1 loop: check that instance is still alive |
| 1135 |
:expectedresults: |
| 1136 |
1. Success |
| 1137 |
2. Success |
| 1138 |
3. Success |
| 1139 |
4. Success |
| 1140 |
""" |
| 1141 |
|
| 1142 |
s1 = topology_m2.ms["supplier1"] |
| 1143 |
s2 = topology_m2.ms["supplier2"] |
| 1144 |
|
| 1145 |
backends = Backends(s1) |
| 1146 |
db_config = DatabaseConfig(s1) |
| 1147 |
# Generate the teardown finalizer |
| 1148 |
belist = [] |
| 1149 |
creds=password_generate() |
| 1150 |
bootstrap_replication(s2, s1, creds) |
| 1151 |
bootstrap_replication(s1, s2, creds) |
| 1152 |
|
| 1153 |
def fin(): |
| 1154 |
s1.start() |
| 1155 |
for be in belist: |
| 1156 |
be.delete() |
| 1157 |
|
| 1158 |
if not DEBUGGING: |
| 1159 |
request.addfinalizer(fin) |
| 1160 |
|
| 1161 |
# 1. Set autotuning (off-line to be able to decrease the value) |
| 1162 |
s1.stop() |
| 1163 |
dse_ldif = DSEldif(s1) |
| 1164 |
dse_ldif.replace(db_config.dn, 'nsslapd-mdb-max-dbs', '0') |
| 1165 |
os.remove(f'{s1.dbdir}/data.mdb') |
| 1166 |
s1.start() |
| 1167 |
|
| 1168 |
# 2. Reinitialize the db: |
| 1169 |
log.info("Bulk import...") |
| 1170 |
agmt = Agreements(s2).list()[0] |
| 1171 |
agmt.begin_reinit() |
| 1172 |
(done, error) = agmt.wait_reinit() |
| 1173 |
log.info(f'Bulk importresult is ({done}, {error})') |
| 1174 |
assert done is True |
| 1175 |
assert error is False |
| 1176 |
|
| 1177 |
# 3. loop 20 times |
| 1178 |
for idx in range(20): |
| 1179 |
s1.restart() |
| 1180 |
log.info(f'Adding backend test{idx}') |
| 1181 |
belist.append(backends.create(properties={'cn': f'test{idx}', |
| 1182 |
'nsslapd-suffix': f'dc=test{idx}'})) |
| 1183 |
assert s1.status() |
| 1184 |
|
| 1185 |
|
| 1186 |
|
| 1187 |
if __name__ == '__main__': |
| 1188 |
# Run isolated |
| 1189 |
# -s for DEBUG mode |
| 1190 |
CURRENT_FILE = os.path.realpath(__file__) |
| 1191 |
pytest.main("-s %s" % CURRENT_FILE) |
| 1192 |
|
| 1193 |
|