From 4200b8096f198a36d8bf109d1b8da679b66322ad Mon Sep 17 00:00:00 2001 From: vshepard Date: Wed, 22 Nov 2023 09:34:13 +0100 Subject: [PATCH] RemoteOperations add_known_host macos fix --- testgres/operations/remote_ops.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/testgres/operations/remote_ops.py b/testgres/operations/remote_ops.py index 421c0a6d..0a545834 100644 --- a/testgres/operations/remote_ops.py +++ b/testgres/operations/remote_ops.py @@ -3,6 +3,7 @@ import os import subprocess import tempfile +import platform # we support both pg8000 and psycopg2 try: @@ -42,7 +43,8 @@ def cmdline(self): class RemoteOperations(OsOperations): def __init__(self, conn_params: ConnectionParams): - if os.name != "posix": + + if not platform.system().lower() == "linux": raise EnvironmentError("Remote operations are supported only on Linux!") super().__init__(conn_params.username) @@ -76,16 +78,14 @@ def close_ssh_tunnel(self): print("No active tunnel to close.") def add_known_host(self, host): - cmd = 'ssh-keyscan -H %s >> /home/%s/.ssh/known_hosts' % (host, os.getlogin()) + known_hosts_path = os.path.expanduser("~/.ssh/known_hosts") + cmd = 'ssh-keyscan -H %s >> %s' % (host, known_hosts_path) + try: - subprocess.check_call( - cmd, - shell=True, - ) + subprocess.check_call(cmd, shell=True) logging.info("Successfully added %s to known_hosts." % host) except subprocess.CalledProcessError as e: - raise ExecUtilException(message="Failed to add %s to known_hosts. Error: %s" % (host, str(e)), command=cmd, - exit_code=e.returncode, out=e.stderr) + raise Exception("Failed to add %s to known_hosts. Error: %s" % (host, str(e))) def exec_command(self, cmd, wait_exit=False, verbose=False, expect_error=False, encoding=None, shell=True, text=False, input=None, stdin=None, stdout=None,