Merge lp:~adeuring/launchpad/test-hwsubm into lp:launchpad

Proposed by Abel Deuring
Status: Merged
Approved by: Abel Deuring
Approved revision: no longer in the source branch.
Merged at revision: 13822
Proposed branch: lp:~adeuring/launchpad/test-hwsubm
Merge into: lp:launchpad
Diff against target: 239 lines (+124/-14)
5 files modified
lib/canonical/launchpad/scripts/hardware-1_0.rng (+11/-5)
lib/canonical/launchpad/scripts/tests/test_hwdb_submission_parser.py (+38/-0)
lib/canonical/launchpad/scripts/tests/test_hwdb_submission_processing.py (+37/-0)
lib/lp/hardwaredb/scripts/hwdbsubmissions.py (+29/-3)
lib/lp/hardwaredb/tests/test_hwdb_submission_validation.py (+9/-6)
To merge this branch: bzr merge lp:~adeuring/launchpad/test-hwsubm
Reviewer Review Type Date Requested Status
Francis J. Lacoste (community) Approve
Review via email: mp+73294@code.launchpad.net

Commit message

[r=flacoste][bug=835103] allow to process HWDB submissions from the checkbox version in Lucid, Maverick, Natty.

Description of the change

This branch allows to parse HWDB reports that come from the Maverick and Natty versions of checkbox. These versions do not provide information we need to store data about SCSI devices in the hardwrae database: the reports have no <sysfs-qttributes> node. This node is supposed to be the source for the vendor annd model name of SCSI devcies.

We could still get the vendor/model name for block devices, by looking into sub-nodes of the "main" udev node for these devcies, but:

- we urgently need a fix
- Data about SCSI block devcies is probably the least interesting data; more intersting are other devices, like tape robots or scanners: support tends to be more fragile that support for disks or CD drives.

This branch changes the RelaxNG schema so that raw submissions without a <sysfs-attributes> node pass; it ensures that the further porcessing of the data works.

The main change is in is_scsi_device (@@ -2731,6 +2747,12 @@): This property is used by the proeprty scsi_vendor and scsi_model to check if the vendor/model name exist; if the latter properties are None, the "potential scsi device" is not considered to be a SCSI devcie, an no data about is stored.

