[autotest-client-tests][PATCH 2/2] UBUNTU: SAUCE: ubuntu_boot: move report_failures() to main() and code cleanup
Po-Hsu Lin
po-hsu.lin at canonical.com
Wed Mar 30 10:12:06 UTC 2022
The report_failures() is now just return whether the test pass or fail
move the code piece to main() and update the docstring accordingly.
Remove unnecessary parentheses for return
Use raise SystemExit() for taint_file not found exeception instead
of the out-of-range (0-255) value of -1.
Signed-off-by: Po-Hsu Lin <po-hsu.lin at canonical.com>
---
ubuntu_boot/kernel_taint_test.py | 32 +++++++++++++-------------------
1 file changed, 13 insertions(+), 19 deletions(-)
diff --git a/ubuntu_boot/kernel_taint_test.py b/ubuntu_boot/kernel_taint_test.py
index 73177089..0e8a7eaa 100755
--- a/ubuntu_boot/kernel_taint_test.py
+++ b/ubuntu_boot/kernel_taint_test.py
@@ -44,10 +44,10 @@ def find_taints(taint_file):
f = open(taint_file, "r")
taints = int(f.read())
except OSError:
- taints = -1
- print("Kernel taint file ({}) not found!".format(taint_file))
+ raise SystemExit(
+ "Kernel taint file ({}) not found!".format(taint_file))
print("Kernel taint value is {}".format(taints))
- return(taints)
+ return taints
def get_modules():
@@ -57,7 +57,7 @@ def get_modules():
for line in lsmod_output:
if line and 'Module' not in line:
modules.append(line.split()[0])
- return(modules)
+ return modules
def print_out_of_tree_modules(modules):
@@ -79,8 +79,15 @@ def print_GPL_incompatible_modules(modules):
print(" %s: %s" % (mod, license))
-def report_failures(taints):
- """Report the failure code and its meaning(s)."""
+def main():
+ """Print out the tainted state code and its meaning(s)."""
+ parser = ArgumentParser()
+ parser.add_argument('--taint-file',
+ default="/proc/sys/kernel/tainted",
+ help='The file that holds the taint information')
+ args = parser.parse_args()
+ taints = find_taints(args.taint_file)
+
# Below meaning strings are taken from
# https://www.kernel.org/doc/html/latest/admin-guide/tainted-kernels.html
taint_meanings = ["proprietary module was loaded",
@@ -124,18 +131,5 @@ def report_failures(taints):
return 1
-def main():
- parser = ArgumentParser()
- parser.add_argument('--taint-file',
- default="/proc/sys/kernel/tainted",
- help='The file that holds the taint information')
- args = parser.parse_args()
- taints = find_taints(args.taint_file)
- if taints < 0:
- return taints
-
- return(report_failures(taints))
-
-
if __name__ == '__main__':
sys.exit(main())
--
2.25.1
More information about the kernel-team
mailing list