From 3dbce20386a19286b671fa93cbfed844718ffe68 Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat Date: Tue, 15 Mar 2016 15:46:06 +0100 Subject: [PATCH] various cosmetic --- nepi/resources/linux/application.py | 10 ++++++++-- nepi/util/sshfuncs.py | 16 +++++++++------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/nepi/resources/linux/application.py b/nepi/resources/linux/application.py index 0a0ed05d..4874a0e0 100644 --- a/nepi/resources/linux/application.py +++ b/nepi/resources/linux/application.py @@ -16,6 +16,10 @@ # # Author: Alina Quereilhac +import os +import subprocess +import logging + from nepi.execution.attribute import Attribute, Flags, Types from nepi.execution.trace import Trace, TraceAttr from nepi.execution.resource import ResourceManager, clsinit_copy, \ @@ -24,8 +28,9 @@ from nepi.resources.linux.node import LinuxNode from nepi.util.sshfuncs import ProcStatus, STDOUT from nepi.util.timefuncs import tnow, tdiffsec -import os -import subprocess +# to debug, just use +# logging.getLogger('application').setLevel(logging.DEBUG) +logger = logging.getLogger("application") # TODO: Resolve wildcards in commands!! # TODO: When a failure occurs during deployment, scp and ssh processes are left running behind!! @@ -248,6 +253,7 @@ class LinuxApplication(ResourceManager): self.info("Retrieving '{}' trace {} ".format(name, attr)) path = self.trace_filepath(name) + logger.debug("trace: path= {}".format(path)) command = "(test -f {} && echo 'success') || echo 'error'".format(path) (out, err), proc = self.node.execute(command) diff --git a/nepi/util/sshfuncs.py b/nepi/util/sshfuncs.py index 1b4d389b..fa7df4b6 100644 --- a/nepi/util/sshfuncs.py +++ b/nepi/util/sshfuncs.py @@ -38,13 +38,15 @@ from six import PY2 _re_inet = re.compile("\d+:\s+(?P[a-z0-9_-]+)\s+inet6?\s+(?P[a-f0-9.:/]+)\s+(brd\s+[0-9.]+)?.*scope\s+global.*") +# to debug, just use +# logging.getLogger('sshfuncs').setLevel(logging.DEBUG) logger = logging.getLogger("sshfuncs") def log(msg, level = logging.DEBUG, out = None, err = None): if out: - msg += " - OUT: {} ".format(out) + msg += " - OUT is {} long".format(len(out)) if err: - msg += " - ERROR: {} ".format(err) + msg += " - ERR is {} long".format(len(err)) logger.log(level, msg) if hasattr(os, "devnull"): @@ -307,16 +309,14 @@ def rexec(command, host, user, args.append(command) - log_msg = " rexec - host {} - command {} ".format(host, " ".join(map(str, args))) + log_msg = " rexec - host {} - command {} ".format(host, pretty_args(args)) stdout = stderr = stdin = subprocess.PIPE if forward_x11: stdout = stderr = stdin = None return _retry_rexec(args, log_msg, - stderr = stderr, - stdin = stdin, - stdout = stdout, + stdin = stdin, stdout = stdout, stderr = stderr, env = env, retry = retry, tmp_known_hosts = tmp_known_hosts, @@ -407,7 +407,7 @@ def rcopy(source, dest, else: args.append(dest) - log_msg = " rcopy - host {} - command {} ".format(host, " ".join(map(str, args))) + log_msg = " rcopy - host {} - command {} ".format(host, pretty_args(args)) return _retry_rexec(args, log_msg, env = None, retry = retry, tmp_known_hosts = tmp_known_hosts, @@ -854,6 +854,7 @@ def _communicate(proc, input, timeout=None, err_on_timeout=True): proc.stdout.close() read_set.remove(proc.stdout) stdout.append(data) + log("have read {} bytes from stdout".format(len(stdout))) # likewise if proc.stderr in rlist: @@ -862,6 +863,7 @@ def _communicate(proc, input, timeout=None, err_on_timeout=True): proc.stderr.close() read_set.remove(proc.stderr) stderr.append(data) + log("have read {} bytes from stderr".format(len(stdout))) # All data exchanged. Translate lists into strings. if stdout is not None: -- 2.43.0