("Potential SCSI devices": Many non-SCSI devices, like ATA disks, USB disks or USB card readers, use the SCSI command set to communicate with the host computer. These devices are treated like real SCSI devcies, but they don't have the sysfs attributes vendor/model; this is already used by the HWDB submission processing script to decide, if data about a given "potentail SCSI device" should be stored.

To post a comment you must log in.
Revision history for this message
Francis J. Lacoste (flacoste) wrote :

<flacoste> adeuring: just FYI, Lucid is also affected, we have very few valid Lucid submissions, and I guess they date from before the problematic checkbox changes
<adeuring> flacoste: right; I'll check a few lucid reports too
<flacoste> adeuring: do we have hwdb integration tests? If we do, is it worth adding one for a problematic report?
<adeuring> flacoste: right, I am aware that such a test is missing -- the main point is: I am too tired to write one today...
<flacoste> adeuring: but do we have such tests already?
<adeuring> flacoste: only one or two: for correct data and for "trivially wrong data", IIRC
<flacoste> adeuring: ok
<flacoste> adeuring: r=me with the note that Lucid and later are affected, and with a reference to the bug report

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/canonical/launchpad/scripts/hardware-1_0.rng'
2--- lib/canonical/launchpad/scripts/hardware-1_0.rng 2009-09-14 09:16:45 +0000
3+++ lib/canonical/launchpad/scripts/hardware-1_0.rng 2011-08-29 20:46:29 +0000
4@@ -148,11 +148,17 @@
5 <element name="dmi">
6 <text/>
7 </element>
8- <element name="sysfs-attributes">
9- <zeroOrMore>
10- <text/>
11- </zeroOrMore>
12- </element>
13+ <optional>
14+ <!-- Unfortunately, the checkbox version in
15+ Maverick and Natty do not provide sysfs
16+ data.
17+ -->
18+ <element name="sysfs-attributes">
19+ <zeroOrMore>
20+ <text/>
21+ </zeroOrMore>
22+ </element>
23+ </optional>
24 </interleave>
25 </group>
26 </choice>
27
28=== modified file 'lib/canonical/launchpad/scripts/tests/test_hwdb_submission_parser.py'
29--- lib/canonical/launchpad/scripts/tests/test_hwdb_submission_parser.py 2011-08-12 11:37:08 +0000
30+++ lib/canonical/launchpad/scripts/tests/test_hwdb_submission_parser.py 2011-08-29 20:46:29 +0000
31@@ -986,6 +986,33 @@
32 result,
33 'Invalid parsing result for <hardware>')
34
35+ def testHardware_no_sysfs_node(self):
36+ """If teh <sysfs-attributes> node is missing, parseHardware()
37+ returns a dicitionary where the entry for this node is None.
38+ """
39+ parser = self.MockSubmissionParserParseHardwareTest(self.log)
40+
41+ node = etree.fromstring("""
42+ <hardware>
43+ <hal/>
44+ <processors/>
45+ <aliases/>
46+ <udev/>
47+ <dmi/>
48+ </hardware>
49+ """)
50+ result = parser._parseHardware(node)
51+ self.assertEqual({
52+ 'hal': 'parsed HAL data',
53+ 'processors': 'parsed processor data',
54+ 'aliases': 'parsed alias data',
55+ 'udev': 'parsed udev data',
56+ 'dmi': 'parsed DMI data',
57+ 'sysfs-attributes': None,
58+ },
59+ result,
60+ 'Invalid parsing result for <hardware>')
61+
62 def test_parseHardware_sub_parsers_fail(self):
63 """Test of SubmissionParser._parseHardware().
64
65@@ -2162,6 +2189,17 @@
66 parser.checkUdevScsiProperties(
67 [self.udev_root_device, self.udev_scsi_device], sysfs_data))
68
69+ def testCheckUdevScsiProperties_data_is_none(self):
70+ """Test of SubmissionParser.checkUdevScsiProperties().
71+
72+ checkUdevScsiProperties() even if no sysfs properties are
73+ available.
74+ """
75+ parser = SubmissionParser()
76+ self.assertTrue(
77+ parser.checkUdevScsiProperties(
78+ [self.udev_root_device, self.udev_scsi_device], None))
79+
80 def testCheckUdevScsiProperties_missing_devtype(self):
81 """Test of SubmissionParser.checkUdevScsiProperties().
82
83
84=== modified file 'lib/canonical/launchpad/scripts/tests/test_hwdb_submission_processing.py'
85--- lib/canonical/launchpad/scripts/tests/test_hwdb_submission_processing.py 2011-08-13 04:07:10 +0000
86+++ lib/canonical/launchpad/scripts/tests/test_hwdb_submission_processing.py 2011-08-29 20:46:29 +0000
87@@ -349,6 +349,29 @@
88 self.assertIs(
89 None, parser.devices[pci_ethernet_controller_path].sysfs)
90
91+ def test_buildUdevDeviceList_no_sysfs_data(self):
92+ """Sysfs data is not required (maverick and natty submissions)."""
93+ root_device_path = '/devices/LNXSYSTM:00'
94+ pci_pci_bridge_path = '/devices/pci0000:00/0000:00:1c.0'
95+ pci_ethernet_controller_path = (
96+ '/devices/pci0000:00/0000:00:1c.0/0000:02:00.0')
97+
98+ udev_paths = (
99+ root_device_path, pci_pci_bridge_path,
100+ pci_ethernet_controller_path)
101+
102+ sysfs_data = None
103+
104+ parsed_data = self.makeUdevDeviceParsedData(udev_paths, sysfs_data)
105+ parser = SubmissionParser()
106+ parser.buildUdevDeviceList(parsed_data)
107+
108+ self.assertIs(
109+ None, parser.devices[pci_pci_bridge_path].sysfs)
110+
111+ self.assertIs(
112+ None, parser.devices[pci_ethernet_controller_path].sysfs)
113+
114 def test_buildUdevDeviceList_invalid_device_path(self):
115 """Test the creation of UdevDevice instances for a submission.
116
117@@ -3875,6 +3898,20 @@
118 device = UdevDevice(None, self.root_device)
119 self.assertFalse(device.is_scsi_device)
120
121+ def test_is_scsi_device__no_sysfs_data(self):
122+ """Test of UdevDevice.is_scsi_device.
123+
124+ If there is no sysfs data for a real SCSI device, is it not
125+ considered as a real SCSI device.
126+
127+ Reason: Without sysfs data, we don't know the vendor and
128+ model name, making it impossible to store data about the
129+ device in the database.
130+ """
131+ device = UdevDevice(
132+ None, self.scsi_scanner_device_data, None)
133+ self.assertFalse(device.is_scsi_device)
134+
135 def test_scsi_vendor(self):
136 """Test of UdevDevice.scsi_vendor."""
137 device = UdevDevice(
138
139=== modified file 'lib/lp/hardwaredb/scripts/hwdbsubmissions.py'
140--- lib/lp/hardwaredb/scripts/hwdbsubmissions.py 2011-05-27 19:53:20 +0000
141+++ lib/lp/hardwaredb/scripts/hwdbsubmissions.py 2011-08-29 20:46:29 +0000
142@@ -680,7 +680,13 @@
143 where the values are the parsing results of _parseHAL,
144 _parseProcessors, _parseAliases.
145 """
146- hardware_data = {}
147+ # Submissions from checkbox for Lucid, Maverick and Natty
148+ # unfortunately do not contain a <sysfs-attributes> node.
149+ # A default value here allows us to mark these submissions.
150+ # See also bug 835103.
151+ hardware_data = {
152+ 'sysfs-attributes': None,
153+ }
154 for node in hardware_node.getchildren():
155 parser = self._parse_hardware_section[node.tag]
156 result = parser(node)
157@@ -1328,6 +1334,13 @@
158 should have a corresponding sysfs node, and this node should
159 define the attributes 'vendor', 'model', 'type'.
160 """
161+ # Broken submissions from Lucid, Maverick and Natty. We'll have
162+ # to deal with incomplete data for SCSI devices in this case if
163+ # we don't want to drop the entire submission, so just pretend
164+ # that things are fine.
165+ # See also bug 835103.
166+ if sysfs_data is None:
167+ return True
168 for device in udev_data:
169 subsystem = device['E'].get('SUBSYSTEM')
170 if subsystem != 'scsi':
171@@ -1456,13 +1469,19 @@
172 dmi_data = parsed_data['hardware']['dmi']
173 for udev_data in parsed_data['hardware']['udev']:
174 device_path = udev_data['P']
175+ if sysfs_data is not None:
176+ sysfs_data_for_device = sysfs_data.get(device_path)
177+ else:
178+ # broken Lucid, Maverick and Natty submissions.
179+ # See also bug 835103.
180+ sysfs_data_for_device = None
181 if device_path == UDEV_ROOT_PATH:
182 device = UdevDevice(
183- self, udev_data, sysfs_data=sysfs_data.get(device_path),
184+ self, udev_data, sysfs_data=sysfs_data_for_device,
185 dmi_data=dmi_data)
186 else:
187 device = UdevDevice(
188- self, udev_data, sysfs_data=sysfs_data.get(device_path))
189+ self, udev_data, sysfs_data=sysfs_data_for_device)
190 self.devices[device_path] = device
191
192 # The parent-child relations are derived from the path names of
193@@ -2731,6 +2750,13 @@
194 # udev sets the property SUBSYSTEM to "scsi" for a number of
195 # different nodes: SCSI hosts, SCSI targets and SCSI devices.
196 # They are distiguished by the property DEVTYPE.
197+
198+ # Hack for broken submissions from Lucid, Maverick and Natty:
199+ # If we don't have sysfs information, pretend that no SCSI
200+ # related node corresponds to a real device.
201+ # See also bug 835103.
202+ if self.sysfs is None:
203+ return False
204 properties = self.udev['E']
205 return (properties.get('SUBSYSTEM') == 'scsi' and
206 properties.get('DEVTYPE') == 'scsi_device')
207
208=== modified file 'lib/lp/hardwaredb/tests/test_hwdb_submission_validation.py'
209--- lib/lp/hardwaredb/tests/test_hwdb_submission_validation.py 2011-08-12 11:37:08 +0000
210+++ lib/lp/hardwaredb/tests/test_hwdb_submission_validation.py 2011-08-29 20:46:29 +0000
211@@ -697,8 +697,8 @@
212 is required, and either <hal> or all three tags <udev>, <dmi>,
213 <sysfs-attributes> must be present.
214 """
215- # Omitting any of the three tags <udev>, <dmi>, <sysfs-attributes>
216- # makes the data invalid.
217+ # Omitting one of the tags <udev>, <dmi> makes the data invalid.
218+ # Omitting <sysfs-attributes> is tolerated.
219 all_tags = ['udev', 'dmi', 'sysfs-attributes']
220 for index, missing_tag in enumerate(all_tags):
221 test_tags = all_tags[:]
222@@ -712,10 +712,13 @@
223 from_text='<hal',
224 to_text='</hal>')
225 result, submission_id = self.runValidator(sample_data)
226- self.assertErrorMessage(
227- submission_id, result,
228- 'Expecting an element %s, got nothing' % missing_tag,
229- 'missing tag <%s> in <hardware>' % missing_tag)
230+ if missing_tag != 'sysfs-attributes':
231+ self.assertErrorMessage(
232+ submission_id, result,
233+ 'Expecting an element %s, got nothing' % missing_tag,
234+ 'missing tag <%s> in <hardware>' % missing_tag)
235+ else:
236+ self.assertFalse(result is None)
237
238 def testHardwareSubTagHalMixedWithUdev(self):
239 """Mixing <hal> with <udev>, <dmi>, <sysfs-attributes> is impossible.