From: Cleber Rosa <crosa@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Kevin Wolf" <kwolf@redhat.com>, "Fam Zheng" <fam@euphon.net>,
"Thomas Huth" <thuth@redhat.com>,
"Eduardo Habkost" <ehabkost@redhat.com>,
qemu-block@nongnu.org, "Erik Skultety" <eskultet@redhat.com>,
"Philippe Mathieu-Daudé" <philmd@redhat.com>,
"Cleber Rosa" <crosa@redhat.com>,
"Philippe Mathieu-Daudé" <f4bug@amsat.org>,
"Wainer dos Santos Moschetta" <wainersm@redhat.com>,
"Andrea Bolognani" <abologna@redhat.com>,
"Willian Rampazzo" <willianr@redhat.com>,
"John Snow" <jsnow@redhat.com>,
"Willian Rampazzo" <wrampazz@redhat.com>,
"Stefan Hajnoczi" <stefanha@gmail.com>,
"Max Reitz" <mreitz@redhat.com>,
"Alex Bennée" <alex.bennee@linaro.org>,
"Beraldo Leal" <bleal@redhat.com>
Subject: [PATCH 2/4] Python QEMU utils: introduce a generic feature list
Date: Tue, 8 Jun 2021 10:09:36 -0400 [thread overview]
Message-ID: <20210608140938.863580-3-crosa@redhat.com> (raw)
In-Reply-To: <20210608140938.863580-1-crosa@redhat.com>
Which can be used to check for any "feature" that is available as a
QEMU command line option, and that will return its list of available
options.
This is a generalization of the list_accel() utility function, which
is itself re-implemented in terms of the more generic feature.
Signed-off-by: Cleber Rosa <crosa@redhat.com>
---
python/qemu/utils/__init__.py | 2 ++
python/qemu/utils/accel.py | 15 ++----------
python/qemu/utils/feature.py | 44 +++++++++++++++++++++++++++++++++++
3 files changed, 48 insertions(+), 13 deletions(-)
create mode 100644 python/qemu/utils/feature.py
diff --git a/python/qemu/utils/__init__.py b/python/qemu/utils/__init__.py
index 7f1a5138c4..1d0789eaa2 100644
--- a/python/qemu/utils/__init__.py
+++ b/python/qemu/utils/__init__.py
@@ -20,12 +20,14 @@
# pylint: disable=import-error
from .accel import kvm_available, list_accel, tcg_available
+from .feature import list_feature
__all__ = (
'get_info_usernet_hostfwd_port',
'kvm_available',
'list_accel',
+ 'list_feature',
'tcg_available',
)
diff --git a/python/qemu/utils/accel.py b/python/qemu/utils/accel.py
index 297933df2a..b5bb80c6d3 100644
--- a/python/qemu/utils/accel.py
+++ b/python/qemu/utils/accel.py
@@ -14,13 +14,11 @@
# the COPYING file in the top-level directory.
#
-import logging
import os
-import subprocess
from typing import List, Optional
+from qemu.utils.feature import list_feature
-LOG = logging.getLogger(__name__)
# Mapping host architecture to any additional architectures it can
# support which often includes its 32 bit cousin.
@@ -39,16 +37,7 @@ def list_accel(qemu_bin: str) -> List[str]:
@raise Exception: if failed to run `qemu -accel help`
@return a list of accelerator names.
"""
- if not qemu_bin:
- return []
- try:
- out = subprocess.check_output([qemu_bin, '-accel', 'help'],
- universal_newlines=True)
- except:
- LOG.debug("Failed to get the list of accelerators in %s", qemu_bin)
- raise
- # Skip the first line which is the header.
- return [acc.strip() for acc in out.splitlines()[1:]]
+ return list_feature(qemu_bin, 'accel')
def kvm_available(target_arch: Optional[str] = None,
diff --git a/python/qemu/utils/feature.py b/python/qemu/utils/feature.py
new file mode 100644
index 0000000000..b4a5f929ab
--- /dev/null
+++ b/python/qemu/utils/feature.py
@@ -0,0 +1,44 @@
+"""
+QEMU feature module:
+
+This module provides a utility for discovering the availability of
+generic features.
+"""
+# Copyright (C) 2022 Red Hat Inc.
+#
+# Authors:
+# Cleber Rosa <crosa@redhat.com>
+#
+# This work is licensed under the terms of the GNU GPL, version 2. See
+# the COPYING file in the top-level directory.
+#
+
+import logging
+import subprocess
+from typing import List
+
+
+LOG = logging.getLogger(__name__)
+
+
+def list_feature(qemu_bin: str, feature: str) -> List[str]:
+ """
+ List available options the QEMU binary for a given feature type.
+
+ By calling a "qemu $feature -help" and parsing its output.
+
+ @param qemu_bin (str): path to the QEMU binary.
+ @param feature (str): feature name, matching the command line option.
+ @raise Exception: if failed to run `qemu -feature help`
+ @return a list of available options for the given feature.
+ """
+ if not qemu_bin:
+ return []
+ try:
+ out = subprocess.check_output([qemu_bin, '-%s' % feature, 'help'],
+ universal_newlines=True)
+ except:
+ LOG.debug("Failed to get the list of %s(s) in %s", feature, qemu_bin)
+ raise
+ # Skip the first line which is the header.
+ return [item.split(' ', 1)[0] for item in out.splitlines()[1:]]
--
2.25.4
next prev parent reply other threads:[~2021-06-08 14:13 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-08 14:09 [PATCH 0/4] Jobs based on custom runners: add CentOS Stream 8 Cleber Rosa
2021-06-08 14:09 ` [PATCH 1/4] block.c: fix compilation error on possible unitialized variable Cleber Rosa
2021-06-09 7:08 ` Thomas Huth
2021-06-08 14:09 ` Cleber Rosa [this message]
2021-06-08 21:42 ` [PATCH 2/4] Python QEMU utils: introduce a generic feature list Wainer dos Santos Moschetta
2021-06-08 23:55 ` Cleber Rosa Junior
2021-06-10 19:39 ` Willian Rampazzo
2021-06-10 20:31 ` Wainer dos Santos Moschetta
2021-06-10 19:48 ` Willian Rampazzo
2021-06-22 15:43 ` John Snow
2021-06-08 14:09 ` [PATCH 3/4] Acceptance Tests: introduce method to require a feature and option Cleber Rosa
2021-06-10 19:46 ` Willian Rampazzo
2021-06-08 14:09 ` [PATCH 4/4] Jobs based on custom runners: add CentOS Stream 8 Cleber Rosa
2021-06-09 20:37 ` Cleber Rosa Junior
2021-06-10 19:27 ` Willian Rampazzo
2021-06-10 18:40 ` [PATCH 0/4] " Willian Rampazzo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210608140938.863580-3-crosa@redhat.com \
--to=crosa@redhat.com \
--cc=abologna@redhat.com \
--cc=alex.bennee@linaro.org \
--cc=bleal@redhat.com \
--cc=ehabkost@redhat.com \
--cc=eskultet@redhat.com \
--cc=f4bug@amsat.org \
--cc=fam@euphon.net \
--cc=jsnow@redhat.com \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=philmd@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@gmail.com \
--cc=thuth@redhat.com \
--cc=wainersm@redhat.com \
--cc=willianr@redhat.com \
--cc=wrampazz@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).