Merge lp://staging/~brendan-donegan/checkbox/bug960087_memory_compare_ram_devices into lp://staging/checkbox

Proposed by Brendan Donegan
Status: Merged
Merged at revision: 1482
Proposed branch: lp://staging/~brendan-donegan/checkbox/bug960087_memory_compare_ram_devices
Merge into: lp://staging/checkbox
Diff against target: 211 lines (+103/-32) (has conflicts)
5 files modified
checkbox/lib/dmi.py (+16/-0)
checkbox/parsers/dmidecode.py (+4/-1)
debian/changelog (+9/-0)
scripts/dmi_resource (+4/-4)
scripts/memory_compare (+70/-27)
Text conflict in debian/changelog
To merge this branch: bzr merge lp://staging/~brendan-donegan/checkbox/bug960087_memory_compare_ram_devices
Reviewer Review Type Date Requested Status
Marc Tardif (community) Approve
Brendan Donegan (community) Needs Resubmitting
Review via email: mp+112987@code.staging.launchpad.net

Description of the change

I reimplemented and restructured the memory_compare script to use Python3 and also to store the dmi and meminfo output into dictionaries, which will allow for more flexibility later on if other fields need to be used to calculate the correct figures. This merge will also fix the bug where ROM devices for example are being included in the calculations, whereas we're only interested in RAM.

To post a comment you must log in.
1478. By Brendan Donegan

Merged from trunk

Revision history for this message
Marc Tardif (cr3) wrote :

Since the script is now written in Python, it should use the parsers in Checkbox to avoid duplicating that potentially error prone logic. Please modify the script to use checkbox.parsers.meminfo and checkbox.parsers.dmidecode. Thanks!

review: Needs Fixing
1479. By Brendan Donegan

Updated memory_compare to use meminfo parser from Checkbox instead of doing the parsing itself.

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

I've updated it to use the meminfo parser. As for the dmi parser, I agree with the fundamental principle of code re-use here, but I'm not too happy that every time I want to use a new attribute I have three files that need to be updated (the parser, the DmiDevice object and the script). I've also had to modify the dmi_resource script to prevent it crapping out because of the new attributes being used (which aren't universal so some checking had to be added). I'll update with the changes that need to be done to use the parser though and we can take it from there.

1480. By Brendan Donegan

Refactored memory_compare python version to use DmidecodeParser

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

I've made the necessary change to dmidecode.py and dmi.py to support the two extra attributes I need. I also extended dmi_resource.py to include them - let me know if you'd rather this wasn't included since it's a little outside the scope of this merge.

review: Needs Resubmitting
Revision history for this message
Marc Tardif (cr3) wrote :

In checkbox.lib.dmi, you added:

+ @property
+ def size(self):
+ attribute = "%s_size" % self.category.lower()
+ size = self._attributes.get(attribute)
+
+ size = int(size.split()[0]) * 1024
+
+ if size:
+ return size
+
+ return None

First, when the attribute exists, it will always interpret the size in kilobytes since it ignores the type in the split. Instead, you should use the string_to_type function defined in checkbox.lib.conversion.

Second, when the attribute doesn't exist, the split() method will fail horribly on a None value. So, I would suggest you write the size property method like this, remembering to import string_to_type at the beginning of the module of course:

+ @property
+ def size(self):
+ attribute = "%s_size" % self.category.lower()
+ size = self._attributes.get(attribute)
+ if size:
+ size = string_to_type(size)
+
+ return size

Still in checkbox.lib.dmi, you added:

+ @property
+ def form(self):
+ attribute = "%s_form" % self.category.lower()
+ form = self._attributes.get(attribute)
+
+ if form:
+ return form
+
+ return None

This could be expressed more simply as:

+ @property
+ def form(self):
+ attribute = "%s_form" % self.category.lower()
+ return self._attributes.get(attribute)

Other than that, the changes look good. After you make these changes, I'll have another look but I think we'll be good to merge. Thanks!

review: Needs Fixing
1481. By Brendan Donegan

Implemented cr3's suggestions.

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

Okay, thanks for pointing out the string_to_type function - very useful! I've implemented these suggestions pretty much verbatim, so I guess we're done here!

review: Needs Resubmitting
Revision history for this message
Marc Tardif (cr3) wrote :

Nice, thanks for improving checkbox.parsers!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
The diff is not available at this time. You can reload the page or download it.

Subscribers

People subscribed via source and target branches