Debian Codegraph @

dirsrvtests/tests/suites/config/autotuning_test.py

raw
1 # --- BEGIN COPYRIGHT BLOCK ---
2 # Copyright (C) 2025 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 import pytest
10 import ldap
11 import logging
12 import os
13 import time
14 from lib389._mapped_object import DSLdapObject
15 from lib389.utils import get_default_db_lib
16 from test389.topologies import topology_st as topo
17 from lib389.backend import Backends
18 from lib389.idm.user import UserAccounts
19 from lib389.config import BDB_LDBMConfig, LMDB_LDBMConfig
20
21
22 from lib389._constants import (
23 DN_USERROOT_LDBM,
24 DEFAULT_SUFFIX
25 )
26
27 pytestmark = pytest.mark.tier0
28
29 DEBUGGING = os.getenv("DEBUGGING", default=False)
30 if DEBUGGING:
31 logging.getLogger(__name__).setLevel(logging.DEBUG)
32 else:
33 logging.getLogger(__name__).setLevel(logging.INFO)
34 log = logging.getLogger(__name__)
35
36
37 def test_threads_basic(topo):
38 """Check that a number of threads are able to be autotuned
39
40 :id: 371fb9c4-9607-4a4b-a4a2-6f00809d6257
41 :setup: Standalone instance
42 :steps:
43 1. Set nsslapd-threadnumber to -1
44 2. Check that number of threads is positive
45 :expectedresults:
46 1. nsslapd-threadnumber should be successfully set
47 2. nsslapd-threadnumber is positive
48 """
49
50 log.info("Set nsslapd-threadnumber: -1 to enable autotuning")
51 topo.standalone.config.set("nsslapd-threadnumber", "-1")
52
53 log.info("Assert nsslapd-threadnumber is equal to the documented expected value")
54 assert topo.standalone.config.get_attr_val_int("nsslapd-threadnumber") > 0
55
56
57 def test_threads_warning(topo):
58 """Check that we log a warning if the thread number is too high or low
59
60 :id: db92412b-2812-49de-84b0-00f452cd254f
61 :setup: Standalone Instance
62 :steps:
63 1. Get autotuned thread number
64 2. Set threads way higher than hw threads, and find a warning in the log
65 3. Set threads way lower than hw threads, and find a warning in the log
66 :expectedresults:
67 1. Success
68 2. Success
69 3. Success
70 """
71 topo.standalone.config.set("nsslapd-threadnumber", "-1")
72 autotuned_value = topo.standalone.config.get_attr_val_utf8("nsslapd-threadnumber")
73
74 topo.standalone.config.set("nsslapd-threadnumber", str(int(autotuned_value) * 4))
75 time.sleep(.5)
76 assert topo.standalone.ds_error_log.match('.*higher.*hurt server performance.*')
77
78 if int(autotuned_value) > 1:
79 # If autotuned is 1, there isn't anything to test here
80 topo.standalone.config.set("nsslapd-threadnumber", "1")
81 time.sleep(.5)
82 assert topo.standalone.ds_error_log.match('.*lower.*hurt server performance.*')
83
84
85 @pytest.mark.parametrize("invalid_value", ('-2', '0', 'invalid'))
86 def test_threads_invalid_value(topo, invalid_value):
87 """Check nsslapd-threadnumber for an invalid values
88
89 :id: 1979eddf-8222-4c9d-809d-269c26de636e
90 :parametrized: yes
91 :setup: Standalone instance
92 :steps:
93 1. Set nsslapd-threadnumber to -2, 0, invalid_str
94 :expectedresults:
95 1. The operation should fail
96 """
97
98 log.info("Set nsslapd-threadnumber: {}. Operation should fail".format(invalid_value))
99 with pytest.raises(ldap.OPERATIONS_ERROR):
100 topo.standalone.config.set("nsslapd-threadnumber", invalid_value)
101
102
103 def test_threads_back_from_manual_value(topo):
104 """Check that thread autotuning works after manual tuning
105
106 :id: 4b674016-e5ca-426b-a9c0-a94745a7dd25
107 :setup: Standalone instance
108 :steps:
109 1. Set nsslapd-threadnumber to -1 and save the autotuned value
110 2. Decrease nsslapd-threadnumber by 2
111 3. Set nsslapd-threadnumber to -1
112 4. Check that nsslapd-threadnumber is back to autotuned value
113 :expectedresults:
114 1. nsslapd-threadnumber should be successfully set
115 2. nsslapd-threadnumber should be successfully decreased
116 3. nsslapd-threadnumber should be successfully set
117 4. nsslapd-threadnumber is set back to the autotuned value
118 """
119
120 log.info("Set nsslapd-threadnumber: -1 to enable autotuning and save the new value")
121 topo.standalone.config.set("nsslapd-threadnumber", "-1")
122 autotuned_value = topo.standalone.config.get_attr_val_utf8("nsslapd-threadnumber")
123
124 log.info("Set nsslapd-threadnumber to the autotuned value decreased by 2")
125 new_value = str(int(autotuned_value) - 2)
126 topo.standalone.config.set("nsslapd-threadnumber", new_value)
127 assert topo.standalone.config.get_attr_val_utf8("nsslapd-threadnumber") == new_value
128
129 log.info("Set nsslapd-threadnumber: -1 to enable autotuning")
130 topo.standalone.config.set("nsslapd-threadnumber", "-1")
131
132 log.info("Assert nsslapd-threadnumber is back to the autotuned value")
133 assert topo.standalone.config.get_attr_val_utf8("nsslapd-threadnumber") == autotuned_value
134
135
136 @pytest.mark.skipif(get_default_db_lib() == "mdb", reason="Not supported over mdb")
137 @pytest.mark.parametrize("autosize,autosize_split", (('', ''), ('', '0'), ('10', '40'), ('', '40'),
138 ('10', ''), ('10', '40'), ('10', '0')))
139 def test_cache_autosize_non_zero(topo, autosize, autosize_split):
140 """Check that autosizing works works properly in different combinations
141
142 :id: 83fa099c-a6c9-457a-82db-0982b67e8598
143 :parametrized: yes
144 :setup: Standalone instance
145 :steps:
146 1. Set in the cn=config,cn=ldbm database,cn=plugins,cn=config:
147 nsslapd-cache-autosize, nsslapd-cache-autosize-split to the next value pairs:
148 ('', ''), ('', '0'), ('10', '40'), ('', '40'),
149 ('10', ''), ('10', '40'), ('10', '0')
150 '' - for deleting the value (set to default)
151 2. Try to modify nsslapd-dbcachesize and nsslapd-cachememsize to
152 some real value, it should be rejected
153 3. Restart the instance
154 4. Check nsslapd-dbcachesize and nsslapd-cachememsize
155 :expectedresults:
156 1. nsslapd-cache-autosize, nsslapd-cache-autosize-split are successfully set
157 2. Modify operation should be rejected
158 3. The instance should be successfully restarted
159 4. nsslapd-dbcachesize and nsslapd-cachememsize should set
160 to value greater than 512KB
161 """
162
163 bdb_config_ldbm = BDB_LDBMConfig(topo.standalone)
164 userroot_ldbm = DSLdapObject(topo.standalone, DN_USERROOT_LDBM)
165
166 cachesize = '33333333'
167
168 dbcachesize_val = bdb_config_ldbm.get_attr_val('nsslapd-dbcachesize')
169 autosize_val = bdb_config_ldbm.get_attr_val('nsslapd-cache-autosize')
170 autosize_split_val = bdb_config_ldbm.get_attr_val('nsslapd-cache-autosize-split')
171
172 cachememsize_val = userroot_ldbm.get_attr_val('nsslapd-cachememsize')
173 dncachememsize_val = userroot_ldbm.get_attr_val('nsslapd-dncachememsize')
174
175 log.info("Check nsslapd-dbcachesize and nsslapd-cachememsize before the test")
176 log.info("nsslapd-dbcachesize == {}".format(dbcachesize_val))
177 log.info("nsslapd-cachememsize == {}".format(cachememsize_val))
178 log.info("nsslapd-dncachememsize == {}".format(dncachememsize_val))
179 log.info("nsslapd-cache-autosize == {}".format(autosize_val))
180 log.info("nsslapd-cache-autosize-split == {}".format(autosize_split_val))
181
182 if autosize:
183 log.info("Set nsslapd-cache-autosize to {}".format(autosize))
184 bdb_config_ldbm.set('nsslapd-cache-autosize', autosize)
185 else:
186 log.info("Delete nsslapd-cache-autosize")
187 try:
188 bdb_config_ldbm.remove('nsslapd-cache-autosize', autosize_val)
189 except ValueError:
190 log.info("nsslapd-cache-autosize wasn't found")
191
192 if autosize_split:
193 log.info("Set nsslapd-cache-autosize-split to {}".format(autosize_split))
194 bdb_config_ldbm.set('nsslapd-cache-autosize-split', autosize_split)
195 else:
196 log.info("Delete nsslapd-cache-autosize-split")
197 try:
198 bdb_config_ldbm.remove('nsslapd-cache-autosize-split', autosize_split_val)
199 except ValueError:
200 log.info("nsslapd-cache-autosize-split wasn't found")
201
202 log.info("Trying to set nsslapd-cachememsize to {}".format(cachesize))
203 with pytest.raises(ldap.UNWILLING_TO_PERFORM):
204 userroot_ldbm.set('nsslapd-cachememsize', cachesize)
205 log.info("Trying to set nsslapd-dbcachesize to {}".format(cachesize))
206 with pytest.raises(ldap.UNWILLING_TO_PERFORM):
207 bdb_config_ldbm.set('nsslapd-dbcachesize ', cachesize)
208 topo.standalone.restart()
209
210 dbcachesize_val = bdb_config_ldbm.get_attr_val('nsslapd-dbcachesize')
211 autosize_val = bdb_config_ldbm.get_attr_val('nsslapd-cache-autosize')
212 autosize_split_val = bdb_config_ldbm.get_attr_val('nsslapd-cache-autosize-split')
213
214 cachememsize_val = userroot_ldbm.get_attr_val('nsslapd-cachememsize')
215 dncachememsize_val = userroot_ldbm.get_attr_val('nsslapd-dncachememsize')
216
217 log.info("Check nsslapd-dbcachesize and nsslapd-cachememsize in the appropriate range.")
218 log.info("nsslapd-dbcachesize == {}".format(dbcachesize_val))
219 log.info("nsslapd-cachememsize == {}".format(cachememsize_val))
220 log.info("nsslapd-dncachememsize == {}".format(dncachememsize_val))
221 log.info("nsslapd-cache-autosize == {}".format(autosize_val))
222 log.info("nsslapd-cache-autosize-split == {}".format(autosize_split_val))
223 assert int(dbcachesize_val) >= 512000
224 assert int(cachememsize_val) >= 512000
225 assert int(dncachememsize_val) >= 512000
226
227
228 @pytest.mark.skipif(get_default_db_lib() == "mdb", reason="Not supported over mdb")
229 @pytest.mark.parametrize("autosize_split", ('0', '', '40'))
230 def test_cache_autosize_basic_sane(topo, autosize_split):
231 """Check that autotuning cachesizes works properly with different values
232
233 :id: 9dc363ef-f551-446d-8b83-8ac45dabb8df
234 :parametrized: yes
235 :setup: Standalone instance
236 :steps:
237 1. Set in the cn=config,cn=ldbm database,cn=plugins,cn=config:
238 nsslapd-cache-autosize, nsslapd-cache-autosize-split to the next value pairs:
239 ('0', '0'), ('0', ''), ('0', '40')
240 '' - for deleting the value (set to default)
241 2. Set in the cn=config,cn=ldbm database,cn=plugins,cn=config:
242 nsslapd-dbcachesize: 0 and some same value
243 3. Set in the cn=UserRoot,cn=ldbm database,cn=plugins,cn=config:
244 nsslapd-cachememsize: 0 and some same value
245 4. Restart the instance
246 5. Check nsslapd-dbcachesize and nsslapd-cachememsize
247 :expectedresults:
248 1. nsslapd-cache-autosize, nsslapd-cache-autosize-split are successfully set
249 2. nsslapd-dbcachesize are successfully set
250 3. nsslapd-cachememsize are successfully set
251 4. The instance should be successfully restarted
252 5. nsslapd-dbcachesize and nsslapd-cachememsize should set
253 to value greater than 512KB
254 """
255
256 bdb_config_ldbm = BDB_LDBMConfig(topo.standalone)
257 userroot_ldbm = DSLdapObject(topo.standalone, DN_USERROOT_LDBM)
258 bdb_config_ldbm.set('nsslapd-cache-autosize', '0')
259
260 # Test with caches with both real values and 0
261 for cachesize in ('0', '33333333'):
262 dbcachesize_val = bdb_config_ldbm.get_attr_val('nsslapd-dbcachesize')
263 autosize_val = bdb_config_ldbm.get_attr_val('nsslapd-cache-autosize')
264 autosize_split_val = bdb_config_ldbm.get_attr_val('nsslapd-cache-autosize-split')
265
266 cachememsize_val = userroot_ldbm.get_attr_val('nsslapd-cachememsize')
267 dncachememsize_val = userroot_ldbm.get_attr_val('nsslapd-dncachememsize')
268
269 log.info("Check nsslapd-dbcachesize and nsslapd-cachememsize before the test")
270 log.info("nsslapd-dbcachesize == {}".format(dbcachesize_val))
271 log.info("nsslapd-cachememsize == {}".format(cachememsize_val))
272 log.info("nsslapd-cache-autosize == {}".format(autosize_val))
273 log.info("nsslapd-cache-autosize-split == {}".format(autosize_split_val))
274
275 if autosize_split:
276 log.info("Set nsslapd-cache-autosize-split to {}".format(autosize_split))
277 bdb_config_ldbm.set('nsslapd-cache-autosize-split', autosize_split)
278 else:
279 log.info("Delete nsslapd-cache-autosize-split")
280 try:
281 bdb_config_ldbm.remove('nsslapd-cache-autosize-split', autosize_split_val)
282 except ValueError:
283 log.info("nsslapd-cache-autosize-split wasn't found")
284
285 log.info("Set nsslapd-dbcachesize to {}".format(cachesize))
286 bdb_config_ldbm.set('nsslapd-dbcachesize', cachesize)
287 log.info("Set nsslapd-cachememsize to {}".format(cachesize))
288 userroot_ldbm.set('nsslapd-cachememsize', cachesize)
289 topo.standalone.restart()
290
291 dbcachesize_val = bdb_config_ldbm.get_attr_val('nsslapd-dbcachesize')
292 autosize_val = bdb_config_ldbm.get_attr_val('nsslapd-cache-autosize')
293 autosize_split_val = bdb_config_ldbm.get_attr_val('nsslapd-cache-autosize-split')
294
295 cachememsize_val = userroot_ldbm.get_attr_val('nsslapd-cachememsize')
296 dncachememsize_val = userroot_ldbm.get_attr_val('nsslapd-dncachememsize')
297
298 log.info("Check nsslapd-dbcachesize and nsslapd-cachememsize in the appropriate range.")
299 log.info("nsslapd-dbcachesize == {}".format(dbcachesize_val))
300 log.info("nsslapd-cachememsize == {}".format(cachememsize_val))
301 log.info("nsslapd-dncachememsize == {}".format(dncachememsize_val))
302 log.info("nsslapd-cache-autosize == {}".format(autosize_val))
303 log.info("nsslapd-cache-autosize-split == {}".format(autosize_split_val))
304 assert int(dbcachesize_val) >= 512000
305 assert int(cachememsize_val) >= 512000
306 assert int(dncachememsize_val) >= 512000
307
308
309 @pytest.mark.skipif(get_default_db_lib() == "mdb", reason="Not supported over mdb")
310 @pytest.mark.parametrize("invalid_value", ('-2', '102', 'invalid'))
311 def test_cache_autosize_invalid_values(topo, invalid_value):
312 """Check that we can't set invalid values to autosize attributes
313
314 :id: 2f0d01b5-ca91-4dc2-97bc-ad0ac8d08633
315 :parametrized: yes
316 :setup: Standalone instance
317 :steps:
318 1. Stop the instance
319 2. Set in the cn=config,cn=ldbm database,cn=plugins,cn=config:
320 nsslapd-cache-autosize and nsslapd-cache-autosize-split
321 to invalid values like (-2, 102, invalid_str)
322 3. Try to start the instance
323 :expectedresults:
324 1. The instance should stop successfully
325 2. nsslapd-cache-autosize, nsslapd-cache-autosize-split are successfully set
326 3. Starting the instance should fail
327 """
328
329 bdb_config_ldbm = BDB_LDBMConfig(topo.standalone)
330 autosize_val = bdb_config_ldbm.get_attr_val('nsslapd-cache-autosize')
331 autosize_split_val = bdb_config_ldbm.get_attr_val('nsslapd-cache-autosize-split')
332
333 log.info("Set nsslapd-cache-autosize-split to {}".format(invalid_value))
334 with pytest.raises(ldap.UNWILLING_TO_PERFORM):
335 bdb_config_ldbm.set('nsslapd-cache-autosize-split', invalid_value)
336 topo.standalone.restart()
337 bdb_config_ldbm.remove('nsslapd-cache-autosize-split', autosize_split_val)
338
339 log.info("Set nsslapd-cache-autosize to {}".format(invalid_value))
340 with pytest.raises(ldap.UNWILLING_TO_PERFORM):
341 bdb_config_ldbm.set('nsslapd-cache-autosize', invalid_value)
342 topo.standalone.restart()
343 bdb_config_ldbm.remove('nsslapd-cache-autosize', autosize_val)
344
345
346 @pytest.mark.skipif(get_default_db_lib() == "bdb",
347 reason="Not supported over bdb")
348 @pytest.mark.parametrize("autosize", ('', '10'))
349 def test_mdb_cache_autosize_non_zero(topo, autosize):
350 """Check that autosizing works works properly in different combinations
351
352 :id: 2b040cd4-6a5d-49fc-9e69-0bf44045603d
353 :parametrized: yes
354 :setup: Standalone instance
355 :steps:
356 1. Set in the cn=config,cn=ldbm database,cn=plugins,cn=config:
357 nsslapd-cache-autosize to the next value pairs:
358 ('', '10')
359 '' - for deleting the value (set to default)
360 2. Try to modify nsslapd-cachememsize to some real value, it should be
361 rejected
362 3. Restart the instance
363 4. Check nsslapd-cachememsize
364 :expectedresults:
365 1. nsslapd-cache-autosize is successfully set
366 2. Modify operation should be rejected
367 3. The instance should be successfully restarted
368 4. nsslapd-cachememsize should set to value greater than 512KB
369 """
370
371 mdb_config_ldbm = LMDB_LDBMConfig(topo.standalone)
372 userroot_ldbm = DSLdapObject(topo.standalone, DN_USERROOT_LDBM)
373
374 cachesize = '33333333'
375 autosize_val = mdb_config_ldbm.get_attr_val('nsslapd-cache-autosize')
376 cachememsize_val = userroot_ldbm.get_attr_val('nsslapd-cachememsize')
377 dncachememsize_val = userroot_ldbm.get_attr_val('nsslapd-dncachememsize')
378
379 log.info("Check nsslapd-cachememsize before the test")
380 log.info("nsslapd-cachememsize == %s", cachememsize_val)
381 log.info("nsslapd-dncachememsize == %s", dncachememsize_val)
382 log.info("nsslapd-cache-autosize == %s", autosize_val)
383
384 if autosize:
385 log.info("Set nsslapd-cache-autosize to %s", autosize)
386 mdb_config_ldbm.set('nsslapd-cache-autosize', autosize)
387 else:
388 log.info("Delete nsslapd-cache-autosize")
389 try:
390 mdb_config_ldbm.remove('nsslapd-cache-autosize', autosize_val)
391 except ValueError:
392 log.info("nsslapd-cache-autosize wasn't found")
393
394 autosize_val = mdb_config_ldbm.get_attr_val('nsslapd-cache-autosize')
395 log.info("Trying to set nsslapd-cachememsize to %s (autosize %s)",
396 cachesize, autosize_val)
397 with pytest.raises(ldap.UNWILLING_TO_PERFORM):
398 userroot_ldbm.set('nsslapd-cachememsize', cachesize)
399 topo.standalone.restart()
400
401 autosize_val = mdb_config_ldbm.get_attr_val('nsslapd-cache-autosize')
402 cachememsize_val = userroot_ldbm.get_attr_val('nsslapd-cachememsize')
403 dncachememsize_val = userroot_ldbm.get_attr_val('nsslapd-dncachememsize')
404
405 log.info("Check nsslapd-cachememsize in the appropriate range.")
406 log.info("nsslapd-cachememsize == %s", cachememsize_val)
407 log.info("nsslapd-dncachememsize == %s", dncachememsize_val)
408 log.info("nsslapd-cache-autosize == %s", autosize_val)
409 assert int(cachememsize_val) >= 512000
410 assert int(dncachememsize_val) >= 512000
411
412
413 @pytest.mark.skipif(get_default_db_lib() == "bdb",
414 reason="Not supported over bdb")
415 def test_mdb_cache_autosize_basic_sane(topo):
416 """Check that autotuning cachesizes works properly with different values
417
418 :id: e0dd2c7a-a28e-4b17-8959-c4743810bd7d
419 :setup: Standalone instance
420 :steps:
421 1. Set in the cn=config,cn=ldbm database,cn=plugins,cn=config:
422 2. Set in the cn=UserRoot,cn=ldbm database,cn=plugins,cn=config:
423 nsslapd-cachememsize: 0 and some same value
424 3. Restart the instance
425 4. Check nsslapd-dbcachesize and nsslapd-cachememsize
426 :expectedresults:
427 1. nsslapd-cache-autosize is successfully set
428 2. nsslapd-cachememsize is successfully set
429 3. The instance should be successfully restarted
430 4. nsslapd-cachememsize should set to value greater than 512KB
431 """
432
433 mdb_config_ldbm = LMDB_LDBMConfig(topo.standalone)
434 userroot_ldbm = DSLdapObject(topo.standalone, DN_USERROOT_LDBM)
435 mdb_config_ldbm.set('nsslapd-cache-autosize', '0')
436
437 # Test with caches with both real values and 0
438 for cachesize in ('0', '33333333'):
439 autosize_val = mdb_config_ldbm.get_attr_val('nsslapd-cache-autosize')
440 cachememsize_val = userroot_ldbm.get_attr_val('nsslapd-cachememsize')
441 dncachesize_val = userroot_ldbm.get_attr_val('nsslapd-dncachememsize')
442
443 log.info("Check nsslapd-cachememsize before the test")
444 log.info("nsslapd-cachememsize == %s", cachememsize_val)
445 log.info("nsslapd-dncachememsize == %s", dncachesize_val)
446 log.info("nsslapd-cache-autosize == %s", autosize_val)
447 log.info("Set nsslapd-cachememsize to %s", cachesize)
448 userroot_ldbm.set('nsslapd-cachememsize', cachesize)
449 topo.standalone.restart()
450
451 autosize_val = mdb_config_ldbm.get_attr_val('nsslapd-cache-autosize')
452 cachememsize_val = userroot_ldbm.get_attr_val('nsslapd-cachememsize')
453 dncachesize_val = userroot_ldbm.get_attr_val('nsslapd-dncachememsize')
454
455 log.info("Check nsslapd-cachememsize in the appropriate range.")
456 log.info("nsslapd-cachememsize == %s", cachememsize_val)
457 log.info("nsslapd-dncachememsize == %s", dncachesize_val)
458 log.info("nsslapd-cache-autosize == %s", autosize_val)
459 assert int(cachememsize_val) >= 512000
460 assert int(dncachesize_val) >= 512000
461
462
463 @pytest.mark.skipif(get_default_db_lib() == "bdb",
464 reason="Not supported over bdb")
465 @pytest.mark.parametrize("invalid_value", ('-2', '102', 'invalid'))
466 def test_mdb_cache_autosize_invalid_values(topo, invalid_value):
467 """Check that we can't set invalid values to autosize attributes
468
469 :id: 266bf0e8-288b-4dee-9c4a-6967567bd815
470 :parametrized: yes
471 :setup: Standalone instance
472 :steps:
473 1. Stop the instance
474 2. Set in the cn=config,cn=ldbm database,cn=plugins,cn=config:
475 nsslapd-cache-autosize
476 to invalid values like (-2, 102, invalid_str)
477 3. Try to start the instance
478 :expectedresults:
479 1. The instance should stop successfully
480 2. nsslapd-cache-autosize is successfully set
481 3. Starting the instance should fail
482 """
483
484 mdb_config_ldbm = LMDB_LDBMConfig(topo.standalone)
485 autosize_val = mdb_config_ldbm.get_attr_val('nsslapd-cache-autosize')
486
487 log.info("Set nsslapd-cache-autosize to %s", invalid_value)
488 with pytest.raises(ldap.UNWILLING_TO_PERFORM):
489 mdb_config_ldbm.set('nsslapd-cache-autosize', invalid_value)
490 topo.standalone.restart()
491 mdb_config_ldbm.remove('nsslapd-cache-autosize', autosize_val)
492
493
494 def test_cache_autosize_multi_backends(topo):
495 """Check that autotuning cachesizes works properly with multiple backends
496
497 :id: 7f54544c-deae-479d-8569-d33498598e63
498 :parametrized: no
499 :setup: Standalone instance
500 :steps:
501 1. Set in the cn=config,cn=ldbm database,cn=plugins,cn=config
502 2. Set in the cn=UserRoot,cn=ldbm database,cn=plugins,cn=config:
503 nsslapd-cachememsize 0 and some same value
504 3. Restart the instance
505 4. Check nsslapd-dbcachesize and nsslapd-cachememsize
506 :expectedresults:
507 1. nsslapd-cache-autosize is successfully set
508 2. nsslapd-cachememsize is successfully set
509 3. The instance should be successfully restarted
510 4. nsslapd-cachememsize should set to value greater than 512KB
511 """
512
513 if get_default_db_lib() == "bdb":
514 config_ldbm = BDB_LDBMConfig(topo.standalone)
515 config_ldbm.set('nsslapd-dbcachesize', '0')
516 else:
517 config_ldbm = LMDB_LDBMConfig(topo.standalone)
518
519 userroot_ldbm = DSLdapObject(topo.standalone, DN_USERROOT_LDBM)
520 DN_SECONDROOT_LDBM = "cn=secondRoot,cn=ldbm database,cn=plugins,cn=config"
521 secondroot_ldbm = DSLdapObject(topo.standalone, DN_SECONDROOT_LDBM)
522 config_ldbm.set('nsslapd-cache-autosize', '0')
523 userroot_ldbm.set('nsslapd-cachememsize', '0')
524 topo.standalone.restart()
525
526 # Check current values with one backend
527 userroot_cachesize = userroot_ldbm.get_attr_val('nsslapd-cachememsize')
528 userroot_dncachesize = userroot_ldbm.get_attr_val('nsslapd-dncachememsize')
529
530 log.info("Check nsslapd-cachememsize before the test")
531 log.info("nsslapd-cachememsize == %s", int(userroot_cachesize))
532 log.info("nsslapd-dncachememsize == %s", int(userroot_dncachesize))
533
534 # Create second backend
535 backends = Backends(topo.standalone)
536 backends.create(properties={'nsslapd-suffix': "dc=second,dc=suffix",
537 'name': 'secondRoot',
538 'sample_entries': '001004002'})
539
540 # Add entries to both suffixes but add more to userroot, then restart
541 log.info("Adding users to userroot ...")
542 users = UserAccounts(topo.standalone, DEFAULT_SUFFIX)
543 for idx in range(1, 200):
544 users.create(properties={
545 'uid': f'testuser{idx}',
546 'cn': f'testuser{idx}',
547 'sn': f'user{idx}',
548 'uidNumber': str(1000 + idx),
549 'gidNumber': str(1000 + idx),
550 'homeDirectory': f'/home/testuser{idx}'
551 })
552 log.info("Adding users to secondroot ...")
553 users = UserAccounts(topo.standalone, "dc=second,dc=suffix")
554 for idx in range(1, 100):
555 users.create(properties={
556 'uid': f'testuser{idx}',
557 'cn': f'testuser{idx}',
558 'sn': f'user{idx}',
559 'uidNumber': str(1000 + idx),
560 'gidNumber': str(1000 + idx),
561 'homeDirectory': f'/home/testuser{idx}'
562 })
563 topo.standalone.restart()
564
565 userroot_cachesize_after = userroot_ldbm.get_attr_val('nsslapd-cachememsize')
566 userroot_dncachesize_after = userroot_ldbm.get_attr_val('nsslapd-dncachememsize')
567 secondroot_cachesize = secondroot_ldbm.get_attr_val('nsslapd-cachememsize')
568 secondroot_dncachesize = secondroot_ldbm.get_attr_val('nsslapd-dncachememsize')
569
570 log.info("Check cache sizes")
571 log.info("userroot before: nsslapd-cachememsize == %s",
572 int(userroot_cachesize))
573 log.info("userroot before: nsslapd-dncachememsize == %s",
574 int(userroot_dncachesize))
575 log.info("userroot after: nsslapd-cachememsize == %s",
576 int(userroot_cachesize_after))
577 log.info("userroot after: nsslapd-dncachememsize == %s",
578 int(userroot_dncachesize_after))
579 log.info("secondroot: nsslapd-cachememsize == %s",
580 int(secondroot_cachesize))
581 log.info("secondroot: nsslapd-dncachememsize == %s",
582 int(secondroot_dncachesize))
583
584 # Userroot cache sizes should be smaller now, and larger than secondRoot
585 # cache sizes
586 assert int(userroot_cachesize) > int(userroot_cachesize_after)
587 assert int(userroot_dncachesize) > int(userroot_dncachesize_after)
588 assert int(userroot_cachesize_after) != int(secondroot_cachesize)
589 assert int(userroot_dncachesize_after) != int(secondroot_dncachesize)
590 assert int(secondroot_cachesize) >= 512000
591 assert int(secondroot_dncachesize) >= 512000
592
593 #
594 # Now test with a specific autosize value
595 #
596 config_ldbm.set('nsslapd-cache-autosize', '30')
597 topo.standalone.restart()
598
599 userroot_cachesize = userroot_ldbm.get_attr_val('nsslapd-cachememsize')
600 userroot_dncachesize = userroot_ldbm.get_attr_val('nsslapd-dncachememsize')
601 secondroot_cachesize = secondroot_ldbm.get_attr_val('nsslapd-cachememsize')
602 secondroot_dncachesize = secondroot_ldbm.get_attr_val('nsslapd-dncachememsize')
603
604 log.info("Check cache sizes")
605 log.info("userroot: nsslapd-cachememsize == %s",
606 int(userroot_cachesize))
607 log.info("userroot: nsslapd-dncachememsize == %s",
608 int(userroot_dncachesize))
609 log.info("secondroot: nsslapd-cachememsize == %s",
610 int(secondroot_cachesize))
611 log.info("secondroot: nsslapd-dncachememsize == %s",
612 int(secondroot_dncachesize))
613
614 # Test cache sizes
615 assert int(userroot_cachesize) > int(secondroot_cachesize)
616 assert int(userroot_dncachesize) > int(secondroot_dncachesize)
617 assert int(secondroot_cachesize) >= 512000
618 assert int(secondroot_dncachesize) >= 512000
619
620 # Now test that manual cache mem size values stick
621 config_ldbm.set('nsslapd-cache-autosize', '0')
622 userroot_ldbm.set('nsslapd-cachememsize', '77777777')
623 topo.standalone.restart()
624 userroot_cachesize = userroot_ldbm.get_attr_val('nsslapd-cachememsize')
625 assert int(userroot_cachesize) == 77777777
626
627 # Test cache tune reset
628 userroot_ldbm.set('nsslapd-cachememsize', '0')
629 topo.standalone.restart()
630 userroot_cachesize = userroot_ldbm.get_attr_val('nsslapd-cachememsize')
631 assert int(userroot_cachesize) != 77777777
632
633 if __name__ == '__main__':
634 # Run isolated
635 # -s for DEBUG mode
636 CURRENT_FILE = os.path.realpath(__file__)
637 pytest.main("-s %s" % CURRENT_FILE)