Skip to content

RemoteOperations add_known_host macos fix #96

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions testgres/operations/remote_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import subprocess
import tempfile
import platform

# we support both pg8000 and psycopg2
try:
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down