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
diff --git a/checkbox_support/scripts/run_watcher.py b/checkbox_support/scripts/run_watcher.py
index 24653a5..7248792 100644
--- a/checkbox_support/scripts/run_watcher.py
+++ b/checkbox_support/scripts/run_watcher.py
@@ -40,7 +40,8 @@ class USBWatcher:
40 "USB Mass Storage device detected": False40 "USB Mass Storage device detected": False
41 },41 },
42 "removal": {42 "removal": {
43 "USB disconnect, device number": False43 "USB disconnect, device number": False,
44 "Aborting journal on device": False
44 }45 }
45 }46 }
4647
@@ -62,7 +63,7 @@ class USBWatcher:
62 while p.poll():63 while p.poll():
63 if j.process() != journal.APPEND:64 if j.process() != journal.APPEND:
64 continue65 continue
65 self._callback([e['MESSAGE'] for e in j if e])66 self._callback([e['MESSAGE'] for e in j if e and 'MESSAGE' in e])
6667
67 def _callback(self, lines):68 def _callback(self, lines):
68 for line in lines:69 for line in lines:
@@ -94,7 +95,8 @@ class USBWatcher:
94 # insertion detection95 # insertion detection
95 if (96 if (
96 self.args.testcase == "insertion" and97 self.args.testcase == "insertion" and
97 self.FLAG_DETECTION["insertion"]["USB Mass Storage device detected"] and98 self.FLAG_DETECTION["insertion"][
99 "USB Mass Storage device detected"] and
98 self.MOUNTED_PARTITION100 self.MOUNTED_PARTITION
99 ):101 ):
100 device = ""102 device = ""
@@ -122,6 +124,15 @@ class USBWatcher:
122 logger.info("USB3 insertion test passed.")124 logger.info("USB3 insertion test passed.")
123 self._write_usb_info()125 self._write_usb_info()
124 sys.exit()126 sys.exit()
127 elif (
128 self.args.testcase == "insertion" and
129 self.args.usb_type == "mediacard" and
130 self.MOUNTED_PARTITION
131 ):
132 logger.info("usable partition: %s" % self.MOUNTED_PARTITION)
133 logger.info("%s insertion test passed." % self.args.usb_type)
134 self._write_usb_info()
135 sys.exit()
125 # removal detection136 # removal detection
126 if (137 if (
127 self.args.testcase == "removal" and138 self.args.testcase == "removal" and
@@ -130,6 +141,14 @@ class USBWatcher:
130 logger.info("Removal test passed.")141 logger.info("Removal test passed.")
131 self._remove_usb_info()142 self._remove_usb_info()
132 sys.exit()143 sys.exit()
144 elif (
145 self.args.testcase == "removal" and
146 self.args.usb_type == "mediacard" and
147 self.FLAG_DETECTION["removal"]["Aborting journal on device"]
148 ):
149 logger.info("Removal test passed.")
150 self._remove_usb_info()
151 sys.exit()
133152
134 def _write_usb_info(self):153 def _write_usb_info(self):
135 """154 """
@@ -153,7 +172,7 @@ class USBWatcher:
153 file_to_share.close()172 file_to_share.close()
154173
155 def _remove_usb_info(self):174 def _remove_usb_info(self):
156 """remove usb strage info from $PLAINBOX_SESSION_SHARE."""175 """remove usb storage info from $PLAINBOX_SESSION_SHARE."""
157 plainbox_session_share = os.environ.get('PLAINBOX_SESSION_SHARE')176 plainbox_session_share = os.environ.get('PLAINBOX_SESSION_SHARE')
158 if not plainbox_session_share:177 if not plainbox_session_share:
159 logger.error("no env var PLAINBOX_SESSION_SHARE")178 logger.error("no env var PLAINBOX_SESSION_SHARE")
@@ -171,8 +190,8 @@ class USBWatcher:
171 detected after USB_ACTION_TIMEOUT secs190 detected after USB_ACTION_TIMEOUT secs
172 """191 """
173 logger.error(192 logger.error(
174 "no USB storage %s was reported in systemd journal"193 "no %s storage %s was reported in systemd journal",
175 % self.args.testcase)194 self.args.usb_type, self.args.testcase)
176 sys.exit(1)195 sys.exit(1)
177196
178197
@@ -182,7 +201,7 @@ def main():
182 choices=['insertion', 'removal'],201 choices=['insertion', 'removal'],
183 help=("insertion or removal"))202 help=("insertion or removal"))
184 parser.add_argument('usb_type',203 parser.add_argument('usb_type',
185 choices=['usb2', 'usb3'],204 choices=['usb2', 'usb3', 'mediacard'],
186 help=("usb2 or usb3"))205 help=("usb2 or usb3"))
187 args = parser.parse_args()206 args = parser.parse_args()
188 watcher = USBWatcher(args)207 watcher = USBWatcher(args)

Subscribers

People subscribed via source and target branches