← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~rvb/maas/bug-1177589 into lp:maas

 

Raphaël Badin has proposed merging lp:~rvb/maas/bug-1177589 into lp:maas.

Commit message:
Fix xpath expression to not take disabled cpus into account.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  Bug #1177589 in MAAS: "Virtual machine reports a number of cpu=64 where there is only 1 cpu"
  https://bugs.launchpad.net/maas/+bug/1177589

For more details, see:
https://code.launchpad.net/~rvb/maas/bug-1177589/+merge/162894
-- 
https://code.launchpad.net/~rvb/maas/bug-1177589/+merge/162894
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~rvb/maas/bug-1177589 into lp:maas.
=== modified file 'src/maasserver/models/node.py'
--- src/maasserver/models/node.py	2013-05-03 14:39:18 +0000
+++ src/maasserver/models/node.py	2013-05-07 22:59:28 +0000
@@ -361,7 +361,9 @@
         return processed_nodes
 
 
-_xpath_processor_count = "count(//node[@id='core']/node[@class='processor'])"
+_xpath_processor_count = (
+    "count(//node[@id='core']/"
+        "node[@class='processor' and not(@disabled='true')])")
 
 # Some machines have a <size> element in their memory <node> with the total
 # amount of memory, and other machines declare the size of the memory in

=== modified file 'src/maasserver/tests/test_node.py'
--- src/maasserver/tests/test_node.py	2013-05-03 14:39:18 +0000
+++ src/maasserver/tests/test_node.py	2013-05-07 22:59:28 +0000
@@ -584,6 +584,20 @@
         node = reload_object(node)
         self.assertEqual(2, node.cpu_count)
 
+    def test_cput_count_skips_disabled_disabled_cpus(self):
+        node = factory.make_node()
+        xmlbytes = (
+            '<node id="core">'
+                '<node id="cpu:0" class="processor"/>'
+                '<node id="cpu:1" disabled="true" claimed="true"'
+                    'class="processor"/>'
+                '<node id="cpu:2" disabled="true" claimed="true"'
+                    'class="processor"/>'
+            '</node>')
+        node.set_hardware_details(xmlbytes)
+        node = reload_object(node)
+        self.assertEqual(1, node.cpu_count)
+
     def test_hardware_updates_memory(self):
         node = factory.make_node()
         xmlbytes = (