Debian Codegraph @

dirsrvtests/tests/suites/clu/dsconf_logging_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 json
10 import subprocess
11 import logging
12 import pytest
13 from lib389._constants import DN_DM
14 from test389.topologies import topology_st as topo
15
16 pytestmark = pytest.mark.tier1
17
18 log = logging.getLogger(__name__)
19
20 SETTINGS = [
21 ('logging-enabled', None),
22 ('logging-disabled', None),
23 ('mode', '700'),
24 ('compress-enabled', None),
25 ('compress-disabled', None),
26 ('buffering-enabled', None),
27 ('buffering-disabled', None),
28 ('max-logs', '4'),
29 ('max-logsize', '7'),
30 ('rotation-interval', '2'),
31 ('rotation-interval-unit', 'week'),
32 ('rotation-tod-enabled', None),
33 ('rotation-tod-disabled', None),
34 ('rotation-tod-hour', '12'),
35 ('rotation-tod-minute', '20'),
36 ('deletion-interval', '3'),
37 ('deletion-interval-unit', 'day'),
38 ('max-disk-space', '20'),
39 ('free-disk-space', '2'),
40 ]
41
42 DEFAULT_TIME_FORMAT = "%FT%TZ"
43
44
45 def execute_dsconf_command(dsconf_cmd, subcommands):
46 """Execute dsconf command and return output and return code"""
47
48 cmdline = dsconf_cmd + subcommands
49 proc = subprocess.Popen(cmdline, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
50 out, err = proc.communicate()
51
52 if proc.returncode != 0 and err:
53 log.error(f"Command failed: {' '.join(cmdline)}")
54 log.error(f"Stderr: {err.decode('utf-8')}")
55
56 return out.decode('utf-8'), proc.returncode
57
58
59 def get_dsconf_base_cmd(topo):
60 """Return base dsconf command list"""
61 return ['/usr/sbin/dsconf', topo.standalone.serverid,
62 '-j', '-D', DN_DM, '-w', 'password', 'logging']
63
64
65 @pytest.mark.parametrize("log_type", ['access', 'audit', 'auditfail', 'error', 'security'])
66 def test_log_settings(topo, log_type):
67 """Test each log setting can be set successfully
68
69 :id: b800fd03-37f5-4e74-9af8-eeb07030eb52
70 :setup: Standalone DS instance
71 :steps:
72 1. Test each log's settings
73 :expectedresults:
74 1. Success
75 """
76
77 dsconf_cmd = get_dsconf_base_cmd(topo)
78
79 output, rc = execute_dsconf_command(dsconf_cmd, [log_type, 'get'])
80 assert rc == 0
81 json_result = json.loads(output)
82 default_location = json_result['Log name and location']
83
84 output, rc = execute_dsconf_command(dsconf_cmd, [log_type, 'set',
85 'location',
86 f'/tmp/{log_type}'])
87 assert rc == 0
88 output, rc = execute_dsconf_command(dsconf_cmd, [log_type, 'set',
89 'location',
90 default_location])
91 assert rc == 0
92
93 if log_type == "access":
94 output, rc = execute_dsconf_command(dsconf_cmd,
95 [log_type, 'list-levels'])
96 assert rc == 0
97
98 output, rc = execute_dsconf_command(dsconf_cmd,
99 [log_type, 'set', 'level',
100 'internal'])
101 assert rc == 0
102 output, rc = execute_dsconf_command(dsconf_cmd,
103 [log_type, 'set', 'level',
104 'internal', 'entry'])
105 assert rc == 0
106 output, rc = execute_dsconf_command(dsconf_cmd,
107 [log_type, 'set', 'level',
108 'internal', 'default'])
109 assert rc == 0
110
111 if log_type == "error":
112 output, rc = execute_dsconf_command(dsconf_cmd,
113 [log_type, 'list-levels'])
114 assert rc == 0
115
116 output, rc = execute_dsconf_command(dsconf_cmd,
117 [log_type, 'set', 'level',
118 'plugin', 'replication'])
119 assert rc == 0
120 output, rc = execute_dsconf_command(dsconf_cmd,
121 [log_type, 'set', 'level',
122 'default'])
123 assert rc == 0
124
125 if log_type in ["access", "audit", "error"]:
126 output, rc = execute_dsconf_command(dsconf_cmd,
127 [log_type, 'set',
128 'time-format', '%D'])
129 assert rc == 0
130 output, rc = execute_dsconf_command(dsconf_cmd,
131 [log_type, 'set',
132 'time-format',
133 DEFAULT_TIME_FORMAT])
134 assert rc == 0
135
136 output, rc = execute_dsconf_command(dsconf_cmd,
137 [log_type, 'set',
138 'log-format',
139 'json'])
140 assert rc == 0, f"Failed to set {log_type} log-format to json: {output}"
141
142 output, rc = execute_dsconf_command(dsconf_cmd,
143 [log_type, 'set',
144 'log-format',
145 'default'])
146 assert rc == 0, f"Failed to set {log_type} log-format to default: {output}"
147
148 if log_type == "audit":
149 output, rc = execute_dsconf_command(dsconf_cmd,
150 [log_type, 'set',
151 'display-attrs', 'cn'])
152 assert rc == 0
153
154 for attr, value in SETTINGS:
155 if log_type == "auditfail" and attr.startswith("buffer"):
156 continue
157
158 if value is None:
159 output, rc = execute_dsconf_command(dsconf_cmd, [log_type,
160 'set', attr])
161 else:
162 output, rc = execute_dsconf_command(dsconf_cmd, [log_type,
163 'set', attr, value])
164 assert rc == 0