Merge ~sylvain-pineau/checkbox-support:run_watcher_mediacard into checkbox-support:master

Proposed by Sylvain Pineau
Status: Merged
Approved by: Sylvain Pineau
Approved revision: 1a41f31e702f864d9a36110ce22f4ec0ef188a56
Merged at revision: 32cba01f50c4f758cf416942317d4eb72b3ff90a
Proposed branch: ~sylvain-pineau/checkbox-support:run_watcher_mediacard
Merge into: checkbox-support:master
Diff against target: 93 lines (+26/-7)
1 file modified
checkbox_support/scripts/run_watcher.py (+26/-7)
Reviewer Review Type Date Requested Status
Paul Larson Approve
Review via email: mp+361224@code.launchpad.net

Description of the change

Minor updates to the run watcher script to detect mediacard insert/removal w/o udisks2 events in systemd logs.

Tested on bionic

To post a comment you must log in.
Revision history for this message
Paul Larson (pwlars) wrote :

lgtm

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/checkbox_support/scripts/run_watcher.py b/checkbox_support/scripts/run_watcher.py
2index 24653a5..7248792 100644
3--- a/checkbox_support/scripts/run_watcher.py
4+++ b/checkbox_support/scripts/run_watcher.py
5@@ -40,7 +40,8 @@ class USBWatcher:
6 "USB Mass Storage device detected": False
7 },
8 "removal": {
9- "USB disconnect, device number": False
10+ "USB disconnect, device number": False,
11+ "Aborting journal on device": False
12 }
13 }
14
15@@ -62,7 +63,7 @@ class USBWatcher:
16 while p.poll():
17 if j.process() != journal.APPEND:
18 continue
19- self._callback([e['MESSAGE'] for e in j if e])
20+ self._callback([e['MESSAGE'] for e in j if e and 'MESSAGE' in e])
21
22 def _callback(self, lines):
23 for line in lines:
24@@ -94,7 +95,8 @@ class USBWatcher:
25 # insertion detection
26 if (
27 self.args.testcase == "insertion" and
28- self.FLAG_DETECTION["insertion"]["USB Mass Storage device detected"] and
29+ self.FLAG_DETECTION["insertion"][
30+ "USB Mass Storage device detected"] and
31 self.MOUNTED_PARTITION
32 ):
33 device = ""
34@@ -122,6 +124,15 @@ class USBWatcher:
35 logger.info("USB3 insertion test passed.")
36 self._write_usb_info()
37 sys.exit()
38+ elif (
39+ self.args.testcase == "insertion" and
40+ self.args.usb_type == "mediacard" and
41+ self.MOUNTED_PARTITION
42+ ):
43+ logger.info("usable partition: %s" % self.MOUNTED_PARTITION)
44+ logger.info("%s insertion test passed." % self.args.usb_type)
45+ self._write_usb_info()
46+ sys.exit()
47 # removal detection
48 if (
49 self.args.testcase == "removal" and
50@@ -130,6 +141,14 @@ class USBWatcher:
51 logger.info("Removal test passed.")
52 self._remove_usb_info()
53 sys.exit()
54+ elif (
55+ self.args.testcase == "removal" and
56+ self.args.usb_type == "mediacard" and
57+ self.FLAG_DETECTION["removal"]["Aborting journal on device"]
58+ ):
59+ logger.info("Removal test passed.")
60+ self._remove_usb_info()
61+ sys.exit()
62
63 def _write_usb_info(self):
64 """
65@@ -153,7 +172,7 @@ class USBWatcher:
66 file_to_share.close()
67
68 def _remove_usb_info(self):
69- """remove usb strage info from $PLAINBOX_SESSION_SHARE."""
70+ """remove usb storage info from $PLAINBOX_SESSION_SHARE."""
71 plainbox_session_share = os.environ.get('PLAINBOX_SESSION_SHARE')
72 if not plainbox_session_share:
73 logger.error("no env var PLAINBOX_SESSION_SHARE")
74@@ -171,8 +190,8 @@ class USBWatcher:
75 detected after USB_ACTION_TIMEOUT secs
76 """
77 logger.error(
78- "no USB storage %s was reported in systemd journal"
79- % self.args.testcase)
80+ "no %s storage %s was reported in systemd journal",
81+ self.args.usb_type, self.args.testcase)
82 sys.exit(1)
83
84
85@@ -182,7 +201,7 @@ def main():
86 choices=['insertion', 'removal'],
87 help=("insertion or removal"))
88 parser.add_argument('usb_type',
89- choices=['usb2', 'usb3'],
90+ choices=['usb2', 'usb3', 'mediacard'],
91 help=("usb2 or usb3"))
92 args = parser.parse_args()
93 watcher = USBWatcher(args)

Subscribers

People subscribed via source and target branches