[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 03/23] Acceptance Tests: distinguish between temp and logs dir
From: |
Cleber Rosa |
Subject: |
[PULL 03/23] Acceptance Tests: distinguish between temp and logs dir |
Date: |
Tue, 13 Jul 2021 17:19:03 -0400 |
Logs can be very important to debug issues, and currently QEMUMachine
instances will remove logs that are created under the temporary
directories.
With this change, the stdout and stderr generated by the QEMU process
started by QEMUMachine will always be kept along the test results
directory.
Signed-off-by: Cleber Rosa <crosa@redhat.com>
Message-Id: <20210211220146.2525771-6-crosa@redhat.com>
Reviewed-by: Wainer dos Santos Moschetta <wainersm@redhat.com>
Signed-off-by: Cleber Rosa <crosa@redhat.com>
---
python/qemu/machine/machine.py | 17 ++++++++++++++---
tests/acceptance/avocado_qemu/__init__.py | 3 ++-
2 files changed, 16 insertions(+), 4 deletions(-)
diff --git a/python/qemu/machine/machine.py b/python/qemu/machine/machine.py
index d47ab3d896..94846dd71b 100644
--- a/python/qemu/machine/machine.py
+++ b/python/qemu/machine/machine.py
@@ -96,7 +96,8 @@ def __init__(self,
socket_scm_helper: Optional[str] = None,
sock_dir: Optional[str] = None,
drain_console: bool = False,
- console_log: Optional[str] = None):
+ console_log: Optional[str] = None,
+ log_dir: Optional[str] = None):
'''
Initialize a QEMUMachine
@@ -110,6 +111,7 @@ def __init__(self,
@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
+ @param log_dir: where to create and keep log files
@note: Qemu process is not started until launch() is used.
'''
# pylint: disable=too-many-arguments
@@ -123,6 +125,7 @@ def __init__(self,
self._name = name or "qemu-%d" % os.getpid()
self._base_temp_dir = base_temp_dir
self._sock_dir = sock_dir or self._base_temp_dir
+ self._log_dir = log_dir
self._socket_scm_helper = socket_scm_helper
if monitor_address is not None:
@@ -314,8 +317,6 @@ def _base_args(self) -> List[str]:
return args
def _pre_launch(self) -> None:
- self._qemu_log_path = os.path.join(self.temp_dir, self._name + ".log")
-
if self._console_set:
self._remove_files.append(self._console_address)
@@ -332,6 +333,7 @@ def _pre_launch(self) -> None:
# NOTE: Make sure any opened resources are *definitely* freed in
# _post_shutdown()!
# pylint: disable=consider-using-with
+ self._qemu_log_path = os.path.join(self.log_dir, self._name + ".log")
self._qemu_log_file = open(self._qemu_log_path, 'wb')
def _post_launch(self) -> None:
@@ -770,3 +772,12 @@ def temp_dir(self) -> str:
self._temp_dir = tempfile.mkdtemp(prefix="qemu-machine-",
dir=self._base_temp_dir)
return self._temp_dir
+
+ @property
+ def log_dir(self) -> str:
+ """
+ Returns a directory to be used for writing logs
+ """
+ if self._log_dir is None:
+ return self.temp_dir
+ return self._log_dir
diff --git a/tests/acceptance/avocado_qemu/__init__.py
b/tests/acceptance/avocado_qemu/__init__.py
index 4ce09de4fa..420c00f1a9 100644
--- a/tests/acceptance/avocado_qemu/__init__.py
+++ b/tests/acceptance/avocado_qemu/__init__.py
@@ -222,9 +222,10 @@ def setUp(self):
def _new_vm(self, name, *args):
self._sd = tempfile.TemporaryDirectory(prefix="avo_qemu_sock_")
vm = QEMUMachine(self.qemu_bin, base_temp_dir=self.workdir,
- sock_dir=self._sd.name)
+ sock_dir=self._sd.name, log_dir=self.logdir)
self.log.debug('QEMUMachine "%s" created', name)
self.log.debug('QEMUMachine "%s" temp_dir: %s', name, vm.temp_dir)
+ self.log.debug('QEMUMachine "%s" log_dir: %s', name, vm.log_dir)
if args:
vm.add_args(*args)
return vm
--
2.31.1
- [PULL 00/23] Python and Acceptance Tests, Cleber Rosa, 2021/07/13
- [PULL 01/23] Acceptance Tests: use the job work directory for created VMs, Cleber Rosa, 2021/07/13
- [PULL 02/23] Acceptance Tests: log information when creating QEMUMachine, Cleber Rosa, 2021/07/13
- [PULL 04/23] Acceptance Tests: rename attribute holding the distro image checksum, Cleber Rosa, 2021/07/13
- [PULL 03/23] Acceptance Tests: distinguish between temp and logs dir,
Cleber Rosa <=
- [PULL 05/23] Acceptance Tests: move definition of distro checksums to the framework, Cleber Rosa, 2021/07/13
- [PULL 06/23] Acceptance Tests: support choosing specific distro and version, Cleber Rosa, 2021/07/13
- [PULL 07/23] tests/acceptance: Ignore binary data sent on serial console, Cleber Rosa, 2021/07/13
- [PULL 09/23] Acceptance Tests: Add default kernel params and pxeboot url to the KNOWN_DISTROS collection, Cleber Rosa, 2021/07/13
- [PULL 08/23] avocado_qemu: Fix KNOWN_DISTROS map into the LinuxDistro class, Cleber Rosa, 2021/07/13
- [PULL 10/23] avocado_qemu: Add SMMUv3 tests, Cleber Rosa, 2021/07/13
- [PULL 11/23] avocado_qemu: Add Intel iommu tests, Cleber Rosa, 2021/07/13
- [PULL 12/23] tests/acceptance: Tag NetBSD tests as 'os:netbsd', Cleber Rosa, 2021/07/13
- [PULL 13/23] tests/acceptance: Automatic set -cpu to the test vm, Cleber Rosa, 2021/07/13
- [PULL 14/23] tests/acceptance: Fix mismatch on cpu tagged tests, Cleber Rosa, 2021/07/13