Skip to content
Open
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
4 changes: 4 additions & 0 deletions libvirt/tests/src/virsh_cmd/host/virsh_cpu_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,9 @@ def run(test, params, env):
logging.debug("Get the CPU models for arch: %s" % arch)
result = virsh.cpu_models(arch, options=option, uri=connect_uri,
ignore_status=True, debug=True)
# Check if the architecture is not supported; log it and skip to the next architecture.
if "architecture is not supported by CPU driver" in result.stderr:
logging.info("%s architecture is not supported by CPU driver as expected" % arch)
continue
Comment on lines +84 to +87
Copy link

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

Consider checking exit status in addition to stderr.

The condition only checks stderr content without verifying that the command actually failed. If the command succeeds (exit status 0) but includes this text in stderr as a warning, the architecture would be incorrectly skipped.

Apply this diff for more defensive error handling:

 # Check if the architecture is not supported; log it and skip to the next architecture.
-if "architecture is not supported by CPU driver" in result.stderr:
+if result.exit_status != 0 and "architecture is not supported by CPU driver" in result.stderr:
     logging.info("%s architecture is not supported by CPU driver as expected" % arch)
     continue

Additionally, the hardcoded error message string may be fragile if libvirt changes its error format.

Please verify the error message format is stable across libvirt versions:


🌐 Web query:

What error message does libvirt virsh cpu-models command return for unsupported architectures?

💡 Result:

It doesn't return an error — for architectures where libvirt has no built-in models it prints "all CPU models are accepted". [1][2]

Sources:
[1] libvirt virsh manpage (cpu-models).
[2] libvirt-devel discussion noting cpu-models prints "all CPU models are accepted" for aarch64/s390x.


Critical: The error message string is incorrect and will never match libvirt's actual output.

libvirt prints "all CPU models are accepted" for unsupported architectures, not "architecture is not supported by CPU driver". This means the condition on line 85 will never trigger, and unsupported architectures won't be skipped as intended.

Fix: Replace the error message string with the correct one:

 # Check if the architecture is not supported; log it and skip to the next architecture.
-if "architecture is not supported by CPU driver" in result.stderr:
+if "all CPU models are accepted" in result.stderr:
     logging.info("%s architecture is not supported by CPU driver as expected" % arch)
     continue
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# Check if the architecture is not supported; log it and skip to the next architecture.
if "architecture is not supported by CPU driver" in result.stderr:
logging.info("%s architecture is not supported by CPU driver as expected" % arch)
continue
# Check if the architecture is not supported; log it and skip to the next architecture.
if "all CPU models are accepted" in result.stderr:
logging.info("%s architecture is not supported by CPU driver as expected" % arch)
continue
🤖 Prompt for AI Agents
In libvirt/tests/src/virsh_cmd/host/virsh_cpu_models.py around lines 84 to 87,
the substring checked in result.stderr is wrong and will never match libvirt
output; replace the check for "architecture is not supported by CPU driver" with
"all CPU models are accepted" so the condition triggers for unsupported
architectures, keep the logging and continue behavior the same.

utlv.check_exit_status(result, expect_error=status_error)
compare_cpu_model_with_qemu(test, params, result, qemu_cmd)