Merge plainbox-provider-checkbox:phlin/code-style-fix into plainbox-provider-checkbox:master

Proposed by Po-Hsu Lin
Status: Merged
Approved by: Po-Hsu Lin
Approved revision: f429d2a74057f1fe7c4c58bdccd7c1ca239a08ff
Merged at revision: 4c7a9c3bf9e2c88b5f5ef85524ac25b2c5ce5db2
Proposed branch: plainbox-provider-checkbox:phlin/code-style-fix
Merge into: plainbox-provider-checkbox:master
Diff against target: 96 lines (+17/-23)
1 file modified
bin/kernel_taint_test.py (+17/-23)
Reviewer Review Type Date Requested Status
Maciej Kisielewski Approve
Jonathan Cave Pending
Review via email: mp+407718@code.launchpad.net

This proposal supersedes a proposal from 2021-07-21.

Commit message

This patch will:
1. move report_failures() to main(), remove unnecessary parentheses

   The report_failures() is now just return whether the test pass or fail
   move the code piece to main() and update the docstring accordingly.

2. remove extra print for kernel taint info
   The tainted bit value and its message will be printed at the beginning
   of this if statement, there is no need to print it again.

3. Use raise SystemExit() for taint_file not found exeception.

To post a comment you must log in.
Revision history for this message
Maciej Kisielewski (kissiel) wrote : Posted in a previous version of this proposal

Thanks for the cleanup!

Some time ago we introduced a guideline for contributions to checkbox and its family. We started using prefixes for what the commit does, so it's easier to create relnotes and overall navigate through the repos.
"""
In addition, if it makes sense to do so, prefix the title with one of the following terms:
Add
Change
Remove
Fix
"""
If you could be so kind and amend the commits with prefix like that it would be awesome.

There's also one thing I highlighted in the diff below. Feel free to not do anything about it :D

Revision history for this message
Po-Hsu Lin (cypressyew) wrote : Posted in a previous version of this proposal

Hi Maciej,
Thanks for the review, I have the title amended and these 2 commits squashed into 1, with your inline diff suggestion included. Please find the resubmitted MP.
Thanks!
Sam

Revision history for this message
Maciej Kisielewski (kissiel) wrote :

Thank you very much!
Looks good! +1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/bin/kernel_taint_test.py b/bin/kernel_taint_test.py
2index 2ee70c1..677d127 100755
3--- a/bin/kernel_taint_test.py
4+++ b/bin/kernel_taint_test.py
5@@ -44,10 +44,10 @@ def find_taints(taint_file):
6 f = open(taint_file, "r")
7 taints = int(f.read())
8 except OSError:
9- taints = -1
10- print("Kernel taint file ({}) not found!".format(taint_file))
11+ raise SystemExit(
12+ "Kernel taint file ({}) not found!".format(taint_file))
13 print("Kernel taint value is {}".format(taints))
14- return(taints)
15+ return taints
16
17
18 def get_modules():
19@@ -57,7 +57,7 @@ def get_modules():
20 for line in lsmod_output:
21 if line and 'Module' not in line:
22 modules.append(line.split()[0])
23- return(modules)
24+ return modules
25
26
27 def process_out_of_tree_modules(modules):
28@@ -68,7 +68,7 @@ def process_out_of_tree_modules(modules):
29 if not check_output(shlex.split(cmd),
30 universal_newlines=True):
31 mod_list.append(mod)
32- return(mod_list)
33+ return mod_list
34
35
36 def process_GPL_incompatible_modules(modules):
37@@ -80,7 +80,7 @@ def process_GPL_incompatible_modules(modules):
38 universal_newlines=True).strip()
39 if "GPL" not in license and "MIT" not in license:
40 mod_list.append((mod, license))
41- return(mod_list)
42+ return mod_list
43
44
45 def remove_ignored_modules(modules):
46@@ -98,11 +98,18 @@ def remove_ignored_modules(modules):
47 modules.remove(ignore_mod)
48 except ValueError:
49 pass
50- return(modules)
51+ return modules
52
53
54-def report_failures(taints):
55- """Report the failure code and its meaning(s)."""
56+def main():
57+ """Print out the tainted state code and its meaning(s)."""
58+ parser = ArgumentParser()
59+ parser.add_argument('--taint-file',
60+ default="/proc/sys/kernel/tainted",
61+ help='The file that holds the taint information')
62+ args = parser.parse_args()
63+ taints = find_taints(args.taint_file)
64+
65 # Below meaning strings are taken from
66 # https://www.kernel.org/doc/html/latest/admin-guide/tainted-kernels.html
67 taint_meanings = ["proprietary module was loaded",
68@@ -151,8 +158,8 @@ def report_failures(taints):
69 print("* Out of Tree modules found, "
70 "but they are expected and OK")
71 else:
72- print("Taint bit value: {} ({})".format(i, taint_meanings[i]))
73 count += 1
74+
75 if count == 0:
76 # else case below contains expected issue in case 0 / 11 / 12
77 if not taints:
78@@ -162,18 +169,5 @@ def report_failures(taints):
79 return 1
80
81
82-def main():
83- parser = ArgumentParser()
84- parser.add_argument('--taint-file',
85- default="/proc/sys/kernel/tainted",
86- help='The file that holds the taint information')
87- args = parser.parse_args()
88- taints = find_taints(args.taint_file)
89- if taints < 0:
90- return taints
91-
92- return(report_failures(taints))
93-
94-
95 if __name__ == '__main__':
96 sys.exit(main())

Subscribers

People subscribed via source and target branches

to all changes: