diff mbox series

[v2,08/29] python/qemu: Add binutils::binary_get_machines()

Message ID 20200129212345.20547-9-philmd@redhat.com (mailing list archive)
State New, archived
Headers show
Series tests/acceptance/virtio_seg_max_adjust: Restrict it to Linux/X86 | expand

Commit Message

Philippe Mathieu-Daudé Jan. 29, 2020, 9:23 p.m. UTC
Add a helper to query the list of machines built into a QEMU binary.
We simply send the 'query-machines' command over a QMP socket.

Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 python/qemu/binutils.py          | 15 +++++++++++++++
 tests/acceptance/core_scripts.py |  9 +++++++++
 2 files changed, 24 insertions(+)

Comments

Cornelia Huck Jan. 31, 2020, 9:53 a.m. UTC | #1
On Wed, 29 Jan 2020 22:23:24 +0100
Philippe Mathieu-Daudé <philmd@redhat.com> wrote:

> Add a helper to query the list of machines built into a QEMU binary.
> We simply send the 'query-machines' command over a QMP socket.
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> ---
>  python/qemu/binutils.py          | 15 +++++++++++++++
>  tests/acceptance/core_scripts.py |  9 +++++++++
>  2 files changed, 24 insertions(+)

Reviewed-by: Cornelia Huck <cohuck@redhat.com>
diff mbox series

Patch

diff --git a/python/qemu/binutils.py b/python/qemu/binutils.py
index 905d393ba5..7bb57c521b 100644
--- a/python/qemu/binutils.py
+++ b/python/qemu/binutils.py
@@ -51,3 +51,18 @@  def binary_get_arch(qemu_bin):
         LOG.info(res)
         vm.shutdown()
         return res['arch']
+
+def binary_get_machines(qemu_bin):
+    '''
+    Get list of machines supported by a QEMU binary
+
+    @param qemu_bin (str): path to the QEMU binary
+    @return list of machines supported by the binary
+    '''
+    with QEMUMachine(qemu_bin) as vm:
+        vm.set_machine('none')
+        vm.launch()
+        res = vm.command('query-machines')
+        LOG.info(res)
+        vm.shutdown()
+        return [m['name'] for m in res]
diff --git a/tests/acceptance/core_scripts.py b/tests/acceptance/core_scripts.py
index 93dd822368..a5b112f928 100644
--- a/tests/acceptance/core_scripts.py
+++ b/tests/acceptance/core_scripts.py
@@ -17,6 +17,7 @@  import logging
 sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'python'))
 from avocado_qemu import Test
 from qemu.binutils import binary_get_arch
+from qemu.binutils import binary_get_machines
 from qemu.binutils import binary_get_version
 
 
@@ -40,3 +41,11 @@  class PythonQemuCoreScripts(Test):
         a = binary_get_arch(self.qemu_bin)
         logger.debug('arch: {}'.format(a))
         self.assertIn(a, ['i386', 'x86_64'])
+
+    def test_get_machines(self):
+        logger = logging.getLogger('core')
+        machines = binary_get_machines(self.qemu_bin)
+        for m in sorted(machines):
+            logger.debug('machine: {}'.format(m))
+        # The 'none' machine is always available
+        self.assertIn('none', machines)