diff options
author | Daniel P. Berrangé <berrange@redhat.com> | 2021-10-29 12:45:48 +0100 |
---|---|---|
committer | Cole Robinson <crobinso@redhat.com> | 2022-01-20 14:16:38 -0500 |
commit | e1c8866163a2861f79a08ce4e1487fc84b7d1ec1 (patch) | |
tree | 92877ef49e273aa74f65e8f1bdf66ed179e0da26 | |
parent | 552759bef49a27d49e6d981d51600cd7da34062e (diff) | |
download | virt-manager-e1c8866163a2861f79a08ce4e1487fc84b7d1ec1.tar.gz |
virtinst: validate that the CPU topology is sane
The product of sockets * dies * cores * threads must be equal to the
vCPU count. While libvirt and QEMU will report this error scenario,
it makes sense to catch it in virt-install, so we can test our local
logic for setting defaults for topology.
This exposes some inconsistent configurations in the test suite.
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
-rw-r--r-- | tests/data/cli/compare/virt-install-singleton-config-1.xml | 2 | ||||
-rw-r--r-- | tests/data/cli/compare/virt-install-singleton-config-3.xml | 2 | ||||
-rw-r--r-- | tests/test_cli.py | 4 | ||||
-rw-r--r-- | tests/test_misc.py | 12 | ||||
-rw-r--r-- | virtinst/domain/cpu.py | 12 |
5 files changed, 26 insertions, 6 deletions
diff --git a/tests/data/cli/compare/virt-install-singleton-config-1.xml b/tests/data/cli/compare/virt-install-singleton-config-1.xml index 05e80f3a..cf8f0eb6 100644 --- a/tests/data/cli/compare/virt-install-singleton-config-1.xml +++ b/tests/data/cli/compare/virt-install-singleton-config-1.xml @@ -37,7 +37,7 @@ <cpu mode="custom" match="exact"> <model fallback="forbid">Broadwell</model> <vendor>Intel</vendor> - <topology sockets="2" dies="1" cores="2" threads="2"/> + <topology sockets="2" dies="1" cores="2" threads="1"/> <feature policy="require" name="vme"/> <feature policy="require" name="ss"/> <feature policy="require" name="f16c"/> diff --git a/tests/data/cli/compare/virt-install-singleton-config-3.xml b/tests/data/cli/compare/virt-install-singleton-config-3.xml index 0dc7b78c..f903c2c9 100644 --- a/tests/data/cli/compare/virt-install-singleton-config-3.xml +++ b/tests/data/cli/compare/virt-install-singleton-config-3.xml @@ -12,7 +12,7 @@ <access mode="shared"/> <source type="anonymous"/> </memoryBacking> - <vcpu current="3" placement="auto">4</vcpu> + <vcpu current="3" placement="auto">6</vcpu> <sysinfo type="smbios"> <bios> <entry name="vendor">Acme LLC</entry> diff --git a/tests/test_cli.py b/tests/test_cli.py index 4cc831da..4d9070c2 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -467,7 +467,7 @@ c = vinst.add_category("xml-comparsion", "--connect %(URI-KVM)s --noautoconsole c.add_compare(""" --memory 1024 --uuid 12345678-12F4-1234-1234-123456789AFA ---vcpus 4,cores=2,threads=2,dies=1,sockets=2 --cpuset=1,3-5 +--vcpus 4,cores=2,threads=1,dies=1,sockets=2 --cpuset=1,3-5 --cpu host-copy --description \"foobar & baz\" --boot uefi,smbios_mode=emulate,boot1.dev=hd,boot.dev=network,initarg1=bar=baz,initarg=foo @@ -573,7 +573,7 @@ memnode0.cellid=1,memnode0.mode=strict,memnode0.nodeset=2 # Test the implied defaults for gl=yes setting virgl=on c.add_compare(""" ---vcpus vcpu.current=3,maxvcpus=4,vcpu.placement=auto +--vcpus vcpu.current=3,maxvcpus=6,vcpu.placement=auto --memory hotplugmemorymax=2048,hotplugmemoryslots=2 --disk none --features apic.eoi=off,hap=on,hyperv.synic.state=on,hyperv.reset.state=off,hyperv.spinlocks.state=on,hyperv.spinlocks.retries=5678,pae=on,pmu.state=on,pvspinlock.state=off,smm.state=off,viridian=on,vmcoreinfo.state=on,vmport.state=off,kvm.hidden.state=on,hyperv.vapic.state=off,hyperv.relaxed.state=off,gic.version=host,kvm.hint-dedicated.state=on,kvm.poll-control.state=on,ioapic.driver=qemu diff --git a/tests/test_misc.py b/tests/test_misc.py index 01f650c3..9b8c95ef 100644 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -42,15 +42,23 @@ def test_misc_cpu_topology(): cpu = virtinst.DomainCpu(conn) cpu.topology.cores = "4" - cpu.set_topology_defaults(9) + cpu.set_topology_defaults(8) assert get_top(cpu) == [2, 1, 4, 1] cpu = virtinst.DomainCpu(conn) cpu.topology.threads = "3" - cpu.set_topology_defaults(14) + cpu.set_topology_defaults(12) assert get_top(cpu) == [4, 1, 1, 3] cpu = virtinst.DomainCpu(conn) + cpu.topology.threads = "3" + try: + cpu.set_topology_defaults(14) + assert False, "Topology unexpectedly validated" + except ValueError: + pass + + cpu = virtinst.DomainCpu(conn) cpu.topology.sockets = 5 cpu.topology.cores = 2 assert cpu.vcpus_from_topology() == 10 diff --git a/virtinst/domain/cpu.py b/virtinst/domain/cpu.py index 16f7a588..f2d0c79f 100644 --- a/virtinst/domain/cpu.py +++ b/virtinst/domain/cpu.py @@ -41,6 +41,18 @@ class _CPUTopology(XMLBuilder): if not self.threads: self.threads = vcpus // self.total_vcpus() + if self.total_vcpus() != vcpus: + raise ValueError(_("Total CPUs implied by topology " + "(sockets=%(sockets)d * dies=%(dies)d * cores=%(cores)d * threads=%(threads)d == %(total)d) " + "does not match vCPU count %(vcpus)d") % { + "sockets": self.sockets, + "dies": self.dies, + "cores": self.cores, + "threads": self.threads, + "total": self.total_vcpus(), + "vcpus": vcpus, + }) + return def total_vcpus(self): |