From 4e49931c19db7aee505be14772a42d2f189f4e22 Mon Sep 17 00:00:00 2001 From: Vladimir Domnich Date: Thu, 28 Jul 2022 11:21:44 +0300 Subject: [PATCH] Add logic to prepend ssh command with sudo. --- pytest_tests/helpers/ssh_helper.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pytest_tests/helpers/ssh_helper.py b/pytest_tests/helpers/ssh_helper.py index 0536b6f..e76d47b 100644 --- a/pytest_tests/helpers/ssh_helper.py +++ b/pytest_tests/helpers/ssh_helper.py @@ -82,6 +82,8 @@ class HostClient: @log_command def exec_with_confirmation(self, cmd: str, confirmation: list, verify=True, timeout=10) -> SSHCommand: + if self.login and self.login != "root": + cmd = f"sudo {cmd}" ssh_stdin, ssh_stdout, ssh_stderr = self.ssh_client.exec_command(cmd, timeout=timeout) for line in confirmation: if not line.endswith('\n'): @@ -195,6 +197,8 @@ class HostClient: def _inner_exec(self, cmd: str, timeout: int) -> SSHCommand: if not self.ssh_client: self.create_connection() + if self.login and self.login != "root": + cmd = f"sudo {cmd}" for _ in range(self.SSH_CONNECTION_ATTEMPTS): try: _, stdout, stderr = self.ssh_client.exec_command(cmd, timeout=timeout)