]> git.ipfire.org Git - thirdparty/qemu.git/commitdiff
python: create qemu packages
authorJohn Snow <jsnow@redhat.com>
Thu, 27 May 2021 21:16:53 +0000 (17:16 -0400)
committerJohn Snow <jsnow@redhat.com>
Tue, 1 Jun 2021 20:21:21 +0000 (16:21 -0400)
move python/qemu/*.py to python/qemu/[machine, qmp, utils]/*.py and
update import directives across the tree.

This is done to create a PEP420 namespace package, in which we may
create subpackages. To do this, the namespace directory ("qemu") should
not have any modules in it. Those files will go into new 'machine',
'qmp' and 'utils' subpackages instead.

Implement machine/__init__.py making the top-level classes and functions
from its various modules available directly inside the package. Change
qmp.py to qmp/__init__.py similarly, such that all of the useful QMP
library classes are available directly from "qemu.qmp" instead of
"qemu.qmp.qmp".

Signed-off-by: John Snow <jsnow@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Cleber Rosa <crosa@redhat.com>
Message-id: 20210527211715.394144-10-jsnow@redhat.com
Signed-off-by: John Snow <jsnow@redhat.com>
17 files changed:
python/.isort.cfg [moved from python/qemu/.isort.cfg with 100% similarity]
python/qemu/__init__.py [deleted file]
python/qemu/machine/.flake8 [moved from python/qemu/.flake8 with 100% similarity]
python/qemu/machine/__init__.py [new file with mode: 0644]
python/qemu/machine/console_socket.py [moved from python/qemu/console_socket.py with 100% similarity]
python/qemu/machine/machine.py [moved from python/qemu/machine.py with 98% similarity]
python/qemu/machine/pylintrc [moved from python/qemu/pylintrc with 100% similarity]
python/qemu/machine/qtest.py [moved from python/qemu/qtest.py with 99% similarity]
python/qemu/qmp/__init__.py [moved from python/qemu/qmp.py with 96% similarity]
python/qemu/utils/__init__.py [moved from python/qemu/utils.py with 66% similarity]
python/qemu/utils/accel.py [moved from python/qemu/accel.py with 100% similarity]
tests/acceptance/avocado_qemu/__init__.py
tests/acceptance/virtio-gpu.py
tests/qemu-iotests/300
tests/qemu-iotests/iotests.py
tests/vm/aarch64vm.py
tests/vm/basevm.py

similarity index 100%
rename from python/qemu/.isort.cfg
rename to python/.isort.cfg
diff --git a/python/qemu/__init__.py b/python/qemu/__init__.py
deleted file mode 100644 (file)
index 4ca06c3..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-# QEMU library
-#
-# Copyright (C) 2015-2016 Red Hat Inc.
-# Copyright (C) 2012 IBM Corp.
-#
-# Authors:
-#  Fam Zheng <famz@redhat.com>
-#
-# This work is licensed under the terms of the GNU GPL, version 2.  See
-# the COPYING file in the top-level directory.
-#
diff --git a/python/qemu/machine/__init__.py b/python/qemu/machine/__init__.py
new file mode 100644 (file)
index 0000000..98302ea
--- /dev/null
@@ -0,0 +1,33 @@
+"""
+QEMU development and testing library.
+
+This library provides a few high-level classes for driving QEMU from a
+test suite, not intended for production use.
+
+- QEMUMachine: Configure and Boot a QEMU VM
+ - QEMUQtestMachine: VM class, with a qtest socket.
+
+- QEMUQtestProtocol: Connect to, send/receive qtest messages.
+"""
+
+# Copyright (C) 2020-2021 John Snow for Red Hat Inc.
+# Copyright (C) 2015-2016 Red Hat Inc.
+# Copyright (C) 2012 IBM Corp.
+#
+# Authors:
+#  John Snow <jsnow@redhat.com>
+#  Fam Zheng <fam@euphon.net>
+#
+# This work is licensed under the terms of the GNU GPL, version 2.  See
+# the COPYING file in the top-level directory.
+#
+
+from .machine import QEMUMachine
+from .qtest import QEMUQtestMachine, QEMUQtestProtocol
+
+
+__all__ = (
+    'QEMUMachine',
+    'QEMUQtestProtocol',
+    'QEMUQtestMachine',
+)
similarity index 98%
rename from python/qemu/machine.py
rename to python/qemu/machine/machine.py
index a8837b36e47680c292ec906a1d4a36b88d32b7cf..d33b02d2ce6c98eb6dbe85c07cd08051eafcf4e1 100644 (file)
@@ -38,8 +38,14 @@ from typing import (
     Type,
 )
 
-from . import console_socket, qmp
-from .qmp import QMPMessage, QMPReturnValue, SocketAddrT
+from qemu.qmp import (
+    QEMUMonitorProtocol,
+    QMPMessage,
+    QMPReturnValue,
+    SocketAddrT,
+)
+
+from . import console_socket
 
 
 LOG = logging.getLogger(__name__)
@@ -139,7 +145,7 @@ class QEMUMachine:
         self._events: List[QMPMessage] = []
         self._iolog: Optional[str] = None
         self._qmp_set = True   # Enable QMP monitor by default.
-        self._qmp_connection: Optional[qmp.QEMUMonitorProtocol] = None
+        self._qmp_connection: Optional[QEMUMonitorProtocol] = None
         self._qemu_full_args: Tuple[str, ...] = ()
         self._temp_dir: Optional[str] = None
         self._launched = False
@@ -314,7 +320,7 @@ class QEMUMachine:
             if self._remove_monitor_sockfile:
                 assert isinstance(self._monitor_address, str)
                 self._remove_files.append(self._monitor_address)
-            self._qmp_connection = qmp.QEMUMonitorProtocol(
+            self._qmp_connection = QEMUMonitorProtocol(
                 self._monitor_address,
                 server=True,
                 nickname=self._name
@@ -541,7 +547,7 @@ class QEMUMachine:
         self._qmp_set = enabled
 
     @property
-    def _qmp(self) -> qmp.QEMUMonitorProtocol:
+    def _qmp(self) -> QEMUMonitorProtocol:
         if self._qmp_connection is None:
             raise QEMUMachineError("Attempt to access QMP with no connection")
         return self._qmp_connection
similarity index 99%
rename from python/qemu/qtest.py
rename to python/qemu/machine/qtest.py
index 78b97d13cf0a164ab89a72e80242035c14fa3e54..e893ca3697af0cfe16068892cacc858210ff4335 100644 (file)
@@ -26,8 +26,9 @@ from typing import (
     TextIO,
 )
 
+from qemu.qmp import SocketAddrT
+
 from .machine import QEMUMachine
-from .qmp import SocketAddrT
 
 
 class QEMUQtestProtocol:
similarity index 96%
rename from python/qemu/qmp.py
rename to python/qemu/qmp/__init__.py
index 2cd4d43036c5e582b03057d029d801a4f2665b1f..9606248a3d2ebe6cd5de397ab7c7a0908f8e2ff3 100644 (file)
@@ -1,4 +1,14 @@
-""" QEMU Monitor Protocol Python class """
+"""
+QEMU Monitor Protocol (QMP) development library & tooling.
+
+This package provides a fairly low-level class for communicating to QMP
+protocol servers, as implemented by QEMU, the QEMU Guest Agent, and the
+QEMU Storage Daemon. This library is not intended for production use.
+
+`QEMUMonitorProtocol` is the primary class of interest, and all errors
+raised derive from `QMPError`.
+"""
+
 # Copyright (C) 2009, 2010 Red Hat Inc.
 #
 # Authors:
similarity index 66%
rename from python/qemu/utils.py
rename to python/qemu/utils/__init__.py
index 5ed789275ee4da82a61bda3e8f7d527c7dc6a111..7f1a5138c4bd3a8c1d4fbe9a011cfdffc4f94b57 100644 (file)
@@ -1,13 +1,14 @@
 """
-QEMU utility library
+QEMU development and testing utilities
 
-This offers miscellaneous utility functions, which may not be easily
-distinguishable or numerous to be in their own module.
+This package provides a small handful of utilities for performing
+various tasks not directly related to the launching of a VM.
 """
 
 # Copyright (C) 2021 Red Hat Inc.
 #
 # Authors:
+#  John Snow <jsnow@redhat.com>
 #  Cleber Rosa <crosa@redhat.com>
 #
 # This work is licensed under the terms of the GNU GPL, version 2.  See
@@ -17,6 +18,17 @@ distinguishable or numerous to be in their own module.
 import re
 from typing import Optional
 
+# pylint: disable=import-error
+from .accel import kvm_available, list_accel, tcg_available
+
+
+__all__ = (
+    'get_info_usernet_hostfwd_port',
+    'kvm_available',
+    'list_accel',
+    'tcg_available',
+)
+
 
 def get_info_usernet_hostfwd_port(info_usernet_output: str) -> Optional[int]:
     """
index 1062a851b97059b23ce530cf37d0670e97b53339..93c4b9851f49a0fd2d758584ff034b1fa4c8a1be 100644 (file)
@@ -41,11 +41,12 @@ else:
 
 sys.path.append(os.path.join(SOURCE_DIR, 'python'))
 
-from qemu.accel import kvm_available
-from qemu.accel import tcg_available
 from qemu.machine import QEMUMachine
-from qemu.utils import get_info_usernet_hostfwd_port
-
+from qemu.utils import (
+    get_info_usernet_hostfwd_port,
+    kvm_available,
+    tcg_available,
+)
 
 def is_readable_executable_file(path):
     return os.path.isfile(path) and os.access(path, os.R_OK | os.X_OK)
index ab18cddbb735a7ab809d55e07ef7cbcc362736b4..e7979343e932d1f6c26b638314b89ba410e95693 100644 (file)
@@ -10,7 +10,7 @@ from avocado_qemu import wait_for_console_pattern
 from avocado_qemu import exec_command_and_wait_for_pattern
 from avocado_qemu import is_readable_executable_file
 
-from qemu.accel import kvm_available
+from qemu.utils import kvm_available
 
 import os
 import socket
index b475a92c4782628c4e9a7e0ae47210965f4f2d44..fe94de84edd94cd6f926f52312fd1d160aedbfad 100755 (executable)
@@ -28,7 +28,7 @@ import iotests
 
 # Import qemu after iotests.py has amended sys.path
 # pylint: disable=wrong-import-order
-import qemu
+from qemu.machine import machine
 
 BlockBitmapMapping = List[Dict[str, object]]
 
@@ -466,7 +466,7 @@ class TestBlockBitmapMappingErrors(TestDirtyBitmapMigration):
         # the failed migration
         try:
             self.vm_b.shutdown()
-        except qemu.machine.AbnormalShutdown:
+        except machine.AbnormalShutdown:
             pass
 
     def test_aliased_bitmap_name_too_long(self) -> None:
index 92681907ed9c70b8ce6a162aa78c8cfb93ca7a8f..89663dac06d288e79d20465f963205b46692bad9 100644 (file)
@@ -38,7 +38,7 @@ from contextlib import contextmanager
 
 # pylint: disable=import-error, wrong-import-position
 sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'python'))
-from qemu import qtest
+from qemu.machine import qtest
 from qemu.qmp import QMPMessage
 
 # Use this logger for logging messages directly from the iotests module
index d70ab843b6b8dabe1901cde508130f044be78d18..b00cce07eb819c8530b7a9cfc488b26d29c70c3e 100644 (file)
@@ -14,7 +14,7 @@ import os
 import sys
 import subprocess
 import basevm
-from qemu.accel import kvm_available
+from qemu.utils import kvm_available
 
 # This is the config needed for current version of QEMU.
 # This works for both kvm and tcg.
index 995e642465b9dad39eb611d2a2a5dd83f84b757e..0f2e436ed33a3812e8df6d85a7475b97c0cc63e3 100644 (file)
@@ -19,9 +19,8 @@ import logging
 import time
 import datetime
 sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'python'))
-from qemu.accel import kvm_available
 from qemu.machine import QEMUMachine
-from qemu.utils import get_info_usernet_hostfwd_port
+from qemu.utils import get_info_usernet_hostfwd_port, kvm_available
 import subprocess
 import hashlib
 import argparse