def _complete_logging_config(
- interactive: bool, destinations: Optional[List[str]]
+ interactive: bool, destinations: Optional[List[str]],
+ logging_level: str = 'debug',
) -> Dict[str, Any]:
"""Return a logging configuration dict, based on the runtime parameters
cephadm was invoked with.
if interactive:
lc = _copy(_interactive_logging_config)
+ # Override the default 'debug' level with the logging level cephadm received
+ if logging_level == 'info':
+ lc['handlers']['log_file']['level'] = 'INFO'
+
handlers = lc['loggers']['']['handlers']
if not destinations:
handlers.append(LogDestination.file.value)
if not os.path.exists(LOG_DIR):
os.makedirs(LOG_DIR)
+ logging_level = getattr(ctx, 'logging_level', 'debug').lower()
lc = _complete_logging_config(
any(op in args for op in _INTERACTIVE_CMDS),
getattr(ctx, 'log_dest', None),
+ logging_level=logging_level,
)
logging.config.dictConfig(lc)
desc="Destination for cephadm command persistent logging",
enum_allowed=['file', 'syslog', 'file,syslog'],
),
+ Option(
+ 'cephadm_binary_logging_level',
+ type='str',
+ default='debug',
+ desc='Logging verbosity for the cephadm binary when invoked by the mgr (e.g. check-host, gather-facts).',
+ enum_allowed=['info', 'debug', 'error', 'warning']
+ ),
Option(
'oob_default_addr',
type='str',
self.certificate_automated_rotation_enabled = False
self.certificate_check_debug_mode = False
self.certificate_check_period = 0
+ self.cephadm_binary_logging_level = 'debug'
self.notify(NotifyType.mon_map, None)
self.config_notify()
assert wait(cephadm_module, c) == ['Scheduled osd.foo update...']
cephadm_module.set_osd_spec('osd.foo', ['1'])
+
+
+class TestCephadmBinaryLoggingLevel:
+ """Test that host-status / cephadm binary logs are suppressed or shown based on
+ mgr/cephadm/cephadm_binary_logging_level (info vs debug).
+ """
+ @mock.patch("cephadm.ssh.SSHManager._remote_connection")
+ @mock.patch("cephadm.ssh.SSHManager._execute_command")
+ @mock.patch("cephadm.ssh.SSHManager._check_execute_command")
+ def test_check_host_invokes_cephadm_with_logging_level_info(
+ self, check_execute_command, execute_command, remote_connection, cephadm_module
+ ):
+ """When cephadm_binary_logging_level is info, check-host must be invoked with
+ --logging-level info so host-status DEBUG logs are suppressed in cephadm.log.
+ """
+ remote_connection.side_effect = async_side_effect(mock.Mock())
+ captured_commands = []
+
+ async def capture_execute(host, cmd, *args, **kwargs):
+ if hasattr(cmd, 'args') and 'check-host' in cmd.args:
+ captured_commands.append(cmd)
+ return ('', '', 0)
+
+ execute_command.side_effect = capture_execute
+
+ orig_get = cephadm_module.get_module_option
+
+ def get_opt(key, default=None):
+ if key == 'cephadm_binary_logging_level':
+ return 'info'
+ return orig_get(key, default)
+
+ with mock.patch.object(cephadm_module, 'get_module_option', side_effect=get_opt):
+ with with_host(cephadm_module, 'test'):
+ pass
+
+ check_host_cmds = [c for c in captured_commands if 'check-host' in c.args]
+ assert len(check_host_cmds) >= 1, 'expected at least one check-host invocation'
+ cmd = check_host_cmds[0]
+ assert '--logging-level' in cmd.args, (
+ 'cephadm should be called with --logging-level when level is info'
+ )
+ idx = cmd.args.index('--logging-level')
+ assert cmd.args[idx + 1] == 'info', (
+ 'host-status logs should be suppressed with logging-level info'
+ )
+
+ @mock.patch("cephadm.ssh.SSHManager._remote_connection")
+ @mock.patch("cephadm.ssh.SSHManager._execute_command")
+ @mock.patch("cephadm.ssh.SSHManager._check_execute_command")
+ def test_check_host_invokes_cephadm_with_logging_level_debug(
+ self, check_execute_command, execute_command, remote_connection, cephadm_module
+ ):
+ """When cephadm_binary_logging_level is debug, check-host must be invoked with
+ --logging-level debug so current (verbose) host-status logging continues.
+ """
+ remote_connection.side_effect = async_side_effect(mock.Mock())
+ captured_commands = []
+
+ async def capture_execute(host, cmd, *args, **kwargs):
+ if hasattr(cmd, 'args') and 'check-host' in cmd.args:
+ captured_commands.append(cmd)
+ return ('', '', 0)
+
+ execute_command.side_effect = capture_execute
+
+ orig_get = cephadm_module.get_module_option
+
+ def get_opt(key, default=None):
+ if key == 'cephadm_binary_logging_level':
+ return 'debug'
+ return orig_get(key, default)
+
+ with mock.patch.object(cephadm_module, 'get_module_option', side_effect=get_opt):
+ with with_host(cephadm_module, 'test'):
+ pass
+
+ check_host_cmds = [c for c in captured_commands if 'check-host' in c.args]
+ assert len(check_host_cmds) >= 1, 'expected at least one check-host invocation'
+ cmd = check_host_cmds[0]
+ assert '--logging-level' in cmd.args, (
+ 'cephadm should be called with --logging-level when level is debug'
+ )
+ idx = cmd.args.index('--logging-level')
+ assert cmd.args[idx + 1] == 'debug', (
+ 'host-status logs should not be suppressed with logging-level debug'
+ )