From: Cleber Rosa <crosa@redhat.com>
To: Peter Maydell <peter.maydell@linaro.org>, qemu-devel@nongnu.org
Cc: "Eduardo Habkost" <ehabkost@redhat.com>,
"Fam Zheng" <fam@euphon.net>,
qemu-block@nongnu.org, "Kevin Wolf" <kwolf@redhat.com>,
"Max Reitz" <mreitz@redhat.com>,
"Philippe Mathieu-Daudé" <philmd@redhat.com>,
"Alex Bennée" <alex.bennee@linaro.org>,
"Cleber Rosa" <crosa@redhat.com>,
"Markus Armbruster" <armbru@redhat.com>,
"Caio Carrara" <ccarrara@redhat.com>,
"Stefan Hajnoczi" <stefanha@redhat.com>
Subject: [Qemu-devel] [PULL 2/7] Introduce a Python module structure
Date: Fri, 22 Feb 2019 14:41:41 -0500 [thread overview]
Message-ID: <20190222194146.13102-3-crosa@redhat.com> (raw)
In-Reply-To: <20190222194146.13102-1-crosa@redhat.com>
This is a simple move of Python code that wraps common QEMU
functionality, and are used by a number of different tests
and scripts.
By treating that code as a real Python module, we can more easily:
* reuse code
* have a proper place for the module's own unittests
* apply a more consistent style
* generate documentation
Signed-off-by: Cleber Rosa <crosa@redhat.com>
Reviewed-by: Caio Carrara <ccarrara@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Message-Id: <20190206162901.19082-2-crosa@redhat.com>
Signed-off-by: Cleber Rosa <crosa@redhat.com>
---
configure | 1 +
scripts/qemu.py => python/qemu/__init__.py | 11 ++++++-----
{scripts/qmp => python/qemu}/qmp.py | 0
{scripts => python/qemu}/qtest.py | 5 +++--
scripts/device-crash-test | 2 ++
scripts/qmp/__init__.py | 0
scripts/qmp/qemu-ga-client | 5 ++++-
scripts/qmp/qmp-shell | 4 +++-
scripts/render_block_graph.py | 2 ++
tests/acceptance/avocado_qemu/__init__.py | 5 ++---
tests/acceptance/virtio_version.py | 2 +-
tests/migration/guestperf/engine.py | 7 ++++---
tests/qemu-iotests/235 | 2 +-
tests/qemu-iotests/238 | 2 +-
tests/qemu-iotests/iotests.py | 4 ++--
tests/vm/basevm.py | 2 +-
16 files changed, 33 insertions(+), 21 deletions(-)
rename scripts/qemu.py => python/qemu/__init__.py (98%)
rename {scripts/qmp => python/qemu}/qmp.py (100%)
rename {scripts => python/qemu}/qtest.py (98%)
delete mode 100644 scripts/qmp/__init__.py
diff --git a/configure b/configure
index a61682c3c7..343dd004e9 100755
--- a/configure
+++ b/configure
@@ -7604,6 +7604,7 @@ LINKS="$LINKS pc-bios/qemu-icon.bmp"
LINKS="$LINKS .gdbinit scripts" # scripts needed by relative path in .gdbinit
LINKS="$LINKS tests/acceptance tests/data"
LINKS="$LINKS tests/qemu-iotests/check"
+LINKS="$LINKS python"
for bios_file in \
$source_path/pc-bios/*.bin \
$source_path/pc-bios/*.lid \
diff --git a/scripts/qemu.py b/python/qemu/__init__.py
similarity index 98%
rename from scripts/qemu.py
rename to python/qemu/__init__.py
index 32b00af5cc..38de3e9177 100644
--- a/scripts/qemu.py
+++ b/python/qemu/__init__.py
@@ -16,12 +16,13 @@ import errno
import logging
import os
import subprocess
-import qmp.qmp
import re
import shutil
import socket
import tempfile
+from . import qmp
+
LOG = logging.getLogger(__name__)
@@ -66,7 +67,7 @@ class QEMUMachineAddDeviceError(QEMUMachineError):
failures reported by the QEMU binary itself.
"""
-class MonitorResponseError(qmp.qmp.QMPError):
+class MonitorResponseError(qmp.QMPError):
"""
Represents erroneous QMP monitor reply
"""
@@ -267,8 +268,8 @@ class QEMUMachine(object):
self._qemu_log_path = os.path.join(self._temp_dir, self._name + ".log")
self._qemu_log_file = open(self._qemu_log_path, 'wb')
- self._qmp = qmp.qmp.QEMUMonitorProtocol(self._vm_monitor,
- server=True)
+ self._qmp = qmp.QEMUMonitorProtocol(self._vm_monitor,
+ server=True)
def _post_launch(self):
self._qmp.accept()
@@ -384,7 +385,7 @@ class QEMUMachine(object):
"""
reply = self.qmp(cmd, conv_keys, **args)
if reply is None:
- raise qmp.qmp.QMPError("Monitor is closed")
+ raise qmp.QMPError("Monitor is closed")
if "error" in reply:
raise MonitorResponseError(reply)
return reply["return"]
diff --git a/scripts/qmp/qmp.py b/python/qemu/qmp.py
similarity index 100%
rename from scripts/qmp/qmp.py
rename to python/qemu/qmp.py
diff --git a/scripts/qtest.py b/python/qemu/qtest.py
similarity index 98%
rename from scripts/qtest.py
rename to python/qemu/qtest.py
index afac3fe900..eb45824dd0 100644
--- a/scripts/qtest.py
+++ b/python/qemu/qtest.py
@@ -13,7 +13,8 @@
import socket
import os
-import qemu
+
+from . import QEMUMachine
class QEMUQtestProtocol(object):
@@ -79,7 +80,7 @@ class QEMUQtestProtocol(object):
self._sock.settimeout(timeout)
-class QEMUQtestMachine(qemu.QEMUMachine):
+class QEMUQtestMachine(QEMUMachine):
'''A QEMU VM'''
def __init__(self, binary, args=None, name=None, test_dir="/var/tmp",
diff --git a/scripts/device-crash-test b/scripts/device-crash-test
index 2a13fa4f84..a6748910ad 100755
--- a/scripts/device-crash-test
+++ b/scripts/device-crash-test
@@ -25,6 +25,7 @@ check for crashes and unexpected errors.
"""
from __future__ import print_function
+import os
import sys
import glob
import logging
@@ -34,6 +35,7 @@ import random
import argparse
from itertools import chain
+sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'python'))
from qemu import QEMUMachine
logger = logging.getLogger('device-crash-test')
diff --git a/scripts/qmp/__init__.py b/scripts/qmp/__init__.py
deleted file mode 100644
index e69de29bb2..0000000000
diff --git a/scripts/qmp/qemu-ga-client b/scripts/qmp/qemu-ga-client
index e8cb7646a0..30cf8a9a0d 100755
--- a/scripts/qmp/qemu-ga-client
+++ b/scripts/qmp/qemu-ga-client
@@ -37,10 +37,13 @@
#
from __future__ import print_function
+import os
+import sys
import base64
import random
-import qmp
+sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'python'))
+from qemu import qmp
class QemuGuestAgent(qmp.QEMUMonitorProtocol):
diff --git a/scripts/qmp/qmp-shell b/scripts/qmp/qmp-shell
index 770140772d..9fec46e2ed 100755
--- a/scripts/qmp/qmp-shell
+++ b/scripts/qmp/qmp-shell
@@ -66,7 +66,6 @@
# sent to QEMU, which is useful for debugging and documentation generation.
from __future__ import print_function
-import qmp
import json
import ast
import readline
@@ -76,6 +75,9 @@ import errno
import atexit
import shlex
+sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'python'))
+from qemu import qmp
+
class QMPCompleter(list):
def complete(self, text, state):
for cmd in self:
diff --git a/scripts/render_block_graph.py b/scripts/render_block_graph.py
index ed7e581b4f..3e9d282a49 100755
--- a/scripts/render_block_graph.py
+++ b/scripts/render_block_graph.py
@@ -23,6 +23,8 @@ import sys
import subprocess
import json
from graphviz import Digraph
+
+sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'python'))
from qemu import MonitorResponseError
diff --git a/tests/acceptance/avocado_qemu/__init__.py b/tests/acceptance/avocado_qemu/__init__.py
index 1e54fd5932..28bfb8e9d3 100644
--- a/tests/acceptance/avocado_qemu/__init__.py
+++ b/tests/acceptance/avocado_qemu/__init__.py
@@ -13,9 +13,8 @@ import sys
import avocado
-SRC_ROOT_DIR = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
-SRC_ROOT_DIR = os.path.abspath(os.path.dirname(SRC_ROOT_DIR))
-sys.path.append(os.path.join(SRC_ROOT_DIR, 'scripts'))
+SRC_ROOT_DIR = os.path.join(os.path.dirname(__file__), '..', '..', '..')
+sys.path.append(os.path.join(SRC_ROOT_DIR, 'python'))
from qemu import QEMUMachine
diff --git a/tests/acceptance/virtio_version.py b/tests/acceptance/virtio_version.py
index 464d75aa4e..37fc01ea18 100644
--- a/tests/acceptance/virtio_version.py
+++ b/tests/acceptance/virtio_version.py
@@ -11,7 +11,7 @@ Check compatibility of virtio device types
import sys
import os
-sys.path.append(os.path.join(os.path.dirname(__file__), "..", "..", "scripts"))
+sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'python'))
from qemu import QEMUMachine
from avocado_qemu import Test
diff --git a/tests/migration/guestperf/engine.py b/tests/migration/guestperf/engine.py
index 398e3f2706..0e304660b8 100644
--- a/tests/migration/guestperf/engine.py
+++ b/tests/migration/guestperf/engine.py
@@ -24,13 +24,14 @@ import re
import sys
import time
-sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', '..', 'scripts'))
-import qemu
-import qmp.qmp
from guestperf.progress import Progress, ProgressStats
from guestperf.report import Report
from guestperf.timings import TimingRecord, Timings
+sys.path.append(os.path.join(os.path.dirname(__file__),
+ '..', '..', '..', 'python'))
+import qemu
+
class Engine(object):
diff --git a/tests/qemu-iotests/235 b/tests/qemu-iotests/235
index d6edd97ab4..75c203b30c 100755
--- a/tests/qemu-iotests/235
+++ b/tests/qemu-iotests/235
@@ -23,7 +23,7 @@ import os
import iotests
from iotests import qemu_img_create, qemu_io, file_path, log
-sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'scripts'))
+sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'python'))
from qemu import QEMUMachine
diff --git a/tests/qemu-iotests/238 b/tests/qemu-iotests/238
index f81ee1112f..688abc9acb 100755
--- a/tests/qemu-iotests/238
+++ b/tests/qemu-iotests/238
@@ -23,7 +23,7 @@ import os
import iotests
from iotests import log
-sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'scripts'))
+sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'python'))
from qemu import QEMUMachine
diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
index b461f53abf..54a31044b4 100644
--- a/tests/qemu-iotests/iotests.py
+++ b/tests/qemu-iotests/iotests.py
@@ -32,8 +32,8 @@ import atexit
import io
from collections import OrderedDict
-sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'scripts'))
-import qtest
+sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'python'))
+from qemu import qtest
# This will not work if arguments contain spaces but is necessary if we
diff --git a/tests/vm/basevm.py b/tests/vm/basevm.py
index bdca6cb2fc..0556bdcf9e 100755
--- a/tests/vm/basevm.py
+++ b/tests/vm/basevm.py
@@ -17,7 +17,7 @@ import sys
import logging
import time
import datetime
-sys.path.append(os.path.join(os.path.dirname(__file__), "..", "..", "scripts"))
+sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'python'))
from qemu import QEMUMachine, kvm_available
import subprocess
import hashlib
--
2.20.1
next prev parent reply other threads:[~2019-02-22 19:42 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-22 19:41 [Qemu-devel] [PULL 0/7] Python queue, 2019-02-22 Cleber Rosa
2019-02-22 19:41 ` [Qemu-devel] [PULL 1/7] Acceptance tests: drop usage of ":avocado: enable" Cleber Rosa
2019-02-22 19:41 ` Cleber Rosa [this message]
2019-02-22 19:41 ` [Qemu-devel] [PULL 3/7] scripts/qemu.py: log QEMU launch command line Cleber Rosa
2019-02-22 19:41 ` [Qemu-devel] [PULL 4/7] tests.acceptance: adds multi vm capability for acceptance tests Cleber Rosa
2019-02-22 19:41 ` [Qemu-devel] [PULL 5/7] tests.acceptance: adds simple migration test Cleber Rosa
2020-11-03 10:40 ` Philippe Mathieu-Daudé
2020-11-03 15:27 ` Cleber Rosa
2020-11-03 18:10 ` Philippe Mathieu-Daudé
2019-02-22 19:41 ` [Qemu-devel] [PULL 6/7] Acceptance tests: use linux-3.6 and set vm memory to 4GiB Cleber Rosa
2019-02-22 19:41 ` [Qemu-devel] [PULL 7/7] Acceptance tests: expect boot to extract 2GiB+ initrd with linux-v4.16 Cleber Rosa
2019-03-01 14:38 ` [Qemu-devel] [PULL 0/7] Python queue, 2019-02-22 Peter Maydell
2019-03-06 20:34 ` Cleber Rosa
2019-03-07 16:58 ` Peter Maydell
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=20190222194146.13102-3-crosa@redhat.com \
--to=crosa@redhat.com \
--cc=alex.bennee@linaro.org \
--cc=armbru@redhat.com \
--cc=ccarrara@redhat.com \
--cc=ehabkost@redhat.com \
--cc=fam@euphon.net \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=philmd@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@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 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.