Skip to content

Commit

Permalink
Issue 6468 - RFE - CLI - Add logging settings to dsconf
Browse files Browse the repository at this point in the history
Description:

It would be nice to have a more friendly CLI interface for managing the server
logging. Specifically the log levels. This PR adds a new subcommand "logging"
that can handle each log type and allthe settings for it.

relates: #6468

Reviewed by: spichugi(Thanks!)
  • Loading branch information
mreynolds389 committed Jan 6, 2025
1 parent c8eda6f commit e3fe994
Show file tree
Hide file tree
Showing 3 changed files with 889 additions and 2 deletions.
168 changes: 168 additions & 0 deletions dirsrvtests/tests/suites/clu/dsconf_logging.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
# --- BEGIN COPYRIGHT BLOCK ---
# Copyright (C) 2025 Red Hat, Inc.
# All rights reserved.
#
# License: GPL (version 3 or any later version).
# See LICENSE for details.
# --- END COPYRIGHT BLOCK ---
#
import json
import subprocess
import logging
import pytest
from lib389._constants import DN_DM
from lib389.topologies import topology_st as topo

pytestmark = pytest.mark.tier1

log = logging.getLogger(__name__)

SETTINGS = [
('logging-enabled', None),
('logging-disabled', None),
('mode', '700'),
('compress-enabled', None),
('compress-disabled', None),
('buffering-enabled', None),
('buffering-disabled', None),
('max-logs', '4'),
('max-logsize', '7'),
('rotation-interval', '2'),
('rotation-interval-unit', 'week'),
('rotation-tod-enabled', None),
('rotation-tod-disabled', None),
('rotation-tod-hour', '12'),
('rotation-tod-minute', '20'),
('deletion-interval', '3'),
('deletion-interval-unit', 'day'),
('max-disk-space', '20'),
('free-disk-space', '2'),
]

DEFAULT_TIME_FORMAT = "%FT%TZ"


def execute_dsconf_command(dsconf_cmd, subcommands):
"""Execute dsconf command and return output and return code"""

cmdline = dsconf_cmd + subcommands
proc = subprocess.Popen(cmdline, stdout=subprocess.PIPE)
out, _ = proc.communicate()
return out.decode('utf-8'), proc.returncode


def get_dsconf_base_cmd(topo):
"""Return base dsconf command list"""
return ['/usr/sbin/dsconf', topo.standalone.serverid,
'-j', '-D', DN_DM, '-w', 'password', 'logging']


def test_log_settings(topo):
"""Test each log setting can be set successfully
:id: b800fd03-37f5-4e74-9af8-eeb07030eb52
:setup: Standalone DS instance
:steps:
1. Test each log's settings
:expectedresults:
1. Success
"""

dsconf_cmd = get_dsconf_base_cmd(topo)
for log_type in ['access', 'audit', 'auditfail', 'error', 'security']:
# Test "get" command
output, rc = execute_dsconf_command(dsconf_cmd, [log_type, 'get'])
assert rc == 0
json_result = json.loads(output)
default_location = json_result['Log name and location']

# Log location
output, rc = execute_dsconf_command(dsconf_cmd, [log_type, 'set',
'location',
f'/tmp/{log_type}'])
assert rc == 0
output, rc = execute_dsconf_command(dsconf_cmd, [log_type, 'set',
'location',
default_location])
assert rc == 0

# Log levels
if log_type == "access":
# List levels
output, rc = execute_dsconf_command(dsconf_cmd,
[log_type, 'list-levels'])
assert rc == 0

# Set levels
output, rc = execute_dsconf_command(dsconf_cmd,
[log_type, 'set', 'level',
'internal'])
assert rc == 0
output, rc = execute_dsconf_command(dsconf_cmd,
[log_type, 'set', 'level',
'internal', 'entry'])
assert rc == 0
output, rc = execute_dsconf_command(dsconf_cmd,
[log_type, 'set', 'level',
'internal', 'default'])
assert rc == 0

if log_type == "error":
# List levels
output, rc = execute_dsconf_command(dsconf_cmd,
[log_type, 'list-levels'])
assert rc == 0

# Set levels
output, rc = execute_dsconf_command(dsconf_cmd,
[log_type, 'set', 'level',
'plugin', 'replication'])
assert rc == 0
output, rc = execute_dsconf_command(dsconf_cmd,
[log_type, 'set', 'level',
'default'])
assert rc == 0

# Log formats
if log_type in ["access", "audit"]:
output, rc = execute_dsconf_command(dsconf_cmd,
[log_type, 'set',
'time-format', '%D'])
assert rc == 0
output, rc = execute_dsconf_command(dsconf_cmd,
[log_type, 'set',
'time-format',
DEFAULT_TIME_FORMAT])
assert rc == 0

output, rc = execute_dsconf_command(dsconf_cmd,
[log_type, 'set',
'log-format',
'json'])
assert rc == 0
output, rc = execute_dsconf_command(dsconf_cmd,
[log_type, 'set',
'log-format',
'default'])
assert rc == 0

# Audit log display attrs
if log_type == "audit":
output, rc = execute_dsconf_command(dsconf_cmd,
[log_type, 'set',
'display-attrs', 'cn'])
assert rc == 0

# Common settings
for attr, value in SETTINGS:
if log_type == "auditfail" and attr.startswith("buffer"):
# auditfail doesn't have a buffering settings
continue

if value is None:
output, rc = execute_dsconf_command(dsconf_cmd, [log_type,
'set', attr])
else:
output, rc = execute_dsconf_command(dsconf_cmd, [log_type,
'set', attr, value])
assert rc == 0
6 changes: 4 additions & 2 deletions src/lib389/cli/dsconf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/python3

# --- BEGIN COPYRIGHT BLOCK ---
# Copyright (C) 2020 Red Hat, Inc.
# Copyright (C) 2020-2025 Red Hat, Inc.
# All rights reserved.
#
# License: GPL (version 3 or any later version).
Expand All @@ -19,6 +19,7 @@ from lib389._constants import DSRC_HOME
from lib389.cli_conf import config as cli_config
from lib389.cli_conf import backend as cli_backend
from lib389.cli_conf import directory_manager as cli_directory_manager
from lib389.cli_conf import logging as cli_logs
from lib389.cli_conf import plugin as cli_plugin
from lib389.cli_conf import schema as cli_schema
from lib389.cli_conf import monitor as cli_monitor
Expand Down Expand Up @@ -73,14 +74,15 @@ cli_backup.create_parser(subparsers)
cli_chaining.create_parser(subparsers)
cli_config.create_parser(subparsers)
cli_directory_manager.create_parsers(subparsers)
cli_logs.create_parser(subparsers)
cli_monitor.create_parser(subparsers)
cli_plugin.create_parser(subparsers)
cli_pwpolicy.create_parser(subparsers)
cli_replication.create_parser(subparsers)
cli_repl_conflicts.create_parser(subparsers)
cli_sasl.create_parser(subparsers)
cli_security.create_parser(subparsers)
cli_schema.create_parser(subparsers)
cli_repl_conflicts.create_parser(subparsers)

argcomplete.autocomplete(parser)

Expand Down
Loading

0 comments on commit e3fe994

Please sign in to comment.