summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel P. Berrangé <berrange@redhat.com>2021-10-29 13:04:16 +0100
committerCole Robinson <crobinso@redhat.com>2022-01-20 14:16:38 -0500
commit609007c9ca4632dc2e51678db7c8a525dde850f1 (patch)
tree5ebe91dd4c15ef29325426d0b64839b3efe1237c
parent9bb86f51861dbe312676250482e5df7a82a9b6bd (diff)
downloadvirt-manager-609007c9ca4632dc2e51678db7c8a525dde850f1.tar.gz
virtinst: make CPU topology defaulting take account of dies
Any missing values in the topology need to be calculated based on the other values which are set. We can take account of fact that 'total_vcpus' treats any unset values as being 1 to simplify the way we set topology defaults. This ensures that topology defaulting takes account of dies. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
-rw-r--r--tests/test_misc.py5
-rw-r--r--virtinst/domain/cpu.py12
2 files changed, 8 insertions, 9 deletions
diff --git a/tests/test_misc.py b/tests/test_misc.py
index 2162daec..933df6b9 100644
--- a/tests/test_misc.py
+++ b/tests/test_misc.py
@@ -33,6 +33,11 @@ def test_misc_cpu_topology():
assert get_top(cpu) == [2, 1, 3, 1]
cpu = virtinst.DomainCpu(conn)
+ cpu.topology.dies = "3"
+ cpu.set_topology_defaults(9)
+ assert get_top(cpu) == [3, 3, 1, 1]
+
+ cpu = virtinst.DomainCpu(conn)
cpu.topology.cores = "4"
cpu.set_topology_defaults(9)
assert get_top(cpu) == [2, 1, 4, 1]
diff --git a/virtinst/domain/cpu.py b/virtinst/domain/cpu.py
index 06858a3f..16f7a588 100644
--- a/virtinst/domain/cpu.py
+++ b/virtinst/domain/cpu.py
@@ -30,22 +30,16 @@ class _CPUTopology(XMLBuilder):
# `sockets`, `cores`, and `threads` are mandatory.
def set_defaults_from_vcpus(self, vcpus):
if not self.sockets:
- if not self.cores:
- self.sockets = vcpus // self.threads
- else:
- self.sockets = vcpus // self.cores
+ self.sockets = vcpus // self.total_vcpus()
if not self.dies:
self.dies = 1
if not self.cores:
- if not self.threads:
- self.cores = vcpus // self.sockets
- else:
- self.cores = vcpus // (self.sockets * self.threads)
+ self.cores = vcpus // self.total_vcpus()
if not self.threads:
- self.threads = vcpus // (self.sockets * self.cores)
+ self.threads = vcpus // self.total_vcpus()
return