From: Jiri Pirko <jiri(a)mellanox.com>
This is dependency for "Custom" test module. Allows it to get all
available single-value options.
Signed-off-by: Jiri Pirko <jiri(a)mellanox.com>
---
v2->v3:
- removed forgotten "print" pointed out by jprochaz
v1->v2:
- no change
---
lnst/Common/TestsCommon.py | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/lnst/Common/TestsCommon.py b/lnst/Common/TestsCommon.py
index e29a609..accb6b8 100644
--- a/lnst/Common/TestsCommon.py
+++ b/lnst/Common/TestsCommon.py
@@ -127,6 +127,14 @@ class TestGeneric(NetTestCommandGeneric):
'''
return self.get_multi_opt(name, mandatory=True, opt_type=opt_type)
+ def get_single_opts(self):
+ opts = {}
+ for key in self._command["options"]:
+ item = self._command["options"][key]
+ if len(item) == 1:
+ opts[key] = item[0]["value"]
+ return opts
+
def _format_cmd_res_header(self):
cmd_val = self._command["module"]
cmd_type = self._command["type"]
--
2.4.3
Show replies by date
From: Jiri Pirko <jiri(a)mellanox.com>
This is very dump test module. All it knows to do is to get option named
"fail" and according to the value, it either fails or passes. Also, it
takes all options user passed to this test module and pushes them into
result data.
Purpose of this test module is to be used from python tasks, providing
possibility to do "embedded" tests directly inside python tasks.
Signed-off-by: Jiri Pirko <jiri(a)mellanox.com>
---
v2->v3:
- no change
v1->v2:
- whitespace issue fixed
---
test_modules/Custom.py | 31 +++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+)
create mode 100644 test_modules/Custom.py
diff --git a/test_modules/Custom.py b/test_modules/Custom.py
new file mode 100644
index 0000000..ac3c742
--- /dev/null
+++ b/test_modules/Custom.py
@@ -0,0 +1,31 @@
+"""
+This module defines custom test
+
+Copyright 2016 Mellanox Technologies. All rights reserved.
+Licensed under the GNU General Public License, version 2 as
+published by the Free Software Foundation; see COPYING for details.
+"""
+
+__author__ = """
+jiri(a)mellanox.com (Jiri Pirko)
+"""
+
+from lnst.Common.TestsCommon import TestGeneric
+from lnst.Common.Utils import bool_it
+
+class Custom(TestGeneric):
+ def run(self):
+ fail_str = self.get_opt("fail")
+ if not fail_str:
+ fail = False
+ else:
+ fail = bool_it(fail_str)
+
+ res_data = self.get_single_opts()
+ if "fail" in res_data:
+ del(res_data["fail"])
+
+ if fail:
+ return self.set_fail(res_data)
+
+ return self.set_pass(res_data)
--
2.4.3