[#367] Use full date during log
All checks were successful
DCO action / DCO (pull_request) Successful in 21s
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:
parent
3966f65c95
commit
a353592d20
3 changed files with 9 additions and 18 deletions
|
@ -141,6 +141,6 @@ class LocalShell(Shell):
|
|||
f"RETCODE: {result.return_code}\n\n"
|
||||
f"STDOUT:\n{result.stdout}\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")
|
||||
|
|
|
@ -68,8 +68,7 @@ class SshConnectionProvider:
|
|||
try:
|
||||
if creds.ssh_key_path:
|
||||
logger.info(
|
||||
f"Trying to connect to host {host} as {creds.ssh_login} using SSH key "
|
||||
f"{creds.ssh_key_path} (attempt {attempt})"
|
||||
f"Trying to connect to host {host} as {creds.ssh_login} using SSH key " f"{creds.ssh_key_path} (attempt {attempt})"
|
||||
)
|
||||
connection.connect(
|
||||
hostname=host,
|
||||
|
@ -79,9 +78,7 @@ class SshConnectionProvider:
|
|||
timeout=self.CONNECTION_TIMEOUT,
|
||||
)
|
||||
else:
|
||||
logger.info(
|
||||
f"Trying to connect to host {host} as {creds.ssh_login} using password " f"(attempt {attempt})"
|
||||
)
|
||||
logger.info(f"Trying to connect to host {host} as {creds.ssh_login} using password " f"(attempt {attempt})")
|
||||
connection.connect(
|
||||
hostname=host,
|
||||
port=port,
|
||||
|
@ -104,9 +101,7 @@ class SshConnectionProvider:
|
|||
connection.close()
|
||||
can_retry = attempt + 1 < self.SSH_CONNECTION_ATTEMPTS
|
||||
if can_retry:
|
||||
logger.warn(
|
||||
f"Can't connect to host {host}, will retry after {self.SSH_ATTEMPTS_INTERVAL}s. Error: {exc}"
|
||||
)
|
||||
logger.warn(f"Can't connect to host {host}, will retry after {self.SSH_ATTEMPTS_INTERVAL}s. Error: {exc}")
|
||||
sleep(self.SSH_ATTEMPTS_INTERVAL)
|
||||
continue
|
||||
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"STDOUT:\n{textwrap.indent(result.stdout, ' ')}\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:
|
||||
|
@ -185,13 +180,11 @@ class SSHShell(Shell):
|
|||
private_key_passphrase: Optional[str] = None,
|
||||
port: str = "22",
|
||||
command_inspectors: Optional[list[CommandInspector]] = None,
|
||||
custom_environment: Optional[dict] = None
|
||||
custom_environment: Optional[dict] = None,
|
||||
) -> None:
|
||||
super().__init__()
|
||||
self.connection_provider = SshConnectionProvider()
|
||||
self.connection_provider.store_creds(
|
||||
host, SshCredentials(login, password, private_key_path, private_key_passphrase)
|
||||
)
|
||||
self.connection_provider.store_creds(host, SshCredentials(login, password, private_key_path, private_key_passphrase))
|
||||
self.host = host
|
||||
self.port = port
|
||||
|
||||
|
@ -220,9 +213,7 @@ class SSHShell(Shell):
|
|||
result = self._exec_non_interactive(command, options)
|
||||
|
||||
if options.check and result.return_code != 0:
|
||||
raise RuntimeError(
|
||||
f"Command: {command}\nreturn code: {result.return_code}\nOutput: {result.stdout}\nStderr: {result.stderr}\n"
|
||||
)
|
||||
raise RuntimeError(f"Command: {command}\nreturn code: {result.return_code}\nOutput: {result.stdout}\nStderr: {result.stderr}\n")
|
||||
return result
|
||||
|
||||
@log_command
|
||||
|
|
|
@ -68,7 +68,7 @@ def _attach_allure_log(cmd: str, output: str, return_code: int, start_time: date
|
|||
f"COMMAND: '{cmd}'\n"
|
||||
f"OUTPUT:\n {output}\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="...")}'):
|
||||
reporter.attach(command_attachment, "Command execution")
|
||||
|
|
Loading…
Add table
Reference in a new issue