Merge lp:~brendan-donegan/checkbox/bug1184661 into lp:checkbox

Proposed by Brendan Donegan
Status: Merged
Approved by: Jeff Lane 
Approved revision: 2227
Merged at revision: 2224
Proposed branch: lp:~brendan-donegan/checkbox/bug1184661
Merge into: lp:checkbox
Diff against target: 114 lines (+43/-20)
3 files modified
checkbox-old/checkbox/parsers/lshwjson.py (+23/-0)
checkbox-old/debian/changelog (+3/-0)
checkbox-old/scripts/memory_compare (+17/-20)
To merge this branch: bzr merge lp:~brendan-donegan/checkbox/bug1184661
Reviewer Review Type Date Requested Status
Jeff Lane  Approve
Review via email: mp+172790@code.launchpad.net

Description of the change

dmidecode doesn't exist on ARM platforms so memory_compare was failing to get the size of the installed RAM on these platforms. lshw was identified as a suitable replacement so this branch includes a parser for that tools JSON formatted output (lshw -json) and uses it in the memory_compare script to get the installed memory size if dmidecode is unable to.

To post a comment you must log in.
Revision history for this message
Brendan Donegan (brendan-donegan) wrote :

Putting this on hold since I want to confer over whether to just scrap the DMI parser altogether and use the lshw one on both x86 and ARM - my own local tests show they return the same figure.

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

> Putting this on hold since I want to confer over whether to just scrap the DMI
> parser altogether and use the lshw one on both x86 and ARM - my own local
> tests show they return the same figure.

Well, I don't mean to scrap the DMI parser altogether - just its use in the memory_compare script.

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

I tested this on the Calxeda node and it seems to work well

Revision history for this message
Jeff Lane  (bladernr) wrote :

I also tested on saucy 64bit, raring 64bit and lucid 32bit and it works fine on all three, produces exactly the same physical memory numbers that dmidecode did.

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

I removed the Dmi code and changed all references to dmi to lshw instead. Now we have a script that works across all platforms!

Revision history for this message
Jeff Lane  (bladernr) wrote :

