Debian Codegraph @

dirsrvtests/tests/suites/clu/dsconf_backend_dynamic_lists_test.py

raw
1
2 # --- BEGIN COPYRIGHT BLOCK ---
3 # Copyright (C) 2025 Red Hat, Inc.
4 # All rights reserved.
5 #
6 # License: GPL (version 3 or any later version).
7 # See LICENSE for details.
8 # --- END COPYRIGHT BLOCK ---
9 #
10 """Test dsconf CLI with Dynamic Lists configuration"""
11
12 import json
13 import os
14 import subprocess
15 import logging
16 import pytest
17 from lib389._constants import DN_DM
18 from test389.topologies import topology_st as topo
19
20 pytestmark = pytest.mark.tier1
21
22 log = logging.getLogger(__name__)
23
24 # Dynamic Lists configuration options to test
25 DYNAMIC_LISTS_SETTINGS = [
26 ('dynamic-oc', 'GroupOfUrls'),
27 ('dynamic-url-attr', 'MemberUrl'),
28 ('dynamic-list-attr', 'uniquemember'),
29 ('enable-dynamic-lists', None),
30 ('disable-dynamic-lists', None),
31 ]
32
33
34 def execute_dsconf_command(dsconf_cmd, subcommands):
35 """Execute dsconf command and return output and return code"""
36
37 cmdline = dsconf_cmd + subcommands
38 proc = subprocess.Popen(cmdline, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
39 out, err = proc.communicate()
40
41 if proc.returncode != 0 and err:
42 log.error(f"Command failed: {' '.join(cmdline)}")
43 log.error(f"Stderr: {err.decode('utf-8')}")
44
45 return out.decode('utf-8'), proc.returncode
46
47
48 def get_dsconf_base_cmd(topo):
49 """Return base dsconf command list"""
50 return ['/usr/sbin/dsconf', topo.standalone.serverid,
51 '-j', '-D', DN_DM, '-w', 'password', 'backend', 'config']
52
53
54 @pytest.mark.parametrize("attr,value", DYNAMIC_LISTS_SETTINGS)
55 def test_dynamic_lists_plugin_set(topo, attr, value):
56 """Test dynamic lists plugin set command with various configuration options
57
58 :id: 8e9fd0d8-bc96-43f0-8119-e18286a325e5
59 :setup: Standalone DS instance
60 :steps:
61 1. Set various dynamic lists plugin configuration options
62 2. Verify the setting was applied
63 :expectedresults:
64 1. Success
65 2. Success
66 """
67
68 dsconf_cmd = get_dsconf_base_cmd(topo)
69
70 # Build the set command
71 if value is None:
72 set_cmd = ['set', f'--{attr}']
73 else:
74 set_cmd = ['set', f'--{attr}', value]
75
76 # Set the configuration
77 output, rc = execute_dsconf_command(dsconf_cmd, set_cmd)
78 assert rc == 0, f"Failed to set {attr}={value}: {output}"
79 log.info(f"Set {attr}={value} successfully")
80
81 # Verify the setting was applied by getting the configuration
82 output, rc = execute_dsconf_command(dsconf_cmd, ['get'])
83 assert rc == 0
84 json_result = json.loads(output)
85
86 # Check if the attribute was set correctly
87 # Map CLI argument names to LDAP attribute names
88 attr_map = {
89 'dynamic-oc': 'nsslapd-dynamic-lists-oc',
90 'dynamic-url-attr': 'nsslapd-dynamic-lists-url-attr',
91 'dynamic-list-attr': 'nsslapd-dynamic-lists-attr',
92 'enable-dynamic-lists': 'nsslapd-dynamic-lists-enabled',
93 'disable-dynamic-lists': 'nsslapd-dynamic-lists-enabled',
94 }
95 ldap_attr = attr_map.get(attr)
96 assert ldap_attr and 'attrs' in json_result
97 config_value = json_result['attrs'].get(ldap_attr)
98 assert config_value is not None
99 if isinstance(config_value, list):
100 config_value = config_value[0]
101
102 if value is None:
103 if attr == 'enable-dynamic-lists':
104 assert config_value == 'on', f"Expected 'on', got {config_value}"
105 elif attr == 'disable-dynamic-lists':
106 assert config_value == 'off', f"Expected 'off', got {config_value}"
107 else:
108 assert config_value == value, f"Expected {value} in {config_value}"
109
110
111 if __name__ == '__main__':
112 # Run isolated
113 # -s for DEBUG mode
114 CURRENT_FILE = os.path.realpath(__file__)
115 pytest.main(["-s", CURRENT_FILE])
116