Skip to content

virttest: handle failed qmp_cmds without crashing#4351

Open
bssrikanth wants to merge 1 commit intoavocado-framework:masterfrom
bssrikanth:fix_qemucap
Open

virttest: handle failed qmp_cmds without crashing#4351
bssrikanth wants to merge 1 commit intoavocado-framework:masterfrom
bssrikanth:fix_qemucap

Conversation

@bssrikanth
Copy link
Copy Markdown

get_qmp_cmds could return None when the query-commands probe produced no parseable output, so has_qmp_cmd did cmd in None and raised TypeError.

Always return a list (empty on failure), log a warning, and treat an empty command set as unsupported so capability checks return false instead of crashing.

@bssrikanth
Copy link
Copy Markdown
Author

Before fix:

..
[stdlog] Traceback (most recent call last):
[stdlog]   File "/usr/local/lib/python3.12/dist-packages/virttest/qemu_vm.py", line 3774, in create
[stdlog]     self.devices, self.spice_options = self.make_create_command()
[stdlog]                                        ^^^^^^^^^^^^^^^^^^^^^^^^^^
[stdlog]   File "/usr/local/lib/python3.12/dist-packages/virttest/qemu_vm.py", line 1839, in make_create_command
[stdlog]     devices = qcontainer.DevContainer(
[stdlog]               ^^^^^^^^^^^^^^^^^^^^^^^^
[stdlog]   File "/usr/local/lib/python3.12/dist-packages/virttest/qemu_devices/qcontainer.py", line 220, in __init__
[stdlog]     self._probe_capabilities()
[stdlog]   File "/usr/local/lib/python3.12/dist-packages/virttest/qemu_devices/qcontainer.py", line 453, in _probe_capabilities
[stdlog]     if self.has_qmp_cmd("migrate-set-parameters") and self.has_hmp_cmd(
[stdlog]        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[stdlog]   File "/usr/local/lib/python3.12/dist-packages/virttest/qemu_devices/qcontainer.py", line 805, in has_qmp_cmd
[stdlog]     return cmd in self.__qmp_cmds
[stdlog]            ^^^^^^^^^^^^^^^^^^^^^^
[stdlog] TypeError: argument of type 'NoneType' is not iterable
[stdlog]
[stdlog] Traceback (most recent call last):
[stdlog]   File "/root/elves/data/avocado-vt/virttest/test-providers.d/downloads/io-github-autotest-qemu/qemu/tests/amd_cvm_boot.py", line 75, in run
[stdlog]     vm.create()
[stdlog]   File "/usr/local/lib/python3.12/dist-packages/virttest/error_context.py", line 141, in new_fn
[stdlog]     return fn(*args, **kwargs)
[stdlog]            ^^^^^^^^^^^^^^^^^^^
[stdlog]   File "/usr/local/lib/python3.12/dist-packages/virttest/qemu_vm.py", line 3787, in create
[stdlog]     raise virt_vm.VMStartError(
[stdlog] virttest.virt_vm.VMStartError: VM 'avocado-vt-vm1' failed to start: Error occurred while executing make_create_command(). Check the log for traceback.
..

After fix:

[stdlog] 2026-03-25 06:02:42,188 avocado.virttest.qemu_devices.qcontainer qcontainer       L0179 WARNI| Could not list QMP commands for /root/amdsos_qemu/bin/qemu-system-x86_64 (query-commands line missing or unparsable). Check that this binary runs with '-qmp stdio -vnc none -S' and prints JSON monitor replies on stdout. Migration-related capability probes will assume QMP commands are absent.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request enhances the QMP command discovery process in virttest/qemu_devices/qcontainer.py. It introduces explicit logging when QMP commands are unparsable or missing and adds a safety check in has_qmp_cmd to handle empty command lists. I have no feedback to provide.

get_qmp_cmds could return None when the query-commands probe produced no
parseable output, so has_qmp_cmd did cmd in None and raised TypeError.

Always return a list (empty on failure), log a warning, and treat an empty
command set as unsupported so capability checks return false instead
of crashing.

Signed-off-by: Srikanth Aithal <sraithal@amd.com>
@bssrikanth
Copy link
Copy Markdown
Author

@smitterl @richtja @nickzhq @YongxueHong @zhencliu @cliping @nanli1 @Yingshun @dzhengfy @chloerh @PaulYuuu requesting maintainers review on this pull request.
Thank you for your time in advance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant