Merge lp:~pwlars/lava-test/json-compat-fix into lp:lava-test/0.0

Proposed by Paul Larson
Status: Merged
Merged at revision: 35
Proposed branch: lp:~pwlars/lava-test/json-compat-fix
Merge into: lp:lava-test/0.0
Diff against target: 173 lines (+61/-28)
3 files modified
abrek/hwprofile.py (+16/-16)
abrek/testdef.py (+8/-7)
tests/test_hwprofile.py (+37/-5)
To merge this branch: bzr merge lp:~pwlars/lava-test/json-compat-fix
Reviewer Review Type Date Requested Status
James Westby (community) Approve
Review via email: mp+36583@code.launchpad.net

Description of the change

These are needed in preparation for being able to submit results to launch-control. Launch-control currently fails silently and accepts invalid results, but if you look into it further you can see that it doesn't properly handle them unless these fixes are in place.

Thanks,
Paul Larson

To post a comment you must log in.
Revision history for this message
James Westby (james-w) wrote :

Hi,

I find these sorts of things a little confusing:

28 - device['desc'] = desc
29 + device['attributes'] = desc

Can we have the local variables not share the name of a key they are
not for?

There are also more code changes than test changes, is the test
coverage good enough in this area?

Thanks,

James

review: Needs Information
Revision history for this message
Zygmunt Krynicki (zyga) wrote :

These are needed in preparation for being able to submit results to launch-control. Launch-control currently fails silently and accepts invalid results,

Yes, you can upload anything as validation and processing is going to be asynchronous anyway. Note that you _can_ check wat went wrong by looking at BundleDeserializationError model right in the web UI.

 but if you look into it further you can see that it doesn't properly handle them unless these fixes are in place.

It can handle correct documents, they just need to adhere to schema.

Best regards.
Zygmunt Krynicki

lp:~pwlars/lava-test/json-compat-fix updated
36. By Paul Larson

match variable names to field names better in hwprofile

37. By Paul Larson

Make hw_profile tests more complete

Revision history for this message
Paul Larson (pwlars) wrote :

> 28 - device['desc'] = desc
> 29 + device['attributes'] = desc
> Can we have the local variables not share the name of a key they are
> not for?
Done

> There are also more code changes than test changes, is the test
> coverage good enough in this area?
Changed this a bit. The tests look at the whole dict that should result from converting the cpuinfo, meminfo, etc. This doesn't add more tests, but makes the existing tests more complete.

Revision history for this message
James Westby (james-w) wrote :

Hi,

Much better, thanks.

34 - device['desc'] = desc
35 + device['attributes'] = desc

I don't know how tricky it would be to clean that one up as well, but
if you can that would be great.

Thanks,

James

review: Approve
Revision history for this message
Paul Larson (pwlars) wrote :

