From 47ad9a2e6081d4b3652f8a529ecc6bd8601e0473 Mon Sep 17 00:00:00 2001
From: Chen Qun <kuhn.chenqun@huawei.com>
Date: Sat, 11 Apr 2020 15:43:41 +0800
Subject: [PATCH 41/77] max_vcpus: add update_vcpu_topology function for
 max_vcpu

It is need to set vcpu topology, if we update max_vcpu num.
Update libvirt version for openEuler.

Signed-off-by: Chen Qun <kuhn.chenqun@huawei.com>
---
 libvirt/tests/cfg/cpu/max_vcpus.cfg | 21 +++++++++++++++++++--
 libvirt/tests/src/cpu/max_vcpus.py  | 17 ++++++++++++++++-
 2 files changed, 35 insertions(+), 3 deletions(-)

diff --git a/libvirt/tests/cfg/cpu/max_vcpus.cfg b/libvirt/tests/cfg/cpu/max_vcpus.cfg
index 95286608..e9a6acab 100644
--- a/libvirt/tests/cfg/cpu/max_vcpus.cfg
+++ b/libvirt/tests/cfg/cpu/max_vcpus.cfg
@@ -17,17 +17,22 @@
             variants:
                 - i440fx_test:
                     only i440fx
+                    guest_vcpu = "240"
+                    vcpu_sockets = "2"
+                    vcpu_cores = "120"
+                    vcpu_threads = "1"
                     variants:
                         - default:
                             check = "i440fx_test_default"
-                            guest_vcpu = "240"
                         - hotplug:
                             check = "i440fx_test_hotplug"
                             current_vcpu = "2"
                             target_vcpu = "50"
-                            guest_vcpu = "240"
                 - ioapic_iommu:
                     guest_vcpu = "50"
+                    vcpu_sockets = "2"
+                    vcpu_cores = "25"
+                    vcpu_threads = "1"
                     only q35
                     variants:
                         - default:
@@ -43,19 +48,31 @@
                     only i440fx
                     check = "i440fx_test_negative"
                     guest_vcpu = "241"
+                    vcpu_sockets = "1"
+                    vcpu_cores = "241"
+                    vcpu_threads = "1"
                     err_msg = "unsupported configuration: Maximum CPUs greater than specified machine type limit"
                 - no_iommu:
                     only q35
                     check = "no_iommu"
                     guest_vcpu = "256"
+                    vcpu_sockets = "2"
+                    vcpu_cores = "128"
+                    vcpu_threads = "1"
                     err_msg = "unsupported configuration: more than 255 vCPUs require extended interrupt mode enabled on the iommu device"
                 - with_iommu:
                     only q35
                     check = "with_iommu"
                     guest_vcpu = "256"
+                    vcpu_sockets = "2"
+                    vcpu_cores = "128"
+                    vcpu_threads = "1"
                     err_msg = "IOMMU interrupt remapping requires split I/O APIC \(ioapic driver='qemu'\)"
                 - ioapic_iommu:
                     only q35
                     check = "ioapic_iommu_ne"
                     guest_vcpu = "289"
+                    vcpu_sockets = "1"
+                    vcpu_cores = "289"
+                    vcpu_threads = "1"
                     err_msg = "unsupported configuration: Maximum CPUs greater than specified machine type limit"
diff --git a/libvirt/tests/src/cpu/max_vcpus.py b/libvirt/tests/src/cpu/max_vcpus.py
index 80054293..13690e03 100644
--- a/libvirt/tests/src/cpu/max_vcpus.py
+++ b/libvirt/tests/src/cpu/max_vcpus.py
@@ -27,6 +27,16 @@ def run(test, params, env):
     vmxml = libvirt_xml.VMXML.new_from_inactive_dumpxml(vm_name)
     bkxml = vmxml.copy()
 
+    def update_vcpu_topology(vmxml):
+        vm_cores = int(params.get("vcpu_cores", 25))
+        vm_threads = int(params.get("vcpu_threads", 1))
+        vm_sockets = int(params.get("vcpu_sockets", 2))
+        vmcpu_xml = vmxml['cpu']
+        vmcpu_xml['topology'] = {'sockets': vm_sockets,
+                                 'cores': vm_cores,
+                                 'threads': vm_threads}
+        vmxml['cpu'] = vmcpu_xml
+
     def check_onlinevcpus(vm, cpu_num):
         """
 
@@ -103,6 +113,7 @@ def run(test, params, env):
             target_vcpu = params.get('target_vcpu')
             if 'hotplug' not in check:
                 vmxml.vcpu = int(guest_vcpu)
+                update_vcpu_topology(vmxml)
                 vmxml.sync()
                 if status_error:
                     if start_fail:
@@ -116,6 +127,7 @@ def run(test, params, env):
                 vmxml.vcpu = int(guest_vcpu)
                 vmxml.current_vcpu = int(current_vcpu)
                 target_vcpu = int(target_vcpu)
+                update_vcpu_topology(vmxml)
                 vmxml.sync()
                 vm.start()
                 logging.info(libvirt_xml.VMXML.new_from_dumpxml(vm_name))
@@ -129,12 +141,14 @@ def run(test, params, env):
         if check == 'no_iommu':
             logging.info('Set vcpu to %s', guest_vcpu)
             vmxml.vcpu = int(guest_vcpu)
+            update_vcpu_topology(vmxml)
             result_need_check = virsh.define(vmxml.xml, debug=True)
 
         # Set iommu device but not set ioapci in features for q35 VM
         if check == 'with_iommu':
             logging.info('Set vcpu to %s', guest_vcpu)
             vmxml.vcpu = int(guest_vcpu)
+            update_vcpu_topology(vmxml)
             set_iommu(vmxml)
             result_need_check = virsh.define(vmxml.xml, debug=True)
 
@@ -153,13 +167,14 @@ def run(test, params, env):
             ori_vcpu = vmxml.vcpu
             vmxml.vcpu = int(guest_vcpu)
             vmxml.current_vcpu = ori_vcpu
+            update_vcpu_topology(vmxml)
 
             if 'hotplug' not in check:
                 vmxml.current_vcpu = int(guest_vcpu)
 
             if status_error:
                 if start_fail:
-                    if libvirt_version.version_compare(5, 6, 0):
+                    if libvirt_version.version_compare(5, 5, 0):
                         result_need_check = virsh.define(vmxml.xml, debug=True)
                     else:
                         vmxml.sync()
-- 
2.23.0

