Skip to content

Add port conn params #127

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

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Prev Previous commit
Next Next commit
Add StrictHostKeyChecking=no for ssh connect
  • Loading branch information
vshepard committed Jun 6, 2024
commit dc775c20df12e5ad4383bbe551cf2964d72c2bd6
18 changes: 3 additions & 15 deletions testgres/operations/remote_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,13 @@ def __init__(self, conn_params: ConnectionParams):
self.host = conn_params.host
self.ssh_key = conn_params.ssh_key
self.port = conn_params.port
self.ssh_cmd = ["-o StrictHostKeyChecking=no"]
if self.ssh_key:
self.ssh_cmd = ["-i", self.ssh_key]
else:
self.ssh_cmd = []
self.ssh_cmd += ["-i", self.ssh_key]
if self.port:
self.ssh_cmd = ["-p", self.port]
self.ssh_cmd += ["-p", self.port]
self.remote = True
self.username = conn_params.username or self.get_user()
self.add_known_host(self.host)
self.tunnel_process = None

def __enter__(self):
Expand All @@ -80,16 +78,6 @@ def close_ssh_tunnel(self):
else:
print("No active tunnel to close.")

def add_known_host(self, host):
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)
logging.info("Successfully added %s to known_hosts." % host)
except subprocess.CalledProcessError as e:
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,
stderr=None, get_process=None, timeout=None):
Expand Down