commit 74dbe0fe73163021045cc0e8fa9efbd57791ebd9
Author: Jan Tluka <jtluka(a)redhat.com>
Date: Fri Oct 3 16:40:32 2014 +0200
NetTestCommand: save_output implementation for NetTestCommandExec class
This patch enables a user to work with the stdout and stderr from within
the python task after a command is run. A user must state that he's
interested in these outputs by statement similar to following,
res = machine1.run("rpm -qa kernel", save_output="yes")
Later, the outputs can be retrieved by
stdout = res.get_result()["res_data"]["stdout"]
stderr = res.get_result()["res_data"]["stderr"]
This is available for NetTestCommandExec class only.
Signed-off-by: Jan Tluka <jtluka(a)redhat.com>
Signed-off-by: Jiri Pirko <jiri(a)resnulli.us>
lnst/Common/NetTestCommand.py | 16 ++++++++++++----
1 files changed, 12 insertions(+), 4 deletions(-)
---
diff --git a/lnst/Common/NetTestCommand.py b/lnst/Common/NetTestCommand.py
index c1b39d9..04d6e86 100644
--- a/lnst/Common/NetTestCommand.py
+++ b/lnst/Common/NetTestCommand.py
@@ -254,7 +254,7 @@ def NetTestCommandTest(command, resource_table):
test_class = getattr(module, module_name)
return test_class(command)
-class NetTestCommandGeneric:
+class NetTestCommandGeneric(object):
def __init__(self, command):
self._command = command
self._result = None
@@ -374,13 +374,21 @@ class NetTestCommandGeneric:
return exec_cmd("cd \"%s\" && %s" % (tools_path, cmd), *args, **kwargs)
class NetTestCommandExec(NetTestCommandGeneric):
+ def __init__(self, command):
+ super(NetTestCommandExec, self).__init__(command)
+ self._save_output = "save_output" in command
+
def run(self):
try:
if "from" in self._command:
- self.exec_from(self._command["from"], self._command["command"])
+ stdout, stderr = self.exec_from(self._command["from"],
+ self._command["command"])
else:
- self.exec_cmd(self._command["command"])
- self.set_pass()
+ stdout, stderr = self.exec_cmd(self._command["command"])
+ res_data = None
+ if self._save_output:
+ res_data = { "stdout": stdout, "stderr": stderr }
+ self.set_pass(res_data)
except ExecCmdFail:
if "bg_id" in self._command:
logging.info("Command probably intentionally killed. Passing.")