forked from TrueCloudLab/frostfs-testlib
[#266] Remove duplicate messages in logs
Signed-off-by: Kirill Sosnovskikh <k.sosnovskikh@yadro.com>
This commit is contained in:
parent
4c0d76408c
commit
166e44da9c
3 changed files with 23 additions and 32 deletions
|
@ -28,7 +28,7 @@ class LocalShell(Shell):
|
||||||
for inspector in [*self.command_inspectors, *extra_inspectors]:
|
for inspector in [*self.command_inspectors, *extra_inspectors]:
|
||||||
command = inspector.inspect(original_command, command)
|
command = inspector.inspect(original_command, command)
|
||||||
|
|
||||||
logger.info(f"Executing command: {command}")
|
with reporter.step(f"Executing command: {command}"):
|
||||||
if options.interactive_inputs:
|
if options.interactive_inputs:
|
||||||
return self._exec_interactive(command, options)
|
return self._exec_interactive(command, options)
|
||||||
return self._exec_non_interactive(command, options)
|
return self._exec_non_interactive(command, options)
|
||||||
|
@ -60,9 +60,7 @@ class LocalShell(Shell):
|
||||||
|
|
||||||
if options.check and result.return_code != 0:
|
if options.check and result.return_code != 0:
|
||||||
raise RuntimeError(
|
raise RuntimeError(
|
||||||
f"Command: {command}\nreturn code: {result.return_code}\n"
|
f"Command: {command}\nreturn code: {result.return_code}\n" f"Output: {result.stdout}\n" f"Stderr: {result.stderr}\n"
|
||||||
f"Output: {result.stdout}\n"
|
|
||||||
f"Stderr: {result.stderr}\n"
|
|
||||||
)
|
)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
@ -93,9 +91,7 @@ class LocalShell(Shell):
|
||||||
stderr="",
|
stderr="",
|
||||||
return_code=exc.returncode,
|
return_code=exc.returncode,
|
||||||
)
|
)
|
||||||
raise RuntimeError(
|
raise RuntimeError(f"Command: {command}\nError with retcode: {exc.returncode}\n Output: {exc.output}") from exc
|
||||||
f"Command: {command}\nError:\n" f"return code: {exc.returncode}\n" f"output: {exc.output}"
|
|
||||||
) from exc
|
|
||||||
except OSError as exc:
|
except OSError as exc:
|
||||||
raise RuntimeError(f"Command: {command}\nOutput: {exc.strerror}") from exc
|
raise RuntimeError(f"Command: {command}\nOutput: {exc.strerror}") from exc
|
||||||
finally:
|
finally:
|
||||||
|
@ -129,15 +125,13 @@ class LocalShell(Shell):
|
||||||
end_time: datetime,
|
end_time: datetime,
|
||||||
result: Optional[CommandResult],
|
result: Optional[CommandResult],
|
||||||
) -> None:
|
) -> None:
|
||||||
# TODO: increase logging level if return code is non 0, should be warning at least
|
if not result:
|
||||||
logger.info(
|
logger.warning(f"Command: {command}\n" f"Error: result is None")
|
||||||
f"Command: {command}\n"
|
return
|
||||||
f"{'Success:' if result and result.return_code == 0 else 'Error:'}\n"
|
|
||||||
f"return code: {result.return_code if result else ''} "
|
status, log_method = ("Success", logger.info) if result.return_code == 0 else ("Error", logger.warning)
|
||||||
f"\nOutput: {result.stdout if result else ''}"
|
log_method(f"Command: {command}\n" f"{status} with retcode {result.return_code}\n" f"Output: \n{result.stdout}")
|
||||||
)
|
|
||||||
|
|
||||||
if result:
|
|
||||||
elapsed_time = end_time - start_time
|
elapsed_time = end_time - start_time
|
||||||
command_attachment = (
|
command_attachment = (
|
||||||
f"COMMAND: {command}\n"
|
f"COMMAND: {command}\n"
|
||||||
|
@ -146,5 +140,4 @@ class LocalShell(Shell):
|
||||||
f"STDERR:\n{result.stderr}\n"
|
f"STDERR:\n{result.stderr}\n"
|
||||||
f"Start / End / Elapsed\t {start_time.time()} / {end_time.time()} / {elapsed_time}"
|
f"Start / End / Elapsed\t {start_time.time()} / {end_time.time()} / {elapsed_time}"
|
||||||
)
|
)
|
||||||
with reporter.step(f"COMMAND: {command}"):
|
|
||||||
reporter.attach(command_attachment, "Command execution.txt")
|
reporter.attach(command_attachment, "Command execution.txt")
|
||||||
|
|
|
@ -200,7 +200,6 @@ def list_containers(wallet: WalletInfo, shell: Shell, endpoint: str, timeout: Op
|
||||||
"""
|
"""
|
||||||
cli = FrostfsCli(shell, FROSTFS_CLI_EXEC, wallet.config_path)
|
cli = FrostfsCli(shell, FROSTFS_CLI_EXEC, wallet.config_path)
|
||||||
result = cli.container.list(rpc_endpoint=endpoint, timeout=timeout)
|
result = cli.container.list(rpc_endpoint=endpoint, timeout=timeout)
|
||||||
logger.info(f"Containers: \n{result}")
|
|
||||||
return result.stdout.split()
|
return result.stdout.split()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -75,7 +75,7 @@ def _attach_allure_log(cmd: str, output: str, return_code: int, start_time: date
|
||||||
reporter.attach(command_attachment, "Command execution")
|
reporter.attach(command_attachment, "Command execution")
|
||||||
|
|
||||||
|
|
||||||
def log_command_execution(url: str, cmd: str, output: Union[str, TypedDict], params: Optional[dict] = None) -> None:
|
def log_command_execution(url: str, cmd: str, output: Union[str, dict], params: Optional[dict] = None) -> None:
|
||||||
logger.info(f"{cmd}: {output}")
|
logger.info(f"{cmd}: {output}")
|
||||||
|
|
||||||
with suppress(Exception):
|
with suppress(Exception):
|
||||||
|
@ -90,7 +90,6 @@ def log_command_execution(url: str, cmd: str, output: Union[str, TypedDict], par
|
||||||
params = json_params
|
params = json_params
|
||||||
|
|
||||||
command_attachment = f"COMMAND: '{cmd}'\n" f"URL: {url}\n" f"PARAMS:\n{params}\n" f"OUTPUT:\n{output}\n"
|
command_attachment = f"COMMAND: '{cmd}'\n" f"URL: {url}\n" f"PARAMS:\n{params}\n" f"OUTPUT:\n{output}\n"
|
||||||
with reporter.step(f'COMMAND: {shorten(cmd, width=60, placeholder="...")}'):
|
|
||||||
reporter.attach(command_attachment, "Command execution")
|
reporter.attach(command_attachment, "Command execution")
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue