← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~jelmer/maas/fix-memory-lenovo into lp:maas

 

Jelmer Vernooij has proposed merging lp:~jelmer/maas/fix-memory-lenovo into lp:maas.

Commit message:
Fix memory count for lshw -xml output without a <size> attribute for the memory <node>.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  Bug #1064638 in MAAS: "Commissioning is failing to set node memory attribute"
  https://bugs.launchpad.net/maas/+bug/1064638

For more details, see:
https://code.launchpad.net/~jelmer/maas/fix-memory-lenovo/+merge/129322

This fixes the memory count for the lenovo machines by looking at the individual banks if there is no <size> attribute on the memory <node>. Unfortunately this makes the xpath expression a fair bit more complex.

Also tested manually with the lshw for highbank and lenovo in the original bug report and on my local x86_64 machine.
-- 
https://code.launchpad.net/~jelmer/maas/fix-memory-lenovo/+merge/129322
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~jelmer/maas/fix-memory-lenovo into lp:maas.
=== modified file 'src/maasserver/models/node.py'
--- src/maasserver/models/node.py	2012-10-11 06:59:33 +0000
+++ src/maasserver/models/node.py	2012-10-11 21:58:21 +0000
@@ -352,7 +352,7 @@
 
 
 _xpath_processor_count = "count(//node[@id='core']/node[@class='processor'])"
-_xpath_memory_bytes = "//node[@id='memory']/size[@units='bytes'] div 1048576"
+_xpath_memory_bytes = "sum(//node[@id='memory']/size[@units='bytes']|//node[starts-with(@id, 'memory:')]/node[starts-with(@id, 'bank:')]/size[@units='bytes']) div 1024 div 1024"
 
 
 def update_hardware_details(node, xmlbytes, tag_manager):

=== modified file 'src/maasserver/tests/test_node.py'
--- src/maasserver/tests/test_node.py	2012-10-11 06:59:33 +0000
+++ src/maasserver/tests/test_node.py	2012-10-11 21:58:21 +0000
@@ -523,6 +523,31 @@
         node = reload_object(node)
         self.assertEqual(4096, node.memory)
 
+    def test_hardware_updates_memory_lenovo(self):
+        node = factory.make_node()
+        xmlbytes = (
+          '<node>\n'
+            '<node id="memory:0" class="memory">\n'
+              '<slot>System board or motherboard</slot>\n'
+              '<node id="bank:0" class="memory" handle="DMI:002D">\n'
+                '<size units="bytes">4294967296</size>\n'
+              '</node>\n'
+              '<node id="bank:1" class="memory" handle="DMI:002E">\n'
+                '<size units="bytes">3221225472</size>\n'
+              '</node>\n'
+            '</node>\n'
+            '<node id="memory:1" class="memory">\n'
+              '<node id="bank:0" class="memory" handle="DMI:002F">\n'
+                '<size units="bytes">536870912</size>\n'
+              '</node>\n'
+            '</node>\n'
+            '<node id="memory:2" class="memory"></node>\n'
+          '</node>\n'
+          )
+        node.set_hardware_details(xmlbytes)
+        node = reload_object(node)
+        self.assertEqual(7680, node.memory)
+
     def test_hardware_updates_tags_match(self):
         tag1 = factory.make_tag(factory.getRandomString(10), "/node")
         tag2 = factory.make_tag(factory.getRandomString(10), "//node")