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
1=== added file 'checkbox-old/checkbox/parsers/lshwjson.py'
2--- checkbox-old/checkbox/parsers/lshwjson.py 1970-01-01 00:00:00 +0000
3+++ checkbox-old/checkbox/parsers/lshwjson.py 2013-07-03 16:16:26 +0000
4@@ -0,0 +1,23 @@
5+import sys
6+import json
7+
8+class LshwJsonParser:
9+
10+ def __init__(self, stream_or_string):
11+ self.stream_or_string = stream_or_string
12+
13+ def _parse_lshw(self, lshw, result):
14+ if 'children' in lshw.keys():
15+ for child in lshw['children']:
16+ self._parse_lshw(child, result)
17+ del lshw['children']
18+
19+ result.addHardware(lshw)
20+
21+ def run(self, result):
22+ try:
23+ lshw = json.loads(self.stream_or_string)
24+ except:
25+ print('not valid json')
26+
27+ self._parse_lshw(lshw, result)
28
29=== modified file 'checkbox-old/debian/changelog'
30--- checkbox-old/debian/changelog 2013-07-01 13:44:11 +0000
31+++ checkbox-old/debian/changelog 2013-07-03 16:16:26 +0000
32@@ -3,6 +3,9 @@
33 [ Brendan Donegan ]
34 * plugins/launchpad_report.py - Don't include attachments which have a status
35 of 'unsupported' (LP: #1196531)
36+ * checkbox/parsers/lshwjson.py, scripts/memory_compare - Create a parser for
37+ lshw and use this in the memory_compare script instead of dmidecode
38+ (LP: #1184661)
39
40 -- Brendan Donegan <brendan.donegan@canonical.com> Fri, 28 Jun 2013 15:02:58 +0100
41
42
43=== modified file 'checkbox-old/scripts/memory_compare'
44--- checkbox-old/scripts/memory_compare 2013-05-29 07:50:30 +0000
45+++ checkbox-old/scripts/memory_compare 2013-07-03 16:16:26 +0000
46@@ -3,29 +3,26 @@
47 import os
48 import sys
49
50-from checkbox.parsers.dmidecode import DmidecodeParser
51+from checkbox.parsers.lshwjson import LshwJsonParser
52 from checkbox.parsers.meminfo import MeminfoParser
53+from subprocess import check_output, PIPE
54
55 THRESHOLD = 10
56
57-class DmiResult:
58+class LshwJsonResult:
59
60 total_size = 0
61
62- def addDmiDevice(self, device):
63- form = getattr(device, "form", None)
64-
65- if form and "IMM" in form:
66- try:
67- self.total_size += int(getattr(device, "size", 0))
68- except ValueError:
69- pass
70+ def addHardware(self, hardware):
71+ if hardware['id'] == 'memory':
72+ self.total_size += int(hardware['size'])
73
74 def get_installed_memory_size():
75- dmi = DmidecodeParser(os.popen('dmidecode'))
76- result = DmiResult()
77-
78- dmi.run(result)
79+ lshw = LshwJsonParser(check_output(['lshw','-json'],
80+ universal_newlines=True,
81+ stderr=PIPE))
82+ result = LshwJsonResult()
83+ lshw.run(result)
84
85 return result.total_size
86
87@@ -57,21 +54,21 @@
88 except ZeroDivisionError:
89 print("Results:")
90 print("\t/proc/meminfo reports:\t%s kB" % visible_memory, file=sys.stderr)
91- print("\tdmi reports:\t%s kB" % installed_memory, file=sys.stderr)
92- print("\nFAIL: Either dmi or /proc/meminfo returned a memory size of 0 kB", file=sys.stderr)
93+ print("\tlshw reports:\t%s kB" % installed_memory, file=sys.stderr)
94+ print("\nFAIL: Either lshw or /proc/meminfo returned a memory size of 0 kB", file=sys.stderr)
95 return 1
96
97 if percentage <= THRESHOLD:
98 print("Results:")
99 print("\t/proc/meminfo reports:\t%s kB" % visible_memory)
100- print("\tdmi reports:\t%s kB" % installed_memory)
101- print("\nPASS: Meminfo reports %d bytes less than DMI, a difference of %.2f%%. This is less than the %d%% variance allowed." % (difference, percentage, THRESHOLD))
102+ print("\tlshw reports:\t%s kB" % installed_memory)
103+ print("\nPASS: Meminfo reports %d bytes less than lshw, a difference of %.2f%%. This is less than the %d%% variance allowed." % (difference, percentage, THRESHOLD))
104 return 0
105 else:
106 print("Results")
107 print("\t/proc/meminfo reports:\t%s kB" % visible_memory, file=sys.stderr)
108- print("\tdmi reports:\t%s kB" % installed_memory, file=sys.stderr)
109- 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)
110+ print("\tlshw reports:\t%s kB" % installed_memory, file=sys.stderr)
111+ 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)
112 return 1
113
114 if __name__ == "__main__":

Subscribers

People subscribed via source and target branches