On Mon, 2010-09-27 at 15:22 +0000, James Westby wrote:
> 34 - device['desc'] = desc
> 35 + device['attributes'] = desc
Bah, missed that one. Thanks!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'abrek/hwprofile.py'
2--- abrek/hwprofile.py 2010-09-18 04:25:23 +0000
3+++ abrek/hwprofile.py 2010-09-27 14:22:38 +0000
4@@ -95,8 +95,8 @@
5 for c in range(len(cpudevs)):
6 device = {}
7 device['device_type'] = 'device.cpu'
8- device['attributes'] = 'Processor #{0}'.format(c)
9- device['desc'] = cpudevs[c]
10+ device['description'] = 'Processor #{0}'.format(c)
11+ device['attributes'] = cpudevs[c]
12 devices.append(device)
13 except IOError:
14 print >> sys.stderr, "WARNING: Could not read cpu information"
15@@ -113,11 +113,11 @@
16 machine = os.uname()[-1]
17 if machine in ('i686', 'x86_64'):
18 try:
19- name = read_file('/sys/class/dmi/id/board_name') or None
20+ description = read_file('/sys/class/dmi/id/board_name') or None
21 vendor = read_file('/sys/class/dmi/id/board_vendor') or None
22 version = read_file('/sys/class/dmi/id/board_version') or None
23- if name:
24- device['attributes'] = name.strip()
25+ if description:
26+ device['description'] = description.strip()
27 if vendor:
28 desc['vendor'] = vendor.strip()
29 if version:
30@@ -140,7 +140,7 @@
31 return devices
32 else:
33 return devices
34- device['desc'] = desc
35+ device['attributes'] = desc
36 device['device_type'] = 'device.board'
37 devices.append(device)
38 return devices
39@@ -166,11 +166,11 @@
40 kind = 'RAM'
41 else:
42 kind = 'swap'
43- name = "{capacity}MiB of {kind}".format(
44+ description = "{capacity}MiB of {kind}".format(
45 capacity=capacity >> 20, kind=kind)
46 device = {}
47- device['attributes'] = name
48- device['desc'] = {'capacity': capacity, 'kind': kind}
49+ device['description'] = description
50+ device['attributes'] = {'capacity': capacity, 'kind': kind}
51 device['device_type'] = "device.mem"
52 devices.append(device)
53 except IOError:
54@@ -183,18 +183,18 @@
55 """
56 pattern = re.compile(
57 "^Bus \d{3} Device \d{3}: ID (?P<vendor_id>[0-9a-f]{4}):"
58- "(?P<product_id>[0-9a-f]{4}) (?P<name>.*)$")
59+ "(?P<product_id>[0-9a-f]{4}) (?P<description>.*)$")
60 devices = []
61 for line in commands.getoutput('lsusb').splitlines():
62 match = pattern.match(line)
63 if match:
64- vendor_id, product_id, name = match.groups()
65- desc = {}
66+ vendor_id, product_id, description = match.groups()
67+ attributes = {}
68 device = {}
69- desc['vendor_id'] = int(vendor_id, 16)
70- desc['product_id'] = int(product_id, 16)
71- device['desc'] = desc
72- device['attributes'] = name
73+ attributes['vendor_id'] = int(vendor_id, 16)
74+ attributes['product_id'] = int(product_id, 16)
75+ device['attributes'] = attributes
76+ device['description'] = description
77 device['device_type'] = 'device.usb'
78 devices.append(device)
79 return devices
80
81=== modified file 'abrek/testdef.py'
82--- abrek/testdef.py 2010-09-21 22:35:55 +0000
83+++ abrek/testdef.py 2010-09-27 14:22:38 +0000
84@@ -92,17 +92,18 @@
85
86 def _savetestdata(self):
87 TIMEFORMAT = '%Y-%m-%dT%H:%M:%SZ'
88- testdata = {}
89+ testdata = [{}]
90+ testdata['format'] = "Dashboard Bundle Format 1.0"
91 filename = os.path.join(self.resultsdir, 'testdata.json')
92- testdata['test_id'] = self.testname
93- testdata['analyzer_assigned_uuid'] = str(uuid1())
94- testdata['time_check_performed'] = False
95- testdata['analyzer_assigned_date'] = datetime.strftime(
96+ testdata[0]['test_id'] = self.testname
97+ testdata[0]['analyzer_assigned_uuid'] = str(uuid1())
98+ testdata[0]['time_check_performed'] = False
99+ testdata[0]['analyzer_assigned_date'] = datetime.strftime(
100 self.runner.starttime,TIMEFORMAT)
101 hw = hwprofile.get_hw_context()
102- testdata['hw_context'] = hw
103+ testdata[0]['hw_context'] = hw
104 sw = swprofile.get_sw_context()
105- testdata['sw_context'] = sw
106+ testdata[0]['sw_context'] = sw
107 write_file(json.dumps(testdata), filename)
108
109 def run(self, quiet=False):
110
111=== modified file 'tests/test_hwprofile.py'
112--- tests/test_hwprofile.py 2010-09-18 04:26:46 +0000
113+++ tests/test_hwprofile.py 2010-09-27 14:22:38 +0000
114@@ -79,22 +79,54 @@
115 def test_get_cpu_devs(self):
116 fake_file('/proc/cpuinfo', ARM_CPUINFO_FILE)
117 devs = abrek.hwprofile.get_cpu_devs()
118- processor = "ARMv7 Processor rev 3 (v7l)"
119- self.assertEqual(processor, devs[0]['desc']['Processor'])
120+ cpuinfo = {
121+ 'attributes': {
122+ 'CPU implementer': '0x41',
123+ 'Features': 'swp half thumb fastmult vfp edsp neon vfpv3*',
124+ 'CPU architecture': '7',
125+ 'BogoMIPS': '483.16',
126+ 'Hardware': 'OMAP3 Beagle Board',
127+ 'CPU revision': '3',
128+ 'CPU part': '0xc08',
129+ 'Serial': '0000000000000000',
130+ 'Processor': 'ARMv7 Processor rev 3 (v7l)',
131+ 'CPU variant': '0x1',
132+ 'Revision': '0020'},
133+ 'description': 'Processor #0',
134+ 'device_type': 'device.cpu'}
135+ self.assertEqual(cpuinfo, devs[0])
136
137 def test_get_board_devs(self):
138 fake_file('/sys/class/dmi/id/board_name', FAKE_BOARDNAME_FILE)
139 devs = abrek.hwprofile.get_board_devs()
140- self.assertEqual(FAKE_BOARDNAME_FILE, devs[0]['attributes'])
141+ boardinfo = {
142+ 'attributes': {
143+ 'version': 'Not Available',
144+ 'vendor': 'LENOVO'},
145+ 'description': 'XXXXXXX',
146+ 'device_type': 'device.board'}
147+ self.assertEqual(boardinfo, devs[0])
148
149 def test_get_mem_devs(self):
150 fake_file('/proc/meminfo', FAKE_MEMINFO_FILE)
151 devs = abrek.hwprofile.get_mem_devs()
152- self.assertEqual(243937280, devs[0]['desc']['capacity'])
153+ meminfo = {
154+ 'attributes': {
155+ 'kind': 'RAM',
156+ 'capacity': 243937280},
157+ 'description': '232MiB of RAM',
158+ 'device_type': 'device.mem'}
159+ self.assertEqual(meminfo, devs[0])
160
161 def test_get_usb_devs(self):
162 devs = abrek.hwprofile.get_usb_devs()
163- self.assertEqual('device.usb', devs[0]['device_type'])
164+ usbinfo = {
165+ 'attributes': {
166+ 'vendor_id': 7531,
167+ 'product_id': 1},
168+ 'description': 'Linux Foundation 1.1 root hub',
169+ 'device_type': 'device.usb'}
170+ self.assertEqual(usbinfo, devs[0])
171
172
173 class MissingFiles(TestCaseWithFixtures):

Subscribers

People subscribed via source and target branches