Yep, tested and looked at, and it's cool. Onward with the decimation of DMI!!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added file 'checkbox-old/checkbox/parsers/lshwjson.py'
--- checkbox-old/checkbox/parsers/lshwjson.py 1970-01-01 00:00:00 +0000
+++ checkbox-old/checkbox/parsers/lshwjson.py 2013-07-03 16:16:26 +0000
@@ -0,0 +1,23 @@
1import sys
2import json
3
4class LshwJsonParser:
5
6 def __init__(self, stream_or_string):
7 self.stream_or_string = stream_or_string
8
9 def _parse_lshw(self, lshw, result):
10 if 'children' in lshw.keys():
11 for child in lshw['children']:
12 self._parse_lshw(child, result)
13 del lshw['children']
14
15 result.addHardware(lshw)
16
17 def run(self, result):
18 try:
19 lshw = json.loads(self.stream_or_string)
20 except:
21 print('not valid json')
22
23 self._parse_lshw(lshw, result)
024
=== modified file 'checkbox-old/debian/changelog'
--- checkbox-old/debian/changelog 2013-07-01 13:44:11 +0000
+++ checkbox-old/debian/changelog 2013-07-03 16:16:26 +0000
@@ -3,6 +3,9 @@
3 [ Brendan Donegan ]3 [ Brendan Donegan ]
4 * plugins/launchpad_report.py - Don't include attachments which have a status4 * plugins/launchpad_report.py - Don't include attachments which have a status
5 of 'unsupported' (LP: #1196531)5 of 'unsupported' (LP: #1196531)
6 * checkbox/parsers/lshwjson.py, scripts/memory_compare - Create a parser for
7 lshw and use this in the memory_compare script instead of dmidecode
8 (LP: #1184661)
69
7 -- Brendan Donegan <brendan.donegan@canonical.com> Fri, 28 Jun 2013 15:02:58 +010010 -- Brendan Donegan <brendan.donegan@canonical.com> Fri, 28 Jun 2013 15:02:58 +0100
811
912
=== modified file 'checkbox-old/scripts/memory_compare'
--- checkbox-old/scripts/memory_compare 2013-05-29 07:50:30 +0000
+++ checkbox-old/scripts/memory_compare 2013-07-03 16:16:26 +0000
@@ -3,29 +3,26 @@
3import os3import os
4import sys4import sys
55
6from checkbox.parsers.dmidecode import DmidecodeParser6from checkbox.parsers.lshwjson import LshwJsonParser
7from checkbox.parsers.meminfo import MeminfoParser7from checkbox.parsers.meminfo import MeminfoParser
8from subprocess import check_output, PIPE
89
9THRESHOLD = 1010THRESHOLD = 10
1011
11class DmiResult:12class LshwJsonResult:
1213
13 total_size = 014 total_size = 0
1415
15 def addDmiDevice(self, device):16 def addHardware(self, hardware):
16 form = getattr(device, "form", None)17 if hardware['id'] == 'memory':
1718 self.total_size += int(hardware['size'])
18 if form and "IMM" in form:
19 try:
20 self.total_size += int(getattr(device, "size", 0))
21 except ValueError:
22 pass
2319
24def get_installed_memory_size():20def get_installed_memory_size():
25 dmi = DmidecodeParser(os.popen('dmidecode'))21 lshw = LshwJsonParser(check_output(['lshw','-json'],
26 result = DmiResult()22 universal_newlines=True,
2723 stderr=PIPE))
28 dmi.run(result)24 result = LshwJsonResult()
25 lshw.run(result)
2926
30 return result.total_size27 return result.total_size
3128
@@ -57,21 +54,21 @@
57 except ZeroDivisionError:54 except ZeroDivisionError:
58 print("Results:")55 print("Results:")
59 print("\t/proc/meminfo reports:\t%s kB" % visible_memory, file=sys.stderr)56 print("\t/proc/meminfo reports:\t%s kB" % visible_memory, file=sys.stderr)
60 print("\tdmi reports:\t%s kB" % installed_memory, file=sys.stderr)57 print("\tlshw reports:\t%s kB" % installed_memory, file=sys.stderr)
61 print("\nFAIL: Either dmi or /proc/meminfo returned a memory size of 0 kB", file=sys.stderr)58 print("\nFAIL: Either lshw or /proc/meminfo returned a memory size of 0 kB", file=sys.stderr)
62 return 159 return 1
63 60
64 if percentage <= THRESHOLD:61 if percentage <= THRESHOLD:
65 print("Results:")62 print("Results:")
66 print("\t/proc/meminfo reports:\t%s kB" % visible_memory)63 print("\t/proc/meminfo reports:\t%s kB" % visible_memory)
67 print("\tdmi reports:\t%s kB" % installed_memory)64 print("\tlshw reports:\t%s kB" % installed_memory)
68 print("\nPASS: Meminfo reports %d bytes less than DMI, a difference of %.2f%%. This is less than the %d%% variance allowed." % (difference, percentage, THRESHOLD))65 print("\nPASS: Meminfo reports %d bytes less than lshw, a difference of %.2f%%. This is less than the %d%% variance allowed." % (difference, percentage, THRESHOLD))
69 return 066 return 0
70 else:67 else:
71 print("Results")68 print("Results")
72 print("\t/proc/meminfo reports:\t%s kB" % visible_memory, file=sys.stderr)69 print("\t/proc/meminfo reports:\t%s kB" % visible_memory, file=sys.stderr)
73 print("\tdmi reports:\t%s kB" % installed_memory, file=sys.stderr)70 print("\tlshw reports:\t%s kB" % installed_memory, file=sys.stderr)
74 print("\nFAIL: Meminfo reports %d bytes less than DMI, a difference of %.2f%%. Only a variance of %d%% in reported memory is allowed." % (difference, percentage, THRESHOLD), file=sys.stderr)71 print("\nFAIL: Meminfo reports %d bytes less than lshw, a difference of %.2f%%. Only a variance of %d%% in reported memory is allowed." % (difference, percentage, THRESHOLD), file=sys.stderr)
75 return 172 return 1
7673
77if __name__ == "__main__":74if __name__ == "__main__":

Subscribers

People subscribed via source and target branches