Skip to content

Commit

Permalink
Issue 5843 - Fix size formatting in dscreate output and enhance tests (
Browse files Browse the repository at this point in the history
…#6309)

Description:
Fix the size formatting in `get_default_mdb_max_size` within `utils.py` to ensure `dscreate` displays the correct value in both interactive and create-template installs.
Additionally, improve and fix related LMDB configuration tests to validate the correctness of size handling. Fix typos in the test descriptions.

Relates: #5843

Reviewed by: @progier389 (Thanks!)
  • Loading branch information
droideck committed Aug 27, 2024
1 parent 2cf519d commit b3b72a3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
25 changes: 18 additions & 7 deletions dirsrvtests/tests/suites/config/config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ def test_ignore_virtual_attrs_after_restart(topo):
assert topo.standalone.config.present('nsslapd-ignore-virtual-attrs', 'off')

def test_ndn_cache_enabled(topo):
"""Test nsslapd-ignore-virtual-attrs configuration attribute
"""Check the behavior of the Normalized DN cache when enabled/disabled
:id: 2caa3ec0-cd05-458e-9e21-3b73cf4697ff
:setup: Standalone instance
Expand Down Expand Up @@ -499,7 +499,7 @@ def test_ndn_cache_enabled(topo):


def test_require_index(topo):
"""Test nsslapd-ignore-virtual-attrs configuration attribute
"""Validate that unindexed searches are rejected
:id: fb6e31f2-acc2-4e75-a195-5c356faeb803
:setup: Standalone instance
Expand Down Expand Up @@ -533,7 +533,7 @@ def test_require_index(topo):

@pytest.mark.skipif(ds_is_older('1.4.2'), reason="The config setting only exists in 1.4.2 and higher")
def test_require_internal_index(topo):
"""Test nsslapd-ignore-virtual-attrs configuration attribute
"""Ensure internal operations require indexed attributes
:id: 22b94f30-59e3-4f27-89a1-c4f4be036f7f
:setup: Standalone instance
Expand Down Expand Up @@ -610,7 +610,7 @@ def check_number_of_threads(cfgnbthreads, monitor, pid):
log.info('pstack is not installed ==> skipping pstack test.')

def test_changing_threadnumber(topo):
"""Test nsslapd-ignore-virtual-attrs configuration attribute
"""Validate thread number changes in the server configuration
:id: 11bcf426-061c-11ee-8c22-482ae39447e5
:setup: Standalone instance
Expand Down Expand Up @@ -700,14 +700,14 @@ def set_and_check(inst, db_config, dsconf_attr, ldap_attr, val):


def test_lmdb_config(create_lmdb_instance):
"""Test nsslapd-ignore-virtual-attrs configuration attribute
"""Verify LMDB configuration settings in custom instance
:id: bca28086-61cf-11ee-a064-482ae39447e5
:setup: Custom instance named 'i_lmdb' having db_lib=mdb and lmdb_size=0.5
:steps:
1. Get dscreate create-template output
2. Check that 'db_lib' is in output
3. Check that 'lmdb_size' is in output
3. Extract 'mdb_max_size' from output and verify it's correct
4. Get the database config
5. Check that nsslapd-backend-implement is mdb
6. Check that nsslapd-mdb-max-size is 536870912 (i.e 0.5Gb)
Expand All @@ -730,7 +730,18 @@ def test_lmdb_config(create_lmdb_instance):
stderr=subprocess.STDOUT, encoding='utf-8')
inst = create_lmdb_instance
assert 'db_lib' in res.stdout
assert 'mdb_max_size' in res.stdout

# Extract the mdb_max_size value from the output
mdb_max_size_line = next(line for line in res.stdout.splitlines() if 'mdb_max_size =' in line)
mdb_max_size_value = mdb_max_size_line.split('=')[1].strip()

# Parse the mdb_max_size value to int and back
parsed_size = parse_size(mdb_max_size_value)
formatted_size = format_size(parsed_size)

# Assert the original value and the processed value are the same
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}"

db_config = DatabaseConfig(inst)
cfg_vals = db_config.get()
assert 'nsslapd-backend-implement' in cfg_vals
Expand Down
2 changes: 1 addition & 1 deletion src/lib389/lib389/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1769,7 +1769,7 @@ def get_default_mdb_max_size(paths):
avail = statvfs.f_frsize * statvfs.f_bavail
avail *= 0.8 # Reserve 20% as margin
if size > avail:
mdb_max_size = str(avail)
mdb_max_size = format_size(avail)
except (TimeoutError, InterruptedError) as e:
raise e
except OSError as e:
Expand Down

0 comments on commit b3b72a3

Please sign in to comment.