[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 11/23] tests/functional: Set up logging
From: |
Thomas Huth |
Subject: |
[PATCH v2 11/23] tests/functional: Set up logging |
Date: |
Wed, 24 Jul 2024 19:52:29 +0200 |
Create log files for each test separately, one file that contains
the basic logging and one that contains the console output.
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
tests/functional/qemu_test/__init__.py | 26 +++++++++++++++++++++++++-
1 file changed, 25 insertions(+), 1 deletion(-)
diff --git a/tests/functional/qemu_test/__init__.py
b/tests/functional/qemu_test/__init__.py
index 40a81c3927..49cce620ab 100644
--- a/tests/functional/qemu_test/__init__.py
+++ b/tests/functional/qemu_test/__init__.py
@@ -208,7 +208,8 @@ class QemuBaseTest(unittest.TestCase):
arch = None
workdir = None
- log = logging.getLogger('qemu-test')
+ log = None
+ logdir = None
def setUp(self, bin_prefix):
self.assertIsNotNone(self.qemu_bin, 'QEMU_TEST_QEMU_BINARY must be
set')
@@ -219,6 +220,19 @@ def setUp(self, bin_prefix):
if not os.path.exists(self.workdir):
os.makedirs(self.workdir)
+ self.logdir = self.workdir
+ self.log = logging.getLogger('qemu-test')
+ self.log.setLevel(logging.DEBUG)
+ self._log_fh = logging.FileHandler(os.path.join(self.logdir,
+ 'base.log'), mode='w')
+ self._log_fh.setLevel(logging.DEBUG)
+ fileFormatter = logging.Formatter('%(asctime)s - %(levelname)s:
%(message)s')
+ self._log_fh.setFormatter(fileFormatter)
+ self.log.addHandler(self._log_fh)
+
+ def tearDown(self):
+ self.log.removeHandler(self._log_fh)
+
def check_hash(self, file_name, expected_hash):
if not expected_hash:
return True
@@ -276,6 +290,15 @@ def setUp(self):
super().setUp('qemu-system-')
+ console_log = logging.getLogger('console')
+ console_log.setLevel(logging.DEBUG)
+ self._console_log_fh = logging.FileHandler(os.path.join(self.workdir,
+ 'console.log'), mode='w')
+ self._console_log_fh.setLevel(logging.DEBUG)
+ fileFormatter = logging.Formatter('%(asctime)s: %(message)s')
+ self._console_log_fh.setFormatter(fileFormatter)
+ console_log.addHandler(self._console_log_fh)
+
def set_machine(self, machinename):
# TODO: We should use QMP to get the list of available machines
if not self._machinehelp:
@@ -366,4 +389,5 @@ def set_vm_arg(self, arg, value):
def tearDown(self):
for vm in self._vms.values():
vm.shutdown()
+ logging.getLogger('console').removeHandler(self._console_log_fh)
super().tearDown()
--
2.45.2
- Re: [PATCH v2 05/23] tests/functional: Convert simple avocado tests into standalone python tests, (continued)
- [PATCH v2 06/23] tests/functional: Convert avocado tests that just need a small adjustment, Thomas Huth, 2024/07/24
- [PATCH v2 07/23] tests/functional: Implement fetch_asset() method for downloading assets, Thomas Huth, 2024/07/24
- [PATCH v2 08/23] tests/functional: Convert some tests that download files via fetch_asset(), Thomas Huth, 2024/07/24
- [PATCH v2 09/23] tests/functional: Add a function for extracting files from an archive, Thomas Huth, 2024/07/24
- [PATCH v2 10/23] tests/functional: Convert some avocado tests that needed avocado.utils.archive, Thomas Huth, 2024/07/24
- [PATCH v2 11/23] tests/functional: Set up logging,
Thomas Huth <=
- [PATCH v2 12/23] tests/functional: Convert the s390x avocado tests into standalone tests, Thomas Huth, 2024/07/24
- [PATCH v2 14/23] tests/functional: Convert the microblaze avocado tests into standalone tests, Thomas Huth, 2024/07/24
- [PATCH v2 13/23] tests/functional: Convert the x86_cpu_model_versions test, Thomas Huth, 2024/07/24
- [PATCH v2 16/23] tests/functional: Convert the virtio_gpu avocado test into a standalone test, Thomas Huth, 2024/07/24
- [PATCH v2 17/23] tests/functional: Convert most ppc avocado tests into standalone tests, Thomas Huth, 2024/07/24
- [PATCH v2 15/23] tests/functional: Convert the riscv_opensbi avocado test into a standalone test, Thomas Huth, 2024/07/24