Merge lp:~rvb/maas/cpu_count-bug-1272326 into lp:~maas-committers/maas/trunk

Proposed by Raphaël Badin
Status: Merged
Approved by: Raphaël Badin
Approved revision: no longer in the source branch.
Merged at revision: 1858
Proposed branch: lp:~rvb/maas/cpu_count-bug-1272326
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 51 lines (+26/-3)
2 files modified
src/metadataserver/models/commissioningscript.py (+8/-3)
src/metadataserver/models/tests/test_commissioningscript.py (+18/-0)
To merge this branch: bzr merge lp:~rvb/maas/cpu_count-bug-1272326
Reviewer Review Type Date Requested Status
Andres Rodriguez (community) Approve
Review via email: mp+203503@code.launchpad.net

Commit message

Fix MAAS' cpu count detection.

Description of the change

The xpath expression now takes into account the declared number of "threads" for a processor, while still counting as one processor those that do not declare their number of threads.

To post a comment you must log in.
Revision history for this message
Andres Rodriguez (andreserl) wrote :

lgtm!

Thanks for the patch! This is awesome!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/metadataserver/models/commissioningscript.py'
2--- src/metadataserver/models/commissioningscript.py 2013-12-02 13:57:39 +0000
3+++ src/metadataserver/models/commissioningscript.py 2014-01-28 10:41:12 +0000
4@@ -116,10 +116,15 @@
5 """)
6
7
8+# Count the processors which do not declare their number of 'threads'
9+# as 1 processor.
10 _xpath_processor_count = """\
11- count(//node[@id='core']/
12- node[@class='processor'][not(@disabled)])
13-"""
14+ sum(//node[@id='core']/
15+ node[@class='processor']
16+ [not(@disabled)]//setting[@id='threads']/@value) +
17+ count(//node[@id='core']/node[@class='processor']
18+ [not(@disabled)][not(configuration/setting[@id='threads'])])"""
19+
20
21 # Some machines have a <size> element in their memory <node> with the total
22 # amount of memory, and other machines declare the size of the memory in
23
24=== modified file 'src/metadataserver/models/tests/test_commissioningscript.py'
25--- src/metadataserver/models/tests/test_commissioningscript.py 2014-01-20 09:01:25 +0000
26+++ src/metadataserver/models/tests/test_commissioningscript.py 2014-01-28 10:41:12 +0000
27@@ -461,6 +461,24 @@
28 node = reload_object(node)
29 self.assertEqual(2, node.cpu_count)
30
31+ def test_cpu_count_counts_multi_cores(self):
32+ node = factory.make_node()
33+ xmlbytes = dedent("""\
34+ <node id="core">
35+ <node id="cpu:0" class="processor">
36+ <configuration>
37+ <setting id="cores" value="2" />
38+ <setting id="enabledcores" value="2" />
39+ <setting id="threads" value="4" />
40+ </configuration>
41+ </node>
42+ <node id="cpu:1" class="processor"/>
43+ </node>
44+ """).encode("utf-8")
45+ update_hardware_details(node, xmlbytes, 0)
46+ node = reload_object(node)
47+ self.assertEqual(5, node.cpu_count)
48+
49 def test_cpu_count_skips_disabled_cpus(self):
50 node = factory.make_node()
51 xmlbytes = dedent("""\