From c6603dbf84c32945dabbc8c097ff661b7631047f Mon Sep 17 00:00:00 2001 From: Andrey Berezin Date: Thu, 3 Nov 2022 12:18:57 +0300 Subject: [PATCH] Add option to skip log output to logger Signed-off-by: Andrey Berezin --- src/neofs_testlib/shell/interfaces.py | 2 ++ src/neofs_testlib/shell/ssh_shell.py | 10 +++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/neofs_testlib/shell/interfaces.py b/src/neofs_testlib/shell/interfaces.py index 52e77a3..ca02582 100644 --- a/src/neofs_testlib/shell/interfaces.py +++ b/src/neofs_testlib/shell/interfaces.py @@ -44,12 +44,14 @@ class CommandOptions: timeout: Timeout for command execution (in seconds). check: Controls whether to check return code of the command. Set to False to ignore non-zero return codes. + no_log: Do not print output to logger if True. """ interactive_inputs: Optional[list[InteractiveInput]] = None close_stdin: bool = False timeout: int = 30 check: bool = True + no_log: bool = False @dataclass diff --git a/src/neofs_testlib/shell/ssh_shell.py b/src/neofs_testlib/shell/ssh_shell.py index 4e918c1..2b0bae3 100644 --- a/src/neofs_testlib/shell/ssh_shell.py +++ b/src/neofs_testlib/shell/ssh_shell.py @@ -36,13 +36,15 @@ class HostIsNotAvailable(Exception): def log_command(func): @wraps(func) - def wrapper(shell: "SSHShell", command: str, *args, **kwargs) -> CommandResult: + def wrapper( + shell: "SSHShell", command: str, options: CommandOptions, *args, **kwargs + ) -> CommandResult: command_info = command.removeprefix("$ProgressPreference='SilentlyContinue'\n") with reporter.step(command_info): logger.info(f'Execute command "{command}" on "{shell.host}"') start_time = datetime.utcnow() - result = func(shell, command, *args, **kwargs) + result = func(shell, command, options, *args, **kwargs) end_time = datetime.utcnow() elapsed_time = end_time - start_time @@ -55,7 +57,9 @@ def log_command(func): f"Start / End / Elapsed\t {start_time.time()} / {end_time.time()} / {elapsed_time}" ) - logger.info(log_message) + if not options.no_log: + logger.info(log_message) + reporter.attach(log_message, "SSH command.txt") return result