Debian Codegraph @

dirsrvtests/tests/suites/config/regression_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 os
10 import logging
11 import pytest
12 import time
13 from lib389._mapped_object import DSLdapObject
14 from lib389.utils import *
15 from lib389.dseldif import DSEldif
16 from lib389.config import BDB_LDBMConfig, LMDB_LDBMConfig, LDBMConfig, Config
17 from lib389.backend import Backends
18 from test389.topologies import topology_st as topo
19 from lib389.idm.user import UserAccounts, TEST_USER_PROPERTIES
20 from lib389._constants import DEFAULT_SUFFIX, PASSWORD, DN_DM
21
22 pytestmark = pytest.mark.tier0
23
24 logging.getLogger(__name__).setLevel(logging.INFO)
25 log = logging.getLogger(__name__)
26
27 DEBUGGING = os.getenv("DEBUGGING", default=False)
28 CUSTOM_MEM = '9100100100'
29 IDLETIMEOUT = 5
30 DN_TEST_USER = f'uid={TEST_USER_PROPERTIES["uid"]},ou=People,{DEFAULT_SUFFIX}'
31
32 RO_ATTR = 'nsslapd-readonly'
33
34
35 @pytest.fixture(scope="module")
36 def idletimeout_topo(topo, request):
37 """Create an instance with a test user and set idletimeout"""
38 inst = topo.standalone
39 config = Config(inst)
40
41 users = UserAccounts(inst, DEFAULT_SUFFIX)
42 user = users.create(properties={
43 **TEST_USER_PROPERTIES,
44 'userpassword' : PASSWORD,
45 })
46 config.replace('nsslapd-idletimeout', str(IDLETIMEOUT))
47
48 def fin():
49 if not DEBUGGING:
50 config.reset('nsslapd-idletimeout')
51 user.delete()
52
53 request.addfinalizer(fin)
54 return topo
55
56
57 # Function to return value of available memory in kb
58 def get_available_memory():
59 with open('/proc/meminfo') as file:
60 for line in file:
61 if 'MemAvailable' in line:
62 free_mem_in_kb = line.split()[1]
63 return int(free_mem_in_kb)
64
65
66 @pytest.mark.skipif(get_available_memory() < (int(CUSTOM_MEM)/1024), reason="available memory is too low")
67 def test_set_cachememsize_to_custom_value(topo):
68 """Test if value nsslapd-cachememsize remains set
69 at the custom setting of value above 3805132804 bytes
70 after changing the value to 9100100100 bytes
71
72 :id: 8a3efc00-65a9-4ee7-b8ee-e35840991ea9
73 :setup: Standalone Instance
74 :steps:
75 1. Disable in the cn=config,cn=ldbm database,cn=plugins,cn=config:
76 nsslapd-cache-autosize by setting it to 0
77 2. Disable in the cn=config,cn=ldbm database,cn=plugins,cn=config:
78 nsslapd-cache-autosize-split by setting it to 0
79 3. Restart the instance
80 4. Set in the cn=UserRoot,cn=ldbm database,cn=plugins,cn=config:
81 nsslapd-cachememsize: CUSTOM_MEM
82 :expectedresults:
83 1. nsslapd-cache-autosize is successfully disabled
84 2. nsslapd-cache-autosize-split is successfully disabled
85 3. The instance should be successfully restarted
86 4. nsslapd-cachememsize is successfully set
87 """
88
89 if get_default_db_lib() == "bdb":
90 config_ldbm = BDB_LDBMConfig(topo.standalone)
91 config_ldbm.set('nsslapd-dbcachesize', '0')
92 else:
93 config_ldbm = LMDB_LDBMConfig(topo.standalone)
94
95 backends = Backends(topo.standalone)
96 userroot_ldbm = backends.get("userroot")
97
98 log.info("Disabling nsslapd-cache-autosize by setting it to 0")
99 assert config_ldbm.set('nsslapd-cache-autosize', '0')
100
101 log.info("Disabling nsslapd-cache-autosize-split by setting it to 0")
102 assert config_ldbm.set('nsslapd-cache-autosize-split', '0')
103
104 log.info("Restarting instance")
105 topo.standalone.restart()
106 log.info("Instance restarted successfully")
107
108 log.info("Set nsslapd-cachememsize to value {}".format(CUSTOM_MEM))
109 assert userroot_ldbm.set('nsslapd-cachememsize', CUSTOM_MEM)
110
111
112 def test_maxbersize_repl(topo):
113 """Check that instance starts when nsslapd-errorlog-maxlogsize
114 nsslapd-errorlog-logmaxdiskspace are set in certain order
115
116 :id: 743e912c-2be4-4f5f-9c2a-93dcb18f51a0
117 :setup: Standalone Instance
118 :steps:
119 1. Stop the instance
120 2. Set nsslapd-errorlog-maxlogsize before/after
121 nsslapd-errorlog-logmaxdiskspace
122 3. Start the instance
123 4. Check the error log for errors
124 :expectedresults:
125 1. Success
126 2. Success
127 3. Success
128 4. The error log should contain no errors
129 """
130
131 inst = topo.standalone
132 dse_ldif = DSEldif(inst)
133
134 inst.stop()
135 log.info("Set nsslapd-errorlog-maxlogsize before nsslapd-errorlog-logmaxdiskspace")
136 dse_ldif.replace('cn=config', 'nsslapd-errorlog-maxlogsize', '300')
137 dse_ldif.replace('cn=config', 'nsslapd-errorlog-logmaxdiskspace', '500')
138 inst.start()
139 log.info("Assert no init_dse_file errors in the error log")
140 assert not inst.ds_error_log.match('.*ERR - init_dse_file.*')
141
142 inst.stop()
143 log.info("Set nsslapd-errorlog-maxlogsize after nsslapd-errorlog-logmaxdiskspace")
144 dse_ldif.replace('cn=config', 'nsslapd-errorlog-logmaxdiskspace', '500')
145 dse_ldif.replace('cn=config', 'nsslapd-errorlog-maxlogsize', '300')
146 inst.start()
147 log.info("Assert no init_dse_file errors in the error log")
148 assert not inst.ds_error_log.match('.*ERR - init_dse_file.*')
149
150
151 def test_bdb_config(topo):
152 """Check that bdb config entry exists
153
154 :id: edbc6f54-7c98-11ee-b1c0-482ae39447e5
155 :setup: standalone
156 :steps:
157 1. Check that bdb config instance exists.
158 :expectedresults:
159 1. Success
160 """
161
162 inst = topo.standalone
163 assert BDB_LDBMConfig(inst).exists()
164
165
166 @pytest.mark.parametrize("dn,expected_result", [(DN_TEST_USER, True), (DN_DM, False)])
167 def test_idletimeout(idletimeout_topo, dn, expected_result):
168 """Check that bdb config entry exists
169
170 :id: b20f2826-942a-11ee-827b-482ae39447e5
171 :parametrized: yes
172 :setup: Standalone Instance with test user and idletimeout
173 :steps:
174 1. Open new ldap connection
175 2. Bind with the provided dn
176 3. Wait longer than idletimeout
177 4. Try to bind again the provided dn and check if
178 connection is closed or not.
179 5. Check if result is the expected one.
180 :expectedresults:
181 1. Success
182 2. Success
183 3. Success
184 4. Success
185 5. Success
186 """
187
188 inst = idletimeout_topo.standalone
189
190 l = ldap.initialize(f'ldap://localhost:{inst.port}')
191 l.bind_s(dn, PASSWORD)
192 time.sleep(IDLETIMEOUT+1)
193 try:
194 l.bind_s(dn, PASSWORD)
195 result = False
196 except ldap.SERVER_DOWN:
197 result = True
198 assert expected_result == result
199
200
201 def test_instance_readonly_mode(topo):
202 """Check that readonly mode is supported
203
204 :id: 34d2e28e-04d7-11f0-b0cf-482ae39447e5
205 :setup: Standalone Instance
206 :steps:
207 1. Set readonly mode
208 2. Stop the instance
209 3. Get dse.ldif modification time
210 4. Start the instance
211 5. Get dse.ldif modification time
212 6. Check that modification time has not changed
213 7. Check that readonly mode is set
214 8. Try to modify another config attribute
215 9. Unset readonly mode
216 10. Restart the instance
217 11. Check that modification time has not changed
218 12. Check that modification time has changed
219 13. Check that readonly mode is unset
220 14. Try to modify another config attribute
221 :expectedresults:
222 1. Success
223 2. Success
224 3. Success
225 4. Success
226 5. Success
227 6. Success
228 7. Success
229 8. Should get ldap.UNWILLING_TO_PERFORM exception
230 9. Success
231 10. Success
232 11. Success
233 12. Success
234 13. Success
235 14. Success
236 """
237
238 inst = topo.standalone
239 dse_path = f'{topo.standalone.get_config_dir()}/dse.ldif'
240 inst.config.replace(RO_ATTR, 'on')
241 inst.stop()
242 dse_mtime = os.stat(dse_path).st_mtime
243 inst.start()
244 new_dse_mtime = os.stat(dse_path).st_mtime
245 assert dse_mtime == new_dse_mtime
246 assert inst.config.get_attr_val_utf8(RO_ATTR) == "on"
247 attr = 'nsslapd-errorlog-maxlogsize'
248 val = inst.config.get_attr_val_utf8(attr)
249 with pytest.raises(ldap.UNWILLING_TO_PERFORM):
250 inst.config.replace(attr, val)
251 inst.config.replace(RO_ATTR, 'off')
252 inst.restart()
253 new_dse_mtime = os.stat(dse_path).st_mtime
254 assert dse_mtime != new_dse_mtime
255 assert inst.config.get_attr_val_utf8(RO_ATTR) == "off"
256 inst.config.replace(attr, val)