From: Jiri Pirko jiri@mellanox.com
Just ignore the user option and save the stderr and stdout always. Allows to shorten the run method call from tasks.
Signed-off-by: Jiri Pirko jiri@mellanox.com --- lnst/Common/NetTestCommand.py | 10 ++-------- lnst/Controller/NetTestController.py | 2 -- lnst/Controller/Task.py | 2 +- lnst/RecipeCommon/IRQ.py | 2 +- regression-tests/tests/28/recipe1.py | 2 +- regression-tests/tests/28/recipe2.py | 2 +- regression-tests/tests/28/recipe3.py | 2 +- regression-tests/tests/28/recipe4.py | 2 +- 8 files changed, 8 insertions(+), 16 deletions(-)
diff --git a/lnst/Common/NetTestCommand.py b/lnst/Common/NetTestCommand.py index 774c26e..3c290dc 100644 --- a/lnst/Common/NetTestCommand.py +++ b/lnst/Common/NetTestCommand.py @@ -400,7 +400,6 @@ class NetTestCommandGeneric(object): class NetTestCommandExec(NetTestCommandGeneric): def __init__(self, command): super(NetTestCommandExec, self).__init__(command) - self._save_output = "save_output" in command
def run(self): try: @@ -409,15 +408,10 @@ class NetTestCommandExec(NetTestCommandGeneric): self._command["command"]) else: stdout, stderr = self.exec_cmd(self._command["command"]) - res_data = None - if self._save_output: - res_data = { "stdout": stdout, "stderr": stderr } + res_data = {"stdout": stdout, "stderr": stderr} self.set_pass(res_data) except ExecCmdFail as e: - res_data = None - if self._save_output: - res_data = { "stdout": e.get_stdout(), - "stderr": e.get_stderr() } + res_data = {"stdout": e.get_stdout(), "stderr": e.get_stderr()} if "bg_id" in self._command: logging.info("Command probably intentionally killed. Passing.") self.set_pass(res_data) diff --git a/lnst/Controller/NetTestController.py b/lnst/Controller/NetTestController.py index 791dd95..c8a58b3 100644 --- a/lnst/Controller/NetTestController.py +++ b/lnst/Controller/NetTestController.py @@ -439,8 +439,6 @@ class NetTestController:
if "from" in cmd_data: cmd["from"] = cmd_data["from"] - if "save_output" in cmd_data: - cmd["save_output"] = cmd_data["save_output"] elif cmd["type"] in ["wait", "intr", "kill"]: # 'proc_id' is used to store bg_id for wait/kill/intr # 'bg_id' is used for test/exec diff --git a/lnst/Controller/Task.py b/lnst/Controller/Task.py index 6f36e86..fefe2cb 100644 --- a/lnst/Controller/Task.py +++ b/lnst/Controller/Task.py @@ -282,7 +282,7 @@ class HostAPI(object): elif arg == "netns": cmd["netns"] = argval elif arg == "save_output": - cmd["save_output"] = argval + pass # now ignored as output is saved always else: msg = "Argument '%s' not recognised by the run() method." % arg raise TaskError(msg) diff --git a/lnst/RecipeCommon/IRQ.py b/lnst/RecipeCommon/IRQ.py index 4548a89..825a2b3 100644 --- a/lnst/RecipeCommon/IRQ.py +++ b/lnst/RecipeCommon/IRQ.py @@ -21,7 +21,7 @@ cpu: integer ''' def pin_dev_irqs(machine, device, cpu): pi = machine.run("grep %s /proc/interrupts | cut -f1 -d: | sed 's/ //'" - % device.get_devname(), save_output=True) + % device.get_devname()) res = pi.get_result() intrs = res["res_data"]["stdout"] for intr in intrs.split('\n'): diff --git a/regression-tests/tests/28/recipe1.py b/regression-tests/tests/28/recipe1.py index a0834e9..ed19f23 100644 --- a/regression-tests/tests/28/recipe1.py +++ b/regression-tests/tests/28/recipe1.py @@ -4,7 +4,7 @@ m1 = ctl.get_host("testmachine1")
m1.sync_resources(modules=["Custom"], tools=[])
-test = m1.run("while true; do echo test; sleep 1; done", bg=True, save_output="yes") +test = m1.run("while true; do echo test; sleep 1; done", bg=True)
ctl.wait(5)
diff --git a/regression-tests/tests/28/recipe2.py b/regression-tests/tests/28/recipe2.py index b47ff5a..7b739bb 100644 --- a/regression-tests/tests/28/recipe2.py +++ b/regression-tests/tests/28/recipe2.py @@ -4,7 +4,7 @@ m1 = ctl.get_host("testmachine1")
m1.sync_resources(modules=["Custom"], tools=[])
-test = m1.run("for i in `seq 5`; do echo test; sleep 1; done", bg=True, save_output="yes") +test = m1.run("for i in `seq 5`; do echo test; sleep 1; done", bg=True)
test.wait()
diff --git a/regression-tests/tests/28/recipe3.py b/regression-tests/tests/28/recipe3.py index 802d93f..9d9fd9b 100644 --- a/regression-tests/tests/28/recipe3.py +++ b/regression-tests/tests/28/recipe3.py @@ -4,7 +4,7 @@ m1 = ctl.get_host("testmachine1")
m1.sync_resources(modules=["Custom"], tools=[])
-test = m1.run("while true; do echo test; sleep 1; done", bg=True, save_output="yes") +test = m1.run("while true; do echo test; sleep 1; done", bg=True)
ctl.wait(5)
diff --git a/regression-tests/tests/28/recipe4.py b/regression-tests/tests/28/recipe4.py index e8e8f99..ae36c37 100644 --- a/regression-tests/tests/28/recipe4.py +++ b/regression-tests/tests/28/recipe4.py @@ -4,7 +4,7 @@ m1 = ctl.get_host("testmachine1")
m1.sync_resources(modules=["Custom"], tools=[])
-test = m1.run("echo test", save_output="yes") +test = m1.run("echo test") output = test.get_result()["res_data"]["stdout"]
custom = ctl.get_module("Custom", options={ "fail": True })
From: Jiri Pirko jiri@mellanox.com
Signed-off-by: Jiri Pirko jiri@mellanox.com --- lnst/Controller/Task.py | 9 +++++++++ 1 file changed, 9 insertions(+)
diff --git a/lnst/Controller/Task.py b/lnst/Controller/Task.py index fefe2cb..1226ce2 100644 --- a/lnst/Controller/Task.py +++ b/lnst/Controller/Task.py @@ -754,6 +754,15 @@ class ProcessAPI(object): """ return self._cmd_res
+ def out(self): + """ + Returns the whole comand result stdout. + + :return: Command result stdout. + :rtype: str + """ + return self.get_result()["res_data"]["stdout"] + def wait(self): """ Blocking wait until the command returns. """ if self._bg_id:
On Sun, Aug 14, 2016 at 11:22:47AM +0200, Jiri Pirko wrote:
From: Jiri Pirko jiri@mellanox.com
Signed-off-by: Jiri Pirko jiri@mellanox.com
Another good idea :)
Acked-by: Ido Schimmel idosch@mellanox.com
lnst/Controller/Task.py | 9 +++++++++ 1 file changed, 9 insertions(+)
diff --git a/lnst/Controller/Task.py b/lnst/Controller/Task.py index fefe2cb..1226ce2 100644 --- a/lnst/Controller/Task.py +++ b/lnst/Controller/Task.py @@ -754,6 +754,15 @@ class ProcessAPI(object): """ return self._cmd_res
- def out(self):
"""
Returns the whole comand result stdout.
s/comand/command/
:return: Command result stdout.
:rtype: str
"""
return self.get_result()["res_data"]["stdout"]
- def wait(self): """ Blocking wait until the command returns. """ if self._bg_id:
-- 2.5.5
Mon, Aug 15, 2016 at 08:49:23AM CEST, idosch@mellanox.com wrote:
On Sun, Aug 14, 2016 at 11:22:47AM +0200, Jiri Pirko wrote:
From: Jiri Pirko jiri@mellanox.com
Signed-off-by: Jiri Pirko jiri@mellanox.com
Another good idea :)
Acked-by: Ido Schimmel idosch@mellanox.com
lnst/Controller/Task.py | 9 +++++++++ 1 file changed, 9 insertions(+)
diff --git a/lnst/Controller/Task.py b/lnst/Controller/Task.py index fefe2cb..1226ce2 100644 --- a/lnst/Controller/Task.py +++ b/lnst/Controller/Task.py @@ -754,6 +754,15 @@ class ProcessAPI(object): """ return self._cmd_res
- def out(self):
"""
Returns the whole comand result stdout.
s/comand/command/
If it is only this will fix it during the apply. Thanks.
:return: Command result stdout.
:rtype: str
"""
return self.get_result()["res_data"]["stdout"]
- def wait(self): """ Blocking wait until the command returns. """ if self._bg_id:
-- 2.5.5
From: Jiri Pirko jiri@mellanox.com
This is handy for processing output of commands producing JSON.
Signed-off-by: Jiri Pirko jiri@mellanox.com --- lnst/Common/ExecCmd.py | 6 +++++- lnst/Common/NetTestCommand.py | 3 ++- lnst/Controller/Task.py | 4 ++++ 3 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/lnst/Common/ExecCmd.py b/lnst/Common/ExecCmd.py index d432c2c..24715ae 100644 --- a/lnst/Common/ExecCmd.py +++ b/lnst/Common/ExecCmd.py @@ -51,7 +51,7 @@ def log_output(log_func, out_type, out): "----------------------------" % (out_type, out))
-def exec_cmd(cmd, die_on_err=True, log_outputs=True, report_stderr=False): +def exec_cmd(cmd, die_on_err=True, log_outputs=True, report_stderr=False, json=False): cmd = cmd.rstrip(" ") logging.debug("Executing: "%s"" % cmd) subp = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, @@ -72,4 +72,8 @@ def exec_cmd(cmd, die_on_err=True, log_outputs=True, report_stderr=False): logging.error(err) raise err
+ if json: + import json + data_stdout = json.loads(data_stdout) + return data_stdout, data_stderr diff --git a/lnst/Common/NetTestCommand.py b/lnst/Common/NetTestCommand.py index 3c290dc..52f2a73 100644 --- a/lnst/Common/NetTestCommand.py +++ b/lnst/Common/NetTestCommand.py @@ -407,7 +407,8 @@ class NetTestCommandExec(NetTestCommandGeneric): stdout, stderr = self.exec_from(self._command["from"], self._command["command"]) else: - stdout, stderr = self.exec_cmd(self._command["command"]) + json = True if "json" in self._command else False + stdout, stderr = self.exec_cmd(self._command["command"], json=json) res_data = {"stdout": stdout, "stderr": stderr} self.set_pass(res_data) except ExecCmdFail as e: diff --git a/lnst/Controller/Task.py b/lnst/Controller/Task.py index 1226ce2..80e4b75 100644 --- a/lnst/Controller/Task.py +++ b/lnst/Controller/Task.py @@ -242,6 +242,8 @@ class HostAPI(object): :type timeout: int :param tool: Run from a tool (the same as 'from' in XML). :type tool: string + :param json: Process JSON output into dictionary. + :type json: bool
:return: A handle for process. :rtype: ProcessAPI @@ -283,6 +285,8 @@ class HostAPI(object): cmd["netns"] = argval elif arg == "save_output": pass # now ignored as output is saved always + elif arg == "json": + cmd["json"] = argval else: msg = "Argument '%s' not recognised by the run() method." % arg raise TaskError(msg)
On Sun, Aug 14, 2016 at 11:22:46AM +0200, Jiri Pirko wrote:
From: Jiri Pirko jiri@mellanox.com
Just ignore the user option and save the stderr and stdout always. Allows to shorten the run method call from tasks.
Signed-off-by: Jiri Pirko jiri@mellanox.com
Acked-by: Ido Schimmel idosch@mellanox.com
Good idea. I can use it in my QoS recipes as well since I have "save_output='yes'" in a couple of places.
Sun, Aug 14, 2016 at 11:22:46AM CEST, jiri@resnulli.us wrote:
From: Jiri Pirko jiri@mellanox.com
Just ignore the user option and save the stderr and stdout always. Allows to shorten the run method call from tasks.
And what if the data is too big? Have you tested with e.g. netperf?
-Jan
Mon, Aug 15, 2016 at 10:09:16AM CEST, jtluka@redhat.com wrote:
Sun, Aug 14, 2016 at 11:22:46AM CEST, jiri@resnulli.us wrote:
From: Jiri Pirko jiri@mellanox.com
Just ignore the user option and save the stderr and stdout always. Allows to shorten the run method call from tasks.
And what if the data is too big? Have you tested with e.g. netperf?
How big? Will stdout be ever mbytes? if not which we can assume, this is not an issue
-Jan
Mon, Aug 15, 2016 at 10:34:48AM CEST, jiri@resnulli.us wrote:
Mon, Aug 15, 2016 at 10:09:16AM CEST, jtluka@redhat.com wrote:
Sun, Aug 14, 2016 at 11:22:46AM CEST, jiri@resnulli.us wrote:
From: Jiri Pirko jiri@mellanox.com
Just ignore the user option and save the stderr and stdout always. Allows to shorten the run method call from tasks.
And what if the data is too big? Have you tested with e.g. netperf?
How big? Will stdout be ever mbytes? if not which we can assume, this is not an issue
Another issue I see here is that all of the stdout and stderr will that way appear in Summary at the end of the test. That means every Exec command you have in recipe will have this data there as it's kept in res_data. So even a smaller output like 100 lines will make summary look ugly.
-Jan
Mon, Aug 15, 2016 at 04:08:04PM CEST, jtluka@redhat.com wrote:
Mon, Aug 15, 2016 at 10:34:48AM CEST, jiri@resnulli.us wrote:
Mon, Aug 15, 2016 at 10:09:16AM CEST, jtluka@redhat.com wrote:
Sun, Aug 14, 2016 at 11:22:46AM CEST, jiri@resnulli.us wrote:
From: Jiri Pirko jiri@mellanox.com
Just ignore the user option and save the stderr and stdout always. Allows to shorten the run method call from tasks.
And what if the data is too big? Have you tested with e.g. netperf?
How big? Will stdout be ever mbytes? if not which we can assume, this is not an issue
Another issue I see here is that all of the stdout and stderr will that way appear in Summary at the end of the test. That means every Exec command you have in recipe will have this data there as it's kept in res_data. So even a smaller output like 100 lines will make summary look ugly.
Will remove in follow-up
-Jan
lnst-developers@lists.fedorahosted.org