|
3 | 3 | import os
|
4 | 4 | import subprocess
|
5 | 5 | import tempfile
|
| 6 | +import platform |
6 | 7 |
|
7 | 8 | # we support both pg8000 and psycopg2
|
8 | 9 | try:
|
@@ -42,7 +43,8 @@ def cmdline(self):
|
42 | 43 |
|
43 | 44 | class RemoteOperations(OsOperations):
|
44 | 45 | def __init__(self, conn_params: ConnectionParams):
|
45 |
| - if os.name != "posix": |
| 46 | + |
| 47 | + if not platform.system().lower() == "linux": |
46 | 48 | raise EnvironmentError("Remote operations are supported only on Linux!")
|
47 | 49 |
|
48 | 50 | super().__init__(conn_params.username)
|
@@ -76,16 +78,14 @@ def close_ssh_tunnel(self):
|
76 | 78 | print("No active tunnel to close.")
|
77 | 79 |
|
78 | 80 | 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 | + |
80 | 84 | try:
|
81 |
| - subprocess.check_call( |
82 |
| - cmd, |
83 |
| - shell=True, |
84 |
| - ) |
| 85 | + subprocess.check_call(cmd, shell=True) |
85 | 86 | logging.info("Successfully added %s to known_hosts." % host)
|
86 | 87 | 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))) |
89 | 89 |
|
90 | 90 | def exec_command(self, cmd, wait_exit=False, verbose=False, expect_error=False,
|
91 | 91 | encoding=None, shell=True, text=False, input=None, stdin=None, stdout=None,
|
|
0 commit comments