[#367] Use full date during log
All checks were successful
DCO action / DCO (pull_request) Successful in 21s

Signed-off-by: a.berezin <a.berezin@yadro.com>
This commit is contained in:
Andrey Berezin 2025-03-19 14:33:25 +03:00
parent 3966f65c95
commit a353592d20
3 changed files with 9 additions and 18 deletions

View file

@ -141,6 +141,6 @@ class LocalShell(Shell):
f"RETCODE: {result.return_code}\n\n" f"RETCODE: {result.return_code}\n\n"
f"STDOUT:\n{result.stdout}\n" f"STDOUT:\n{result.stdout}\n"
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} / {end_time} / {elapsed_time}"
) )
reporter.attach(command_attachment, "Command execution.txt") reporter.attach(command_attachment, "Command execution.txt")

View file

@ -68,8 +68,7 @@ class SshConnectionProvider:
try: try:
if creds.ssh_key_path: if creds.ssh_key_path:
logger.info( logger.info(
f"Trying to connect to host {host} as {creds.ssh_login} using SSH key " f"Trying to connect to host {host} as {creds.ssh_login} using SSH key " f"{creds.ssh_key_path} (attempt {attempt})"
f"{creds.ssh_key_path} (attempt {attempt})"
) )
connection.connect( connection.connect(
hostname=host, hostname=host,
@ -79,9 +78,7 @@ class SshConnectionProvider:
timeout=self.CONNECTION_TIMEOUT, timeout=self.CONNECTION_TIMEOUT,
) )
else: else:
logger.info( logger.info(f"Trying to connect to host {host} as {creds.ssh_login} using password " f"(attempt {attempt})")
f"Trying to connect to host {host} as {creds.ssh_login} using password " f"(attempt {attempt})"
)
connection.connect( connection.connect(
hostname=host, hostname=host,
port=port, port=port,
@ -104,9 +101,7 @@ class SshConnectionProvider:
connection.close() connection.close()
can_retry = attempt + 1 < self.SSH_CONNECTION_ATTEMPTS can_retry = attempt + 1 < self.SSH_CONNECTION_ATTEMPTS
if can_retry: if can_retry:
logger.warn( logger.warn(f"Can't connect to host {host}, will retry after {self.SSH_ATTEMPTS_INTERVAL}s. Error: {exc}")
f"Can't connect to host {host}, will retry after {self.SSH_ATTEMPTS_INTERVAL}s. Error: {exc}"
)
sleep(self.SSH_ATTEMPTS_INTERVAL) sleep(self.SSH_ATTEMPTS_INTERVAL)
continue continue
logger.exception(f"Can't connect to host {host}") logger.exception(f"Can't connect to host {host}")
@ -139,7 +134,7 @@ def log_command(func):
f"RC:\n {result.return_code}\n" f"RC:\n {result.return_code}\n"
f"STDOUT:\n{textwrap.indent(result.stdout, ' ')}\n" f"STDOUT:\n{textwrap.indent(result.stdout, ' ')}\n"
f"STDERR:\n{textwrap.indent(result.stderr, ' ')}\n" f"STDERR:\n{textwrap.indent(result.stderr, ' ')}\n"
f"Start / End / Elapsed\t {start_time.time()} / {end_time.time()} / {elapsed_time}" f"Start / End / Elapsed\t {start_time} / {end_time} / {elapsed_time}"
) )
if not options.no_log: if not options.no_log:
@ -185,13 +180,11 @@ class SSHShell(Shell):
private_key_passphrase: Optional[str] = None, private_key_passphrase: Optional[str] = None,
port: str = "22", port: str = "22",
command_inspectors: Optional[list[CommandInspector]] = None, command_inspectors: Optional[list[CommandInspector]] = None,
custom_environment: Optional[dict] = None custom_environment: Optional[dict] = None,
) -> None: ) -> None:
super().__init__() super().__init__()
self.connection_provider = SshConnectionProvider() self.connection_provider = SshConnectionProvider()
self.connection_provider.store_creds( self.connection_provider.store_creds(host, SshCredentials(login, password, private_key_path, private_key_passphrase))
host, SshCredentials(login, password, private_key_path, private_key_passphrase)
)
self.host = host self.host = host
self.port = port self.port = port
@ -220,9 +213,7 @@ class SSHShell(Shell):
result = self._exec_non_interactive(command, options) result = self._exec_non_interactive(command, options)
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}\nOutput: {result.stdout}\nStderr: {result.stderr}\n")
f"Command: {command}\nreturn code: {result.return_code}\nOutput: {result.stdout}\nStderr: {result.stderr}\n"
)
return result return result
@log_command @log_command

View file

@ -68,7 +68,7 @@ def _attach_allure_log(cmd: str, output: str, return_code: int, start_time: date
f"COMMAND: '{cmd}'\n" f"COMMAND: '{cmd}'\n"
f"OUTPUT:\n {output}\n" f"OUTPUT:\n {output}\n"
f"RC: {return_code}\n" f"RC: {return_code}\n"
f"Start / End / Elapsed\t {start_time.time()} / {end_time.time()} / {end_time - start_time}" f"Start / End / Elapsed\t {start_time} / {end_time} / {end_time - start_time}"
) )
with reporter.step(f'COMMAND: {shorten(cmd, width=60, placeholder="...")}'): with reporter.step(f'COMMAND: {shorten(cmd, width=60, placeholder="...")}'):
reporter.attach(command_attachment, "Command execution") reporter.attach(command_attachment, "Command execution")