Merge lp:~cr3/checkbox/remove_storage_watcher_refactor into lp:checkbox

Proposed by Marc Tardif
Status: Merged
Merged at revision: 1187
Proposed branch: lp:~cr3/checkbox/remove_storage_watcher_refactor
Merge into: lp:checkbox
Diff against target: 157 lines (+45/-39)
3 files modified
jobs/firewire.txt.in (+2/-2)
jobs/usb.txt.in (+2/-2)
scripts/removable_storage_watcher (+41/-35)
To merge this branch: bzr merge lp:~cr3/checkbox/remove_storage_watcher_refactor
Reviewer Review Type Date Requested Status
Brendan Donegan (community) Approve
Marc Tardif (community) Needs Resubmitting
Review via email: mp+89485@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Brendan Donegan (brendan-donegan) wrote :

They aren't required options, they're required arguments ;) If you want to leave this change as it is then the jobs need to be updated to say:

removable_storage_watcher insert usb

instead of:

removable_storage_watcher --device=usb --action=insert

Personally I think the latter is clearer.

The other changes are fine though. Thanks!

review: Needs Fixing
1188. By Marc Tardif

Updated jobs to match changed arguments in removable_storage_watcher.

Revision history for this message
Marc Tardif (cr3) wrote :

Good catch, I updated the jobs accordingly and resubmitting. The new syntax seems readable though, it reminds me of apt-get install foo or bzr pull bar. In other words, the first argument is an action and the second argument a target on which to perform the action.

review: Needs Resubmitting
Revision history for this message
Brendan Donegan (brendan-donegan) wrote :

