Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion libvirt/tests/cfg/libvirt_vcpu_plug_unplug.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,17 @@
vcpu_plug_num = 240
vcpu_unplug_num = 1
vcpu_max_num = 240

- with_compat_mode:
only live
only ppc64le,ppc64
only POWER11
compat_mode = "yes"
cpu_model = "power10"
test_itr = 5
vcpu_max_num = "8"
vcpu_current_num = "2"
vcpu_plug_num = "6"
vcpu_unplug_num = "3"
variants:
- live:
setvcpu_option = "--live"
Expand Down
17 changes: 17 additions & 0 deletions libvirt/tests/src/libvirt_vcpu_plug_unplug.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@ def check_setvcpus_result(cmd_result, expect_error):
with_stress = "yes" == params.get("run_stress", "no")
iterations = int(params.get("test_itr", 1))
topology_correction = "yes" == params.get("topology_correction", "no")
compat_mode = params.get("compat_mode")
cpu_model = params.get("cpu_model")
Comment on lines +243 to +244

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Use explicit yes/no parsing for compat_mode to avoid false-positive activation.

Line 243 stores a raw string and Line 303 checks truthiness, so "no" would still enter compat-mode logic. Parse it like other flags in this file.

Suggested fix
-    compat_mode = params.get("compat_mode")
-    cpu_model =  params.get("cpu_model")
+    compat_mode = "yes" == params.get("compat_mode", "no")
+    cpu_model = params.get("cpu_model")
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@libvirt/tests/src/libvirt_vcpu_plug_unplug.py` around lines 243 - 244, The
compat_mode variable at line 243 is assigned a raw string from params.get(),
which causes a false-positive when checked with if compat_mode at line 303,
since the string "no" is still truthy. Replace the assignment of compat_mode
with explicit boolean parsing using the same pattern as other boolean flags in
this file (likely params.get_bool() or equivalent), so that string values like
"no" are properly parsed as False instead of being treated as truthy.

# Init expect vcpu count values
expect_vcpu_num = {'max_config': vcpu_max_num, 'max_live': vcpu_max_num,
'cur_config': vcpu_current_num,
Expand Down Expand Up @@ -298,6 +300,21 @@ def check_setvcpus_result(cmd_result, expect_error):
vmxml.set_agent_channel()
else:
vmxml.remove_agent_channels()
if compat_mode:
logging.info("Setting compatibility mode with CPU model: %s", cpu_model)

try:
cpu_xml = vmxml.cpu
except xcepts.LibvirtXMLNotFoundError:
logging.debug("No CPU element found, creating new one")
cpu_xml = VMCPUXML()
Comment on lines +307 to +310

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Verify canonical definitions/import patterns for these symbols in this repo.
rg -n "class VMCPUXML|LibvirtXMLNotFoundError" -C2
rg -n "from virttest\.libvirt_xml import xcepts|from virttest\.libvirt_xml\.vm_xml import .*VMCPUXML" -C2

Repository: autotest/tp-libvirt

Length of output: 37962


🏁 Script executed:

head -50 libvirt/tests/src/libvirt_vcpu_plug_unplug.py | cat -n

Repository: autotest/tp-libvirt

Length of output: 1896


🏁 Script executed:

sed -n '305,315p' libvirt/tests/src/libvirt_vcpu_plug_unplug.py | cat -n

Repository: autotest/tp-libvirt

Length of output: 543


Import xcepts and VMCPUXML to fix undefined name errors.

The exception handler at line 308 references xcepts.LibvirtXMLNotFoundError, and line 310 instantiates VMCPUXML(), but neither is imported. This will raise NameError when the fallback path executes.

Fix
 from virttest.libvirt_xml.vm_xml import VMXML
+from virttest.libvirt_xml import xcepts
+from virttest.libvirt_xml.vm_xml import VMCPUXML

Or combine into a single import line:

-from virttest.libvirt_xml.vm_xml import VMXML
+from virttest.libvirt_xml import xcepts
+from virttest.libvirt_xml.vm_xml import VMXML, VMCPUXML
🧰 Tools
🪛 Ruff (0.15.17)

[error] 308-308: Undefined name xcepts

(F821)


[error] 310-310: Undefined name VMCPUXML

(F821)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@libvirt/tests/src/libvirt_vcpu_plug_unplug.py` around lines 307 - 310, Add
the missing imports at the top of the libvirt_vcpu_plug_unplug.py file to
resolve the NameError exceptions. The exception handler at line 308 references
xcepts.LibvirtXMLNotFoundError which requires importing the xcepts module, and
line 310 instantiates VMCPUXML() which requires importing the VMCPUXML class.
Add both imports in the appropriate import section of the file alongside other
existing imports from the virttest library and related modules.

Source: Linters/SAST tools


# Force mode to host-model when explicit compat model is provided
cpu_xml.mode = "host-model"
cpu_xml.model = cpu_model
vmxml.cpu = cpu_xml
logging.info("CPU mode set to 'host-model' with model '%s'", cpu_model)

vmxml.sync()

vmxml.set_vm_vcpus(vm_name, vcpu_max_num, vcpu_current_num,
Expand Down
Loading