Skip to content

Commit 846c05f

Browse files
authored
Merge pull request #96 from postgrespro/add_known_host-macos-fix
RemoteOperations add_known_host macos fix
2 parents 90ab804 + 4200b80 commit 846c05f

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

testgres/operations/remote_ops.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import os
44
import subprocess
55
import tempfile
6+
import platform
67

78
# we support both pg8000 and psycopg2
89
try:
@@ -42,7 +43,8 @@ def cmdline(self):
4243

4344
class RemoteOperations(OsOperations):
4445
def __init__(self, conn_params: ConnectionParams):
45-
if os.name != "posix":
46+
47+
if not platform.system().lower() == "linux":
4648
raise EnvironmentError("Remote operations are supported only on Linux!")
4749

4850
super().__init__(conn_params.username)
@@ -76,16 +78,14 @@ def close_ssh_tunnel(self):
7678
print("No active tunnel to close.")
7779

7880
def add_known_host(self, host):
79-
cmd = 'ssh-keyscan -H %s >> /home/%s/.ssh/known_hosts' % (host, os.getlogin())
81+
known_hosts_path = os.path.expanduser("~/.ssh/known_hosts")
82+
cmd = 'ssh-keyscan -H %s >> %s' % (host, known_hosts_path)
83+
8084
try:
81-
subprocess.check_call(
82-
cmd,
83-
shell=True,
84-
)
85+
subprocess.check_call(cmd, shell=True)
8586
logging.info("Successfully added %s to known_hosts." % host)
8687
except subprocess.CalledProcessError as e:
87-
raise ExecUtilException(message="Failed to add %s to known_hosts. Error: %s" % (host, str(e)), command=cmd,
88-
exit_code=e.returncode, out=e.stderr)
88+
raise Exception("Failed to add %s to known_hosts. Error: %s" % (host, str(e)))
8989

9090
def exec_command(self, cmd, wait_exit=False, verbose=False, expect_error=False,
9191
encoding=None, shell=True, text=False, input=None, stdin=None, stdout=None,

0 commit comments

Comments
 (0)