From 20afe1a62f15fb479bb8557abed7ee203ebbdc94 Mon Sep 17 00:00:00 2001 From: Ian Wienand Date: Wed, 24 Aug 2016 10:52:37 +1000 Subject: [PATCH] launch-node.py: More verbose logging One problem with "shell script as python" is that there's no equivalent of "-x" in shell, which makes it really hard to extract what's being called and where output came from. This adds a bit more verbose logging around the ssh calls to try and help someone parsing the logs. Change-Id: I85e2415b47e044cfa1c678fc7786b4891fa1f93e --- launch/launch-node.py | 2 +- launch/sshclient.py | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/launch/launch-node.py b/launch/launch-node.py index 61b9d5315a..f49c3c498a 100755 --- a/launch/launch-node.py +++ b/launch/launch-node.py @@ -74,7 +74,7 @@ def bootstrap_server(server, key, name, volume_device, keep, ip = server.public_v4 ssh_kwargs = dict(pkey=key) - print 'Public IP', ip + print("--- Running initial configuration on host %s ---" % ip) for username in ['root', 'ubuntu', 'centos', 'admin']: ssh_client = utils.ssh_connect(ip, username, ssh_kwargs, timeout=600) if ssh_client: diff --git a/launch/sshclient.py b/launch/sshclient.py index 49d6bf6359..1c23aafda4 100644 --- a/launch/sshclient.py +++ b/launch/sshclient.py @@ -40,19 +40,23 @@ class SSHClient(object): def ssh(self, command, error_ok=False): stdin, stdout, stderr = self.client.exec_command(command) - print command + print('--- ssh: "%s" ---' % command) + print(' -- stdout --') output = '' for x in stdout: output += x - sys.stdout.write(x) + sys.stdout.write(" | " + x) ret = stdout.channel.recv_exit_status() - print stderr.read() + print(" -- stderr --") + for x in stderr: + sys.stdout.write(" | " + x) if (not error_ok) and ret: raise SSHException("Unable to %s" % command, ret) + print("--- done ---\n") return ret, output def scp(self, source, dest): - print 'copy', source, dest + print('--- scp copy: %s -> %s' % (source, dest)) ftp = self.client.open_sftp() ftp.put(source, dest) ftp.close()