diff --git a/imclient/imclient.py b/imclient/imclient.py index 06ba761..b14a6ba 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 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