[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 01/44] Python: expose QEMUMachine's temporary directory
From: |
John Snow |
Subject: |
[PULL 01/44] Python: expose QEMUMachine's temporary directory |
Date: |
Thu, 27 May 2021 22:31:37 -0400 |
From: Cleber Rosa <crosa@redhat.com>
Each instance of qemu.machine.QEMUMachine currently has a "test
directory", which may not have any relation to a "test", and it's
really a temporary directory.
Users instantiating the QEMUMachine class will be able to set the
location of the directory that will *contain* the QEMUMachine unique
temporary directory, so that parameter name has been changed from
test_dir to base_temp_dir.
A property has been added to allow users to access it without using
private attributes, and with that, the directory is created on first
use of the property.
Signed-off-by: Cleber Rosa <crosa@redhat.com>
Message-Id: <20210211220146.2525771-3-crosa@redhat.com>
Reviewed-by: Wainer dos Santos Moschetta <wainersm@redhat.com>
Signed-off-by: Cleber Rosa <crosa@redhat.com>
Signed-off-by: John Snow <jsnow@redhat.com>
---
python/qemu/machine.py | 24 ++++++++++++++++--------
python/qemu/qtest.py | 6 +++---
tests/qemu-iotests/iotests.py | 2 +-
3 files changed, 20 insertions(+), 12 deletions(-)
diff --git a/python/qemu/machine.py b/python/qemu/machine.py
index 6e44bda337e..b379fcbe726 100644
--- a/python/qemu/machine.py
+++ b/python/qemu/machine.py
@@ -84,7 +84,7 @@ def __init__(self,
args: Sequence[str] = (),
wrapper: Sequence[str] = (),
name: Optional[str] = None,
- test_dir: str = "/var/tmp",
+ base_temp_dir: str = "/var/tmp",
monitor_address: Optional[SocketAddrT] = None,
socket_scm_helper: Optional[str] = None,
sock_dir: Optional[str] = None,
@@ -97,10 +97,10 @@ def __init__(self,
@param args: list of extra arguments
@param wrapper: list of arguments used as prefix to qemu binary
@param name: prefix for socket and log file names (default: qemu-PID)
- @param test_dir: where to create socket and log file
+ @param base_temp_dir: default location where temporary files are
created
@param monitor_address: address for QMP monitor
@param socket_scm_helper: helper program, required for send_fd_scm()
- @param sock_dir: where to create socket (overrides test_dir for sock)
+ @param sock_dir: where to create socket (defaults to base_temp_dir)
@param drain_console: (optional) True to drain console socket to buffer
@param console_log: (optional) path to console log file
@note: Qemu process is not started until launch() is used.
@@ -112,8 +112,8 @@ def __init__(self,
self._wrapper = wrapper
self._name = name or "qemu-%d" % os.getpid()
- self._test_dir = test_dir
- self._sock_dir = sock_dir or self._test_dir
+ self._base_temp_dir = base_temp_dir
+ self._sock_dir = sock_dir or self._base_temp_dir
self._socket_scm_helper = socket_scm_helper
if monitor_address is not None:
@@ -303,9 +303,7 @@ def _base_args(self) -> List[str]:
return args
def _pre_launch(self) -> None:
- self._temp_dir = tempfile.mkdtemp(prefix="qemu-machine-",
- dir=self._test_dir)
- self._qemu_log_path = os.path.join(self._temp_dir, self._name + ".log")
+ self._qemu_log_path = os.path.join(self.temp_dir, self._name + ".log")
self._qemu_log_file = open(self._qemu_log_path, 'wb')
if self._console_set:
@@ -744,3 +742,13 @@ def console_socket(self) -> socket.socket:
file=self._console_log_path,
drain=self._drain_console)
return self._console_socket
+
+ @property
+ def temp_dir(self) -> str:
+ """
+ Returns a temporary directory to be used for this machine
+ """
+ if self._temp_dir is None:
+ self._temp_dir = tempfile.mkdtemp(prefix="qemu-machine-",
+ dir=self._base_temp_dir)
+ return self._temp_dir
diff --git a/python/qemu/qtest.py b/python/qemu/qtest.py
index 39a0cf62fe9..78b97d13cf0 100644
--- a/python/qemu/qtest.py
+++ b/python/qemu/qtest.py
@@ -112,14 +112,14 @@ def __init__(self,
binary: str,
args: Sequence[str] = (),
name: Optional[str] = None,
- test_dir: str = "/var/tmp",
+ base_temp_dir: str = "/var/tmp",
socket_scm_helper: Optional[str] = None,
sock_dir: Optional[str] = None):
if name is None:
name = "qemu-%d" % os.getpid()
if sock_dir is None:
- sock_dir = test_dir
- super().__init__(binary, args, name=name, test_dir=test_dir,
+ sock_dir = base_temp_dir
+ super().__init__(binary, args, name=name, base_temp_dir=base_temp_dir,
socket_scm_helper=socket_scm_helper,
sock_dir=sock_dir)
self._qtest: Optional[QEMUQtestProtocol] = None
diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
index 777fa2ec0e8..92681907ed9 100644
--- a/tests/qemu-iotests/iotests.py
+++ b/tests/qemu-iotests/iotests.py
@@ -571,7 +571,7 @@ class VM(qtest.QEMUQtestMachine):
def __init__(self, path_suffix=''):
name = "qemu%s-%d" % (path_suffix, os.getpid())
super().__init__(qemu_prog, qemu_opts, name=name,
- test_dir=test_dir,
+ base_temp_dir=test_dir,
socket_scm_helper=socket_scm_helper,
sock_dir=sock_dir)
self._num_drives = 0
--
2.31.1
- [PULL 00/44] Python patches, John Snow, 2021/05/27
- [PULL 01/44] Python: expose QEMUMachine's temporary directory,
John Snow <=
- [PULL 02/44] tests/acceptance/virtiofs_submounts.py: add missing accel tag, John Snow, 2021/05/27
- [PULL 03/44] tests/acceptance/virtiofs_submounts.py: evaluate string not length, John Snow, 2021/05/27
- [PULL 04/44] Python: add utility function for retrieving port redirection, John Snow, 2021/05/27
- [PULL 05/44] Acceptance Tests: move useful ssh methods to base class, John Snow, 2021/05/27
- [PULL 06/44] Acceptance Tests: add port redirection for ssh by default, John Snow, 2021/05/27
- [PULL 07/44] Acceptance Tests: make username/password configurable, John Snow, 2021/05/27
- [PULL 08/44] Acceptance Tests: set up SSH connection by default after boot for LinuxTest, John Snow, 2021/05/27
- [PULL 09/44] tests/acceptance/virtiofs_submounts.py: remove launch_vm(), John Snow, 2021/05/27
- [PULL 10/44] Acceptance Tests: add basic documentation on LinuxTest base class, John Snow, 2021/05/27
- [PULL 11/44] Acceptance Tests: introduce CPU hotplug test, John Snow, 2021/05/27