In the interest of moving things forward, I'll not argue with that logic. Since the changes you made do seem to leave the script functionally the same, I'll merge this. I have noticed a few undesirable glitches but these were present before the refactoring too, so I'll sort them out in good time.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'jobs/firewire.txt.in'
2--- jobs/firewire.txt.in 2012-01-20 16:23:54 +0000
3+++ jobs/firewire.txt.in 2012-01-20 22:07:30 +0000
4@@ -1,6 +1,6 @@
5 plugin: manual
6 name: firewire/insert
7-command: removable_storage_watcher --device=firewire --action=insert
8+command: removable_storage_watcher insert firewire
9 _description:
10 PURPOSE:
11 This test will check the system can detect the insertion of a FireWire HDD
12@@ -23,7 +23,7 @@
13 plugin: manual
14 name: firewire/remove
15 depends: firewire/storage-test
16-command: removable_storage_watcher --device=firewire --action=remove
17+command: removable_storage_watcher remove firewire
18 _description:
19 PURPOSE:
20 This test will check the system can detect the removal of a FireWire HDD
21
22=== modified file 'jobs/usb.txt.in'
23--- jobs/usb.txt.in 2012-01-20 10:50:13 +0000
24+++ jobs/usb.txt.in 2012-01-20 22:07:30 +0000
25@@ -51,7 +51,7 @@
26 name: usb/insert
27 depends: usb/detect
28 requires: package.name == 'linux'
29-command: removable_storage_watcher --device=usb --action=insert
30+command: removable_storage_watcher insert usb
31 _description:
32 PURPOSE:
33 This test will check that the system correctly detects the insertion of
34@@ -68,7 +68,7 @@
35 name: usb/remove
36 depends: usb/storage-automated
37 requires: package.name == 'linux'
38-command: removable_storage_watcher --device=usb --action=remove
39+command: removable_storage_watcher remove usb
40 _description:
41 PURPOSE:
42 This test will check that the system correctly detects the removal of
43
44=== modified file 'scripts/removable_storage_watcher'
45--- scripts/removable_storage_watcher 2012-01-20 10:40:36 +0000
46+++ scripts/removable_storage_watcher 2012-01-20 22:07:30 +0000
47@@ -1,25 +1,43 @@
48 #!/usr/bin/python
49
50 import sys
51-import signal
52 import gobject
53 import dbus
54
55 from argparse import ArgumentParser
56 from dbus.mainloop.glib import DBusGMainLoop
57
58+
59 class StorageDeviceListener(object):
60
61- def timeout(self):
62- print "Ten seconds has expired waiting for the device to be inserted."
63- self.error = 1
64- self.loop.quit()
65+ def __init__(self, action, device):
66+ self._action = action
67+ self._device = device
68+ self._bus = dbus.SystemBus(mainloop=DBusGMainLoop())
69+ self._loop = gobject.MainLoop()
70+
71+ def check(self, timeout):
72+ if self._action == 'insert':
73+ self._bus.add_signal_receiver(self.add_detected, signal_name='DeviceAdded', dbus_interface='org.freedesktop.UDisks')
74+ elif self._action == 'remove':
75+ self._bus.add_signal_receiver(self.remove_detected, signal_name='DeviceRemoved', dbus_interface='org.freedesktop.UDisks')
76+
77+ error = False
78+ def timeout_callback():
79+ print "%s seconds have expired waiting for the device to be inserted." % timeout
80+ global error
81+ error = True
82+ self._loop.quit()
83+
84+ gobject.timeout_add_seconds(timeout, timeout_callback)
85+ self._loop.run()
86+
87+ return error
88
89 def job_change_detected(self, device, job_in_progress, job_id, job_num_tasks, job_cur_task_id, job_cur_task_percentage):
90 if job_id == "FilesystemMount" and self.is_device_inserted():
91 print "Expected device %s inserted" % self._device
92- self.error = 0
93- self.loop.quit()
94+ self._loop.quit()
95
96 def add_detected(self, added_path):
97 self._bus.add_signal_receiver(self.job_change_detected, signal_name='DeviceJobChanged', dbus_interface='org.freedesktop.UDisks')
98@@ -27,14 +45,13 @@
99 def remove_detected(self, removed_path):
100 if not self.is_device_inserted():
101 print "Expected device %s has been removed" % self._device
102- self.error = 0
103-
104- self.loop.quit()
105-
106+
107+ self._loop.quit()
108+
109 def is_device_inserted(self):
110 ud_manager_obj = self._bus.get_object("org.freedesktop.UDisks", "/org/freedesktop/UDisks")
111 ud_manager = dbus.Interface(ud_manager_obj, 'org.freedesktop.UDisks')
112-
113+
114 for dev in ud_manager.EnumerateDevices():
115 try:
116 device_obj = self._bus.get_object("org.freedesktop.UDisks", dev)
117@@ -46,28 +63,17 @@
118 pass
119
120 return False
121-
122- def __init__(self, device, action):
123- self._device = device
124- self._action = action
125- self._bus = dbus.SystemBus(mainloop=DBusGMainLoop())
126- self.loop = gobject.MainLoop()
127- self.error = 0
128-
129- if self._action == 'insert':
130- self._bus.add_signal_receiver(self.add_detected, signal_name='DeviceAdded', dbus_interface='org.freedesktop.UDisks')
131- elif self._action == 'remove':
132- self._bus.add_signal_receiver(self.remove_detected, signal_name='DeviceRemoved', dbus_interface='org.freedesktop.UDisks')
133-
134- gobject.timeout_add_seconds(10, self.timeout)
135-
136-if __name__ == "__main__":
137+
138+def main():
139 parser = ArgumentParser(description="Wait for the specified device to be inserted or removed.")
140- parser.add_argument('--device', required=True, choices=['usb','firewire','sdio'])
141- parser.add_argument('--action', required=True, choices=['insert','remove'])
142+ parser.add_argument('action', choices=['insert','remove'])
143+ parser.add_argument('device', choices=['usb','firewire','sdio'])
144+ parser.add_argument('--timeout', type=int, default=10)
145 args = parser.parse_args()
146-
147- listener = StorageDeviceListener(args.device, args.action)
148- listener.loop.run()
149-
150- sys.exit(listener.error)
151+
152+ listener = StorageDeviceListener(args.action, args.device)
153+ return listener.check(args.timeout)
154+
155+
156+if __name__ == "__main__":
157+ sys.exit(main())

Subscribers

People subscribed via source and target branches