Skip to content

Commit

Permalink
HAWQ-1425. Print error message if ssh connect failed.
Browse files Browse the repository at this point in the history
  • Loading branch information
radarwave committed Apr 7, 2017
1 parent 18e928c commit 32e01c7
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions tools/bin/hawqpylib/hawqlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,13 @@ def check_hostname_equal(remote_host, user = ""):
cmd = "hostname"
result_local, local_hostname, stderr_remote = local_ssh_output(cmd)
result_remote, remote_hostname, stderr_remote = remote_ssh_output(cmd, remote_host, user)
if result_remote != 0:
print "Execute command '%s' failed with return code %d on %s." % (cmd, result_remote, remote_host)
print "Either ssh connection fails or command exits with error. Details:"
print stderr_remote
print "For ssh connection issue, please make sure passwordless ssh is enabled or check remote host."
sys.exit(result_remote)

if local_hostname.strip() == remote_hostname.strip():
return True
else:
Expand Down Expand Up @@ -265,9 +272,9 @@ def local_ssh_output(cmd):
def remote_ssh(cmd, host, user):

if user == "":
remote_cmd_str = "ssh -o 'StrictHostKeyChecking no' %s \"%s\"" % (host, cmd)
remote_cmd_str = "ssh -o StrictHostKeyChecking=no %s \"%s\"" % (host, cmd)
else:
remote_cmd_str = "ssh -o 'StrictHostKeyChecking no' %s@%s \"%s\"" % (user, host, cmd)
remote_cmd_str = "ssh -o StrictHostKeyChecking=no %s@%s \"%s\"" % (user, host, cmd)
try:
result = subprocess.Popen(remote_cmd_str, shell=True).wait()
except subprocess.CalledProcessError:
Expand All @@ -280,14 +287,14 @@ def remote_ssh(cmd, host, user):
def remote_ssh_output(cmd, host, user):

if user == "":
remote_cmd_str = "ssh -o 'StrictHostKeyChecking no' %s \"%s\"" % (host, cmd)
remote_cmd_str = "ssh -o StrictHostKeyChecking=no %s \"%s\"" % (host, cmd)
else:
remote_cmd_str = "ssh -o 'StrictHostKeyChecking no' %s@%s \"%s\"" % (user, host, cmd)
remote_cmd_str = "ssh -o StrictHostKeyChecking=no %s@%s \"%s\"" % (user, host, cmd)

try:
result = subprocess.Popen(remote_cmd_str, shell=True, stdout = subprocess.PIPE, stderr = subprocess.PIPE)
stdout,stderr = result.communicate()
except subprocess.CalledProcessError:
except:
print "Execute shell command on %s failed" % host
pass

Expand Down

0 comments on commit 32e01c7

Please sign in to comment.