From a6db0594a314e75e5f0676e2e7bdb7ca6551b8a1 Mon Sep 17 00:00:00 2001 From: Miguel Caballer Date: Sat, 3 Aug 2024 08:38:14 +0200 Subject: [PATCH 1/2] Improve ssh print command --- imclient/imclient.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/imclient/imclient.py b/imclient/imclient.py index e96e4de..60d950c 100755 --- a/imclient/imclient.py +++ b/imclient/imclient.py @@ -93,7 +93,10 @@ def run(radl, show_only=False): ops = CmdSsh._connect_password(radl) if show_only: - print(" ".join(ops)) + for op in ops: + if "ProxyCommand" in op: + op = "'" + op + "'" + print(op, end=" ") else: os.execlp(ops[0], *ops) except OSError as e: @@ -199,12 +202,13 @@ def _connect_password(radl): ssh_args = CmdSsh._get_proxy_command(radl, ip, s.getValue("disk.0.os.credentials.username")) res = ["sshpass", "-p%s" % s.getValue("disk.0.os.credentials.password"), - "ssh", "-p", ssh_port, "-o", "UserKnownHostsFile=/dev/null", "-o", "StrictHostKeyChecking=no", - "%s@%s" % (s.getValue("disk.0.os.credentials.username"), ip)] + "ssh", "-p", ssh_port, "-o", "UserKnownHostsFile=/dev/null", "-o", "StrictHostKeyChecking=no"] if ssh_args: res.extend(ssh_args) + res.append("%s@%s" % (s.getValue("disk.0.os.credentials.username"), ip)) + return res @staticmethod @@ -222,11 +226,10 @@ def _connect_key(radl): ssh_args = CmdSsh._get_proxy_command(radl, ip, s.getValue("disk.0.os.credentials.username")) res = ["ssh", "-p", ssh_port, "-i", f.name, "-o", "UserKnownHostsFile=/dev/null", - "-o", "StrictHostKeyChecking=no", - "%s@%s" % (s.getValue("disk.0.os.credentials.username"), ip)] - + "-o", "StrictHostKeyChecking=no"] if ssh_args: res.extend(ssh_args) + res.append("%s@%s" % (s.getValue("disk.0.os.credentials.username"), ip)) return res From 7adb3523378e07f5d815ec991246e93f4f85f232 Mon Sep 17 00:00:00 2001 From: Miguel Caballer Date: Sat, 3 Aug 2024 08:46:28 +0200 Subject: [PATCH 2/2] Improve ssh print command --- test/unit/test_client.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/unit/test_client.py b/test/unit/test_client.py index eeaad6a..e445ab2 100755 --- a/test/unit/test_client.py +++ b/test/unit/test_client.py @@ -1086,8 +1086,8 @@ def test_sshvm(self, server_proxy): self.assertEquals(res, True) output = out.getvalue().strip() self.assertIn("sshpass -pyoyoyo ssh -p 22 -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no " - "ubuntu@10.0.0.1 -o ProxyCommand=sshpass -p passwd ssh -W %h:%p -p 22" - " -o StrictHostKeyChecking=no username@someserver.com", output) + "-o 'ProxyCommand=sshpass -p passwd ssh -W %h:%p -p 22" + " -o StrictHostKeyChecking=no username@someserver.com' ubuntu@10.0.0.1", output) sys.stdout = oldstdout sys.stderr = oldstderr @@ -1146,9 +1146,9 @@ def test_sshvm_via_master(self, server_proxy): self.assertEquals(res, True) output = out.getvalue().strip() self.assertIn("ssh -p 22 -i /tmp/", output) - self.assertIn(" -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ubuntu@10.0.0.2" - " -o ProxyCommand=ssh -W %h:%p -i /var/tmp/ubuntu_ubuntu_10.0.0.2.pem -p 22" - " -o StrictHostKeyChecking=no ubuntu@8.8.8.8", output) + self.assertIn(" -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" + " -o 'ProxyCommand=ssh -W %h:%p -i /var/tmp/ubuntu_ubuntu_10.0.0.2.pem -p 22" + " -o StrictHostKeyChecking=no ubuntu@8.8.8.8' ubuntu@10.0.0.2", output) sys.stdout = oldstdout sys.stderr = oldstderr