All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] tests/functional: use QMP to query available machines
@ 2026-06-25 16:53 Ganesh Harshan
  2026-06-26 10:12 ` Daniel P. Berrangé
  0 siblings, 1 reply; 2+ messages in thread
From: Ganesh Harshan @ 2026-06-25 16:53 UTC (permalink / raw)
  To: th.huth+qemu; +Cc: philmd, berrange, qemu-devel, Ganesh Harshan

Replace parsing of "qemu -M help" in set_machine() with
QMP "query-machines".

The previous approach relied on parsing human-readable CLI
output and substring matching, which is fragile and prone to
incorrect matches. It is also sensitive to output format changes.

Use QMP instead to retrieve structured machine information,
ensuring accurate matching and better maintainability.

Cache the result at the class level to avoid repeated QEMU
startup overhead.

Signed-off-by: Ganesh Harshan <ganeshredcobra@gmail.com>
---
 tests/functional/qemu_test/testcase.py | 32 +++++++++++++++++++++-----
 1 file changed, 26 insertions(+), 6 deletions(-)

diff --git a/tests/functional/qemu_test/testcase.py b/tests/functional/qemu_test/testcase.py
index eaec1bea13..5920d6a784 100644
--- a/tests/functional/qemu_test/testcase.py
+++ b/tests/functional/qemu_test/testcase.py
@@ -314,14 +314,34 @@ def setUp(self):
         console_log.addHandler(self._console_log_fh)
 
     def set_machine(self, machinename):
-        # TODO: We should use QMP to get the list of available machines
-        if not self._machinehelp:
-            self._machinehelp = run(
-                [self.qemu_bin, '-M', 'help'],
-                capture_output=True, check=True, encoding='utf8').stdout
-        if self._machinehelp.find(machinename) < 0:
+        cls = type(self)
+
+        if not hasattr(cls, "_machines"):
+            tmp_vm = QEMUMachine(self.qemu_bin)
+            tmp_vm.set_machine('none')
+
+            try:
+                tmp_vm.launch()
+                resp = tmp_vm.qmp('query-machines')
+
+                machines = resp.get('return', [])
+                cls._machines = [
+                    m.get('name') for m in machines if 'name' in m
+                ]
+
+            finally:
+                try:
+                    tmp_vm.shutdown()
+                except Exception:
+                    pass
+
+        self._machines = cls._machines
+
+        if machinename not in self._machines:
             self.skipTest('no support for machine ' + machinename)
+
         self.machine = machinename
+        self.vm.set_machine(machinename)
 
     def require_accelerator(self, accelerator):
         """
-- 
2.47.3



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] tests/functional: use QMP to query available machines
  2026-06-25 16:53 [PATCH] tests/functional: use QMP to query available machines Ganesh Harshan
@ 2026-06-26 10:12 ` Daniel P. Berrangé
  0 siblings, 0 replies; 2+ messages in thread
From: Daniel P. Berrangé @ 2026-06-26 10:12 UTC (permalink / raw)
  To: Ganesh Harshan; +Cc: th.huth+qemu, philmd, qemu-devel

On Thu, Jun 25, 2026 at 12:53:10PM -0400, Ganesh Harshan wrote:
> Replace parsing of "qemu -M help" in set_machine() with
> QMP "query-machines".
> 
> The previous approach relied on parsing human-readable CLI
> output and substring matching, which is fragile and prone to
> incorrect matches. It is also sensitive to output format changes.
> 
> Use QMP instead to retrieve structured machine information,
> ensuring accurate matching and better maintainability.
> 
> Cache the result at the class level to avoid repeated QEMU
> startup overhead.
> 
> Signed-off-by: Ganesh Harshan <ganeshredcobra@gmail.com>
> ---
>  tests/functional/qemu_test/testcase.py | 32 +++++++++++++++++++++-----
>  1 file changed, 26 insertions(+), 6 deletions(-)

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>


With regards,
Daniel
-- 
|: https://berrange.com       ~~        https://hachyderm.io/@berrange :|
|: https://libvirt.org          ~~          https://entangle-photo.org :|
|: https://pixelfed.art/berrange   ~~    https://fstop138.berrange.com :|



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-06-26 10:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-25 16:53 [PATCH] tests/functional: use QMP to query available machines Ganesh Harshan
2026-06-26 10:12 ` Daniel P. Berrangé

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.