This method is used for detecting if program is present in $PATH
Signed-off-by: Jiri Prochazka jprochaz@redhat.com --- lnst/Common/Utils.py | 12 ++++++++++++ 1 file changed, 12 insertions(+)
diff --git a/lnst/Common/Utils.py b/lnst/Common/Utils.py index b42fc86..22d2925 100644 --- a/lnst/Common/Utils.py +++ b/lnst/Common/Utils.py @@ -278,3 +278,15 @@ def deprecated(func): % (func.__name__, self.__class__.__name__)) return func(self, *args, **kwargs) return log + +def is_installed(program): + """ + Returns True if program is detected by which, False otherwise + """ + cmd = "which %s" % program + try: + subprocess.check_call(cmd, shell=True, stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + return True + except subprocess.CalledProcessError: + return False
If netperf (on client side) or netserver (on server side) is present in recipe and is not installed on slave, test will FAIL and logs relevant error message
Signed-off-by: Jiri Prochazka jprochaz@redhat.com --- test_modules/Netperf.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/test_modules/Netperf.py b/test_modules/Netperf.py index bbd6ea0..6703fc0 100644 --- a/test_modules/Netperf.py +++ b/test_modules/Netperf.py @@ -11,7 +11,7 @@ import errno import re from lnst.Common.TestsCommon import TestGeneric from lnst.Common.ShellProcess import ShellProcess -from lnst.Common.Utils import std_deviation +from lnst.Common.Utils import std_deviation, is_installed
class Netperf(TestGeneric):
@@ -318,9 +318,20 @@ class Netperf(TestGeneric): cmd = self._compose_cmd() logging.debug("compiled command: %s" % cmd) if self._role == "client": + if not is_installed("netperf"): + res_data = {} + res_data["msg"] = "Netperf is not installed on this machine!" + logging.error(res_data["msg"]) + return self.set_fail(res_data) + (rv, res_data) = self._run_client(cmd) if rv == False: return self.set_fail(res_data) return self.set_pass(res_data) elif self._role == "server": + if not is_installed("netserver"): + res_data = {} + res_data["msg"] = "Netserver is not installed on this machine!" + logging.error(res_data["msg"]) + return self.set_fail(res_data) self._run_server(cmd)
If Iperf is present in recipe and is not installed on slave machine, test will FAIL and logs relevant error message
Signed-off-by: Jiri Prochazka jprochaz@redhat.com --- test_modules/Iperf.py | 6 ++++++ 1 file changed, 6 insertions(+)
diff --git a/test_modules/Iperf.py b/test_modules/Iperf.py index 09cc6b4..77bd1a0 100644 --- a/test_modules/Iperf.py +++ b/test_modules/Iperf.py @@ -13,6 +13,7 @@ import re from lnst.Common.TestsCommon import TestGeneric from lnst.Common.ExecCmd import exec_cmd from lnst.Common.ShellProcess import ShellProcess +from lnst.Common.Utils import is_installed
class Iperf(TestGeneric): def _compose_iperf_cmd(self, role): @@ -138,6 +139,11 @@ class Iperf(TestGeneric): role = self.get_mopt("role") cmd = self._compose_iperf_cmd(role) logging.debug("compiled command: %s" % cmd) + if not is_installed("iperf"): + res_data = {} + res_data["msg"] = "Iperf is not installed on this machine!" + logging.error(res_data["msg"]) + return self.set_fail(res_data)
if role == "server": logging.debug("running as server ...")
Because installation check for netperf is now done, output message is now obsolete
Signed-off-by: Jiri Prochazka jprochaz@redhat.com --- test_modules/Netperf.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/test_modules/Netperf.py b/test_modules/Netperf.py index 6703fc0..21d18b8 100644 --- a/test_modules/Netperf.py +++ b/test_modules/Netperf.py @@ -301,9 +301,7 @@ class Netperf(TestGeneric): (rate, rate_deviation)
if rv != 0 and self._runs == 1: - res_data["msg"] = "Could not get performance throughput! Are you "\ - "sure netperf is installed on both machines and "\ - "machines are mutually accessible?" + res_data["msg"] = "Could not get performance throughput!" logging.info(res_data["msg"]) return (False, res_data) elif rv != 0 and self._runs > 1:
If execution of netperf fails, for example because selected test is not compiled, show the output for more detailed explanation.
Signed-off-by: Jiri Prochazka jprochaz@redhat.com --- test_modules/Netperf.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/test_modules/Netperf.py b/test_modules/Netperf.py index 21d18b8..868cca0 100644 --- a/test_modules/Netperf.py +++ b/test_modules/Netperf.py @@ -249,8 +249,10 @@ class Netperf(TestGeneric): except OSError as e: if e.errno == errno.EINTR: client.kill() + + output = client.read_nonblocking() + if ret_code == 0: - output = client.read_nonblocking() results.append(self._parse_output(output)) rates.append(results[-1]["rate"])
Tue, Aug 25, 2015 at 04:53:34PM CEST, jprochaz@redhat.com wrote:
This method is used for detecting if program is present in $PATH
Signed-off-by: Jiri Prochazka jprochaz@redhat.com
lnst/Common/Utils.py | 12 ++++++++++++ 1 file changed, 12 insertions(+)
diff --git a/lnst/Common/Utils.py b/lnst/Common/Utils.py index b42fc86..22d2925 100644 --- a/lnst/Common/Utils.py +++ b/lnst/Common/Utils.py @@ -278,3 +278,15 @@ def deprecated(func): % (func.__name__, self.__class__.__name__)) return func(self, *args, **kwargs) return log
+def is_installed(program):
- """
- Returns True if program is detected by which, False otherwise
- """
- cmd = "which %s" % program
- try:
subprocess.check_call(cmd, shell=True, stdout=subprocess.PIPE,stderr=subprocess.PIPE)return True- except subprocess.CalledProcessError:
return False-- 2.4.3
LNST-developers mailing list LNST-developers@lists.fedorahosted.org https://lists.fedorahosted.org/mailman/listinfo/lnst-developers
ack
Acked-by: Jan Tluka jtluka@redhat.com
lnst-developers@lists.fedorahosted.org