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
=== modified file 'abrek/hwprofile.py'
--- abrek/hwprofile.py 2010-09-18 04:25:23 +0000
+++ abrek/hwprofile.py 2010-09-27 14:22:38 +0000
@@ -95,8 +95,8 @@
95 for c in range(len(cpudevs)):95 for c in range(len(cpudevs)):
96 device = {}96 device = {}
97 device['device_type'] = 'device.cpu'97 device['device_type'] = 'device.cpu'
98 device['attributes'] = 'Processor #{0}'.format(c)98 device['description'] = 'Processor #{0}'.format(c)
99 device['desc'] = cpudevs[c]99 device['attributes'] = cpudevs[c]
100 devices.append(device)100 devices.append(device)
101 except IOError:101 except IOError:
102 print >> sys.stderr, "WARNING: Could not read cpu information"102 print >> sys.stderr, "WARNING: Could not read cpu information"
@@ -113,11 +113,11 @@
113 machine = os.uname()[-1]113 machine = os.uname()[-1]
114 if machine in ('i686', 'x86_64'):114 if machine in ('i686', 'x86_64'):
115 try:115 try:
116 name = read_file('/sys/class/dmi/id/board_name') or None116 description = read_file('/sys/class/dmi/id/board_name') or None
117 vendor = read_file('/sys/class/dmi/id/board_vendor') or None117 vendor = read_file('/sys/class/dmi/id/board_vendor') or None
118 version = read_file('/sys/class/dmi/id/board_version') or None118 version = read_file('/sys/class/dmi/id/board_version') or None
119 if name:119 if description:
120 device['attributes'] = name.strip()120 device['description'] = description.strip()
121 if vendor:121 if vendor:
122 desc['vendor'] = vendor.strip()122 desc['vendor'] = vendor.strip()
123 if version:123 if version:
@@ -140,7 +140,7 @@
140 return devices140 return devices
141 else:141 else:
142 return devices142 return devices
143 device['desc'] = desc143 device['attributes'] = desc
144 device['device_type'] = 'device.board'144 device['device_type'] = 'device.board'
145 devices.append(device)145 devices.append(device)
146 return devices146 return devices
@@ -166,11 +166,11 @@
166 kind = 'RAM'166 kind = 'RAM'
167 else:167 else:
168 kind = 'swap'168 kind = 'swap'
169 name = "{capacity}MiB of {kind}".format(169 description = "{capacity}MiB of {kind}".format(
170 capacity=capacity >> 20, kind=kind)170 capacity=capacity >> 20, kind=kind)
171 device = {}171 device = {}
172 device['attributes'] = name172 device['description'] = description
173 device['desc'] = {'capacity': capacity, 'kind': kind}173 device['attributes'] = {'capacity': capacity, 'kind': kind}
174 device['device_type'] = "device.mem"174 device['device_type'] = "device.mem"
175 devices.append(device)175 devices.append(device)
176 except IOError:176 except IOError:
@@ -183,18 +183,18 @@
183 """183 """
184 pattern = re.compile(184 pattern = re.compile(
185 "^Bus \d{3} Device \d{3}: ID (?P<vendor_id>[0-9a-f]{4}):"185 "^Bus \d{3} Device \d{3}: ID (?P<vendor_id>[0-9a-f]{4}):"
186 "(?P<product_id>[0-9a-f]{4}) (?P<name>.*)$")186 "(?P<product_id>[0-9a-f]{4}) (?P<description>.*)$")
187 devices = []187 devices = []
188 for line in commands.getoutput('lsusb').splitlines():188 for line in commands.getoutput('lsusb').splitlines():
189 match = pattern.match(line)189 match = pattern.match(line)
190 if match:190 if match:
191 vendor_id, product_id, name = match.groups()191 vendor_id, product_id, description = match.groups()
192 desc = {}192 attributes = {}
193 device = {}193 device = {}
194 desc['vendor_id'] = int(vendor_id, 16)194 attributes['vendor_id'] = int(vendor_id, 16)
195 desc['product_id'] = int(product_id, 16)195 attributes['product_id'] = int(product_id, 16)
196 device['desc'] = desc196 device['attributes'] = attributes
197 device['attributes'] = name197 device['description'] = description
198 device['device_type'] = 'device.usb'198 device['device_type'] = 'device.usb'
199 devices.append(device)199 devices.append(device)
200 return devices200 return devices
201201
=== modified file 'abrek/testdef.py'
--- abrek/testdef.py 2010-09-21 22:35:55 +0000
+++ abrek/testdef.py 2010-09-27 14:22:38 +0000
@@ -92,17 +92,18 @@
9292
93 def _savetestdata(self):93 def _savetestdata(self):
94 TIMEFORMAT = '%Y-%m-%dT%H:%M:%SZ'94 TIMEFORMAT = '%Y-%m-%dT%H:%M:%SZ'
95 testdata = {}95 testdata = [{}]
96 testdata['format'] = "Dashboard Bundle Format 1.0"
96 filename = os.path.join(self.resultsdir, 'testdata.json')97 filename = os.path.join(self.resultsdir, 'testdata.json')
97 testdata['test_id'] = self.testname98 testdata[0]['test_id'] = self.testname
98 testdata['analyzer_assigned_uuid'] = str(uuid1())99 testdata[0]['analyzer_assigned_uuid'] = str(uuid1())
99 testdata['time_check_performed'] = False100 testdata[0]['time_check_performed'] = False
100 testdata['analyzer_assigned_date'] = datetime.strftime(101 testdata[0]['analyzer_assigned_date'] = datetime.strftime(
101 self.runner.starttime,TIMEFORMAT)102 self.runner.starttime,TIMEFORMAT)
102 hw = hwprofile.get_hw_context()103 hw = hwprofile.get_hw_context()
103 testdata['hw_context'] = hw104 testdata[0]['hw_context'] = hw
104 sw = swprofile.get_sw_context()105 sw = swprofile.get_sw_context()
105 testdata['sw_context'] = sw106 testdata[0]['sw_context'] = sw
106 write_file(json.dumps(testdata), filename)107 write_file(json.dumps(testdata), filename)
107108
108 def run(self, quiet=False):109 def run(self, quiet=False):
109110
=== modified file 'tests/test_hwprofile.py'
--- tests/test_hwprofile.py 2010-09-18 04:26:46 +0000
+++ tests/test_hwprofile.py 2010-09-27 14:22:38 +0000
@@ -79,22 +79,54 @@
79 def test_get_cpu_devs(self):79 def test_get_cpu_devs(self):
80 fake_file('/proc/cpuinfo', ARM_CPUINFO_FILE)80 fake_file('/proc/cpuinfo', ARM_CPUINFO_FILE)
81 devs = abrek.hwprofile.get_cpu_devs()81 devs = abrek.hwprofile.get_cpu_devs()
82 processor = "ARMv7 Processor rev 3 (v7l)"82 cpuinfo = {
83 self.assertEqual(processor, devs[0]['desc']['Processor'])83 'attributes': {
84 'CPU implementer': '0x41',
85 'Features': 'swp half thumb fastmult vfp edsp neon vfpv3*',
86 'CPU architecture': '7',
87 'BogoMIPS': '483.16',
88 'Hardware': 'OMAP3 Beagle Board',
89 'CPU revision': '3',
90 'CPU part': '0xc08',
91 'Serial': '0000000000000000',
92 'Processor': 'ARMv7 Processor rev 3 (v7l)',
93 'CPU variant': '0x1',
94 'Revision': '0020'},
95 'description': 'Processor #0',
96 'device_type': 'device.cpu'}
97 self.assertEqual(cpuinfo, devs[0])
8498
85 def test_get_board_devs(self):99 def test_get_board_devs(self):
86 fake_file('/sys/class/dmi/id/board_name', FAKE_BOARDNAME_FILE)100 fake_file('/sys/class/dmi/id/board_name', FAKE_BOARDNAME_FILE)
87 devs = abrek.hwprofile.get_board_devs()101 devs = abrek.hwprofile.get_board_devs()
88 self.assertEqual(FAKE_BOARDNAME_FILE, devs[0]['attributes'])102 boardinfo = {
103 'attributes': {
104 'version': 'Not Available',
105 'vendor': 'LENOVO'},
106 'description': 'XXXXXXX',
107 'device_type': 'device.board'}
108 self.assertEqual(boardinfo, devs[0])
89109
90 def test_get_mem_devs(self):110 def test_get_mem_devs(self):
91 fake_file('/proc/meminfo', FAKE_MEMINFO_FILE)111 fake_file('/proc/meminfo', FAKE_MEMINFO_FILE)
92 devs = abrek.hwprofile.get_mem_devs()112 devs = abrek.hwprofile.get_mem_devs()
93 self.assertEqual(243937280, devs[0]['desc']['capacity'])113 meminfo = {
114 'attributes': {
115 'kind': 'RAM',
116 'capacity': 243937280},
117 'description': '232MiB of RAM',
118 'device_type': 'device.mem'}
119 self.assertEqual(meminfo, devs[0])
94120
95 def test_get_usb_devs(self):121 def test_get_usb_devs(self):
96 devs = abrek.hwprofile.get_usb_devs()122 devs = abrek.hwprofile.get_usb_devs()
97 self.assertEqual('device.usb', devs[0]['device_type'])123 usbinfo = {
124 'attributes': {
125 'vendor_id': 7531,
126 'product_id': 1},
127 'description': 'Linux Foundation 1.1 root hub',
128 'device_type': 'device.usb'}
129 self.assertEqual(usbinfo, devs[0])
98130
99131
100class MissingFiles(TestCaseWithFixtures):132class MissingFiles(TestCaseWithFixtures):

Subscribers

People subscribed via source and target branches