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

Proposed by Marc Tardif
Status: Merged
Merged at revision: 1434
Proposed branch: lp:~cr3/checkbox/removable_resource
Merge into: lp:checkbox
Diff against target: 153 lines (+34/-39)
4 files modified
data/whitelists/default.whitelist (+1/-1)
jobs/disk.txt.in (+6/-6)
jobs/resource.txt.in (+2/-2)
scripts/block_device_resource (+25/-30)
To merge this branch: bzr merge lp:~cr3/checkbox/removable_resource
Reviewer Review Type Date Requested Status
Sylvain Pineau Approve
Daniel Manrique (community) Approve
Review via email: mp+110077@code.launchpad.net

Description of the change

Minor improvement suggestions.

To post a comment you must log in.
Revision history for this message
Daniel Manrique (roadmr) wrote :

Looks OK, I tested at least the resource script and it works as advertised. Merging, thanks!

review: Approve
Revision history for this message
Sylvain Pineau (sylvain-pineau) wrote :

OK for me as well, a bit late though.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'data/whitelists/default.whitelist'
2--- data/whitelists/default.whitelist 2012-06-13 14:13:01 +0000
3+++ data/whitelists/default.whitelist 2012-06-13 14:40:31 +0000
4@@ -12,7 +12,7 @@
5 sleep
6 display
7 optical_drive
8-block_devices
9+block_device
10 __audio__
11 audio/alsa_record_playback_external
12 audio/alsa_record_playback_internal
13
14=== modified file 'jobs/disk.txt.in'
15--- jobs/disk.txt.in 2012-06-13 12:33:46 +0000
16+++ jobs/disk.txt.in 2012-06-13 14:40:31 +0000
17@@ -13,7 +13,7 @@
18 name: disk/benchmark_`ls /sys$path/block`
19 requires:
20 device.path == "$path"
21- block_devices.`ls /sys$path/block` != 'removable'
22+ block_device.name == `ls /sys$path/block` and block_device.state != 'removable'
23 package.name == 'linux'
24 user: root
25 command: hdparm -tT /dev/`ls /sys$path/block | sed 's|!|/|'` | sed 's/:.*= */ = /' | grep -v "^$"
26@@ -30,7 +30,7 @@
27 name: disk/stats_`ls /sys$path/block`
28 requires:
29 device.path == "$path"
30- block_devices.`ls /sys$path/block` != 'removable'
31+ block_device.name == `ls /sys$path/block` and block_device.state != 'removable'
32 package.name == 'linux'
33 user: root
34 command: disk_stats_test `ls /sys$path/block | sed 's|!|/|'`
35@@ -50,7 +50,7 @@
36 name: disk/smart_`ls /sys$path/block`
37 requires:
38 device.path == "$path"
39- block_devices.`ls /sys$path/block` != 'removable'
40+ block_device.name == `ls /sys$path/block` and block_device.state != 'removable'
41 description:
42 This tests the SMART capabilities for $product (Note that this test will not work against hardware RAID)
43 user: root
44@@ -68,7 +68,7 @@
45 name: disk/max_diskspace_used_`ls /sys$path/block`
46 requires:
47 device.path == "$path"
48- block_devices.`ls /sys$path/block` != 'removable'
49+ block_device.name == `ls /sys$path/block` and block_device.state != 'removable'
50 description: Maximum disk space test for $product
51 user: root
52 command: max_diskspace_used `ls /sys$path/block | sed 's|!|/|'`
53@@ -85,7 +85,7 @@
54 name: disk/read_performance_`ls /sys$path/block`
55 requires:
56 device.path == "$path"
57- block_devices.`ls /sys$path/block` != 'removable'
58+ block_device.name == `ls /sys$path/block` and block_device.state != 'removable'
59 package.name == 'linux'
60 description: Disk performance test for $product
61 user: root
62@@ -104,7 +104,7 @@
63 user: root
64 requires:
65 device.path == "$path"
66- block_devices.`ls /sys$path/block` != 'removable'
67+ block_device.name == `ls /sys$path/block` and block_device.state != 'removable'
68 package.name == 'linux'
69 description: Disk I/O stress test for $product
70 command: storage_test `ls /sys$path/block | sed 's|!|/|'`
71
72=== modified file 'jobs/resource.txt.in'
73--- jobs/resource.txt.in 2012-06-11 07:24:31 +0000
74+++ jobs/resource.txt.in 2012-06-13 14:40:31 +0000
75@@ -64,9 +64,9 @@
76 command: for media in CD DVD; do wodim -prcap 2>/dev/null | grep -q -i "Does write $media" && echo "$media: writable" || echo "$media: readonly"; done
77 description: Create resource info for supported optical actions
78
79-name: block_devices
80+name: block_device
81 plugin: resource
82-command: removable_resource
83+command: block_device_resource
84 description: Create resource info for removable block devices
85
86 name: display
87
88=== renamed file 'scripts/removable_resource' => 'scripts/block_device_resource'
89--- scripts/removable_resource 2012-06-11 07:24:31 +0000
90+++ scripts/block_device_resource 2012-06-13 14:40:31 +0000
91@@ -5,37 +5,32 @@
92 from glob import glob
93
94
95-def device_removable(d):
96- """
97- Follow pmount policy to find removable devices
98- """
99+def device_state(name):
100+ """
101+ Follow pmount policy to determine whether a device is removable or internal.
102+ """
103+ with open('/sys/block/%s/device/block/%s/removable' % (name, name)) as f:
104+ if f.read(1) == '1':
105+ return 'removable'
106
107- removable_property = 'internal'
108 rootdir_pattern = re.compile('^.*?/devices')
109- with open('/sys/block/%s/device/block/%s/removable' % (d, d)) as f:
110- removable_property = f.read(1)
111-
112- if removable_property == '1':
113- return 'removable'
114- else:
115- removable_property = 'internal'
116-
117- path = rootdir_pattern.sub('', os.readlink('/sys/block/%s' % d))
118+ path = rootdir_pattern.sub('', os.readlink('/sys/block/%s' % name))
119 hotplug_buses = ("usb", "ieee1394", "mmc", "pcmcia", "firewire")
120 for bus in hotplug_buses:
121- if not os.path.exists('/sys/bus/%s' % bus):
122- continue
123- for device_bus in os.listdir('/sys/bus/%s/devices' % bus):
124- device_link = rootdir_pattern.sub('', os.readlink(
125- '/sys/bus/%s/devices/%s' % (bus, device_bus)))
126- if re.search(device_link, path):
127- return 'removable'
128-
129- return removable_property
130-
131-
132-devices = [re.sub('.*/(.*?)/device', '\g<1>', d)
133- for d in glob('/sys/block/*/device')]
134-
135-for d in devices:
136- print('%s: %s' % (d, device_removable(d)))
137+ if os.path.exists('/sys/bus/%s' % bus):
138+ for device_bus in os.listdir('/sys/bus/%s/devices' % bus):
139+ device_link = rootdir_pattern.sub('', os.readlink(
140+ '/sys/bus/%s/devices/%s' % (bus, device_bus)))
141+ if re.search(device_link, path):
142+ return 'removable'
143+
144+ return 'internal'
145+
146+
147+for path in glob('/sys/block/*/device'):
148+ name = re.sub('.*/(.*?)/device', '\g<1>', path)
149+ state = device_state(name)
150+ print("""\
151+name: %s
152+state: %s
153+""" % (name, state))

Subscribers

People subscribed via source and target branches