]> git.ipfire.org Git - thirdparty/qemu.git/commitdiff
Introduce a Python module structure
authorCleber Rosa <crosa@redhat.com>
Wed, 6 Feb 2019 16:29:01 +0000 (11:29 -0500)
committerCleber Rosa <crosa@redhat.com>
Fri, 22 Feb 2019 19:07:01 +0000 (14:07 -0500)
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>
16 files changed:
configure
python/qemu/__init__.py [moved from scripts/qemu.py with 98% similarity]
python/qemu/qmp.py [moved from scripts/qmp/qmp.py with 100% similarity]
python/qemu/qtest.py [moved from scripts/qtest.py with 98% similarity]
scripts/device-crash-test
scripts/qmp/__init__.py [deleted file]
scripts/qmp/qemu-ga-client
scripts/qmp/qmp-shell
scripts/render_block_graph.py
tests/acceptance/avocado_qemu/__init__.py
tests/acceptance/virtio_version.py
tests/migration/guestperf/engine.py
tests/qemu-iotests/235
tests/qemu-iotests/238
tests/qemu-iotests/iotests.py
tests/vm/basevm.py

index a61682c3c727f467ce2710c7469a33b261da8ff6..343dd004e9d9c065fdb0b5ea39c8998df8561f66 100755 (executable)
--- 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 \
similarity index 98%
rename from scripts/qemu.py
rename to python/qemu/__init__.py
index 32b00af5cca7eb564fa44341fcd758f1a0a0cfd5..38de3e9177e927787a5f2fdad638d4bfbe7d7f71 100644 (file)
@@ -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"]
similarity index 100%
rename from scripts/qmp/qmp.py
rename to python/qemu/qmp.py
similarity index 98%
rename from scripts/qtest.py
rename to python/qemu/qtest.py
index afac3fe900ab5b443ccb618907f3d45cf0dfdf39..eb45824dd0bd91908d9f861838a666f34e424ef2 100644 (file)
@@ -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",
index 2a13fa4f848fb6c04e90bdecb23bb8a1374c60dc..a6748910ad2eb0afa94acab4e0cf27212a3f6c7d 100755 (executable)
@@ -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 (file)
index e69de29..0000000
index e8cb7646a0be1127c6fecaa41085448ae787156a..30cf8a9a0da6a436bf3ab52c3ffcbaa932ded79c 100755 (executable)
 #
 
 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):
index 770140772d07b90d8a03d54a6d570d269002cb07..9fec46e2ed0d98cf158c50bc2fda251999f9a90a 100755 (executable)
@@ -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:
index ed7e581b4f4ecaad49c42054a66760246ae5ccdd..3e9d282a49bd2a13fa4571e05c70d2c1c0fb1a3f 100755 (executable)
@@ -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
 
 
index 1e54fd59329895ef41ccdc02765b3bab6cd43adf..28bfb8e9d3226834889d2fa5577df18b4b703c9e 100644 (file)
@@ -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
 
index 464d75aa4e5a5c1e41df01740d8aad8fb830c297..37fc01ea187c708b8126d6c78edb05295bf9998f 100644 (file)
@@ -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
 
index 398e3f27066551bc231276eb6c38dc23390c3abb..0e304660b864057adac92e9ae1d07a330850a13e 100644 (file)
@@ -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):
 
index d6edd97ab4f47a4711e22e211fd87cc962aca94c..75c203b30c7dfe07e8a8e473db6faddced3ce547 100755 (executable)
@@ -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
 
index f81ee1112f7a08dfb5550150bc2a5489f04d77e2..688abc9acb44ba267f30399e6541d91adf7cd3c9 100755 (executable)
@@ -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
 
index b461f53abf8727085772bdd066bd042c62fabdc2..54a31044b427cf5be2256acd1baae49aa0337af6 100644 (file)
@@ -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
index bdca6cb2fc5677cea3c37cd9f2ec30a07f17d178..0556bdcf9e9ffb12cdcf59ff968cee14906d84a3 100755 (executable)
@@ -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