From b662f80956f0c7b79fd1271424a36f661dc8ea65 Mon Sep 17 00:00:00 2001 From: Sebastian Mitterle Date: Tue, 12 Sep 2023 07:06:13 -0400 Subject: [PATCH] libvirt-guests: Improve test logging The test sometimes fails and there's no log for the guest service at all. Add checks for start and restart to succeed and if not, log the service logs with journalctl. Also, the Tail was called incorrectly leading to (per default unrecorded) TypeError "can only concatenate str (not "tuple") to str" The Tail already has a log file where it stores the output. Print its path so it can be inspected if needed. Signed-off-by: Sebastian Mitterle --- .../sysconfig_libvirt_guests/libvirt_guests.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/libvirt/tests/src/daemon/conf_file/sysconfig_libvirt_guests/libvirt_guests.py b/libvirt/tests/src/daemon/conf_file/sysconfig_libvirt_guests/libvirt_guests.py index 75092a35eb2..5f7013c8d1b 100644 --- a/libvirt/tests/src/daemon/conf_file/sysconfig_libvirt_guests/libvirt_guests.py +++ b/libvirt/tests/src/daemon/conf_file/sysconfig_libvirt_guests/libvirt_guests.py @@ -39,10 +39,9 @@ def get_log(): :returns: the appended data tailed from /var/log/messages """ - tailed_log_file = os.path.join(data_dir.get_tmp_dir(), 'tail_log') - tailed_messages = aexpect.Tail(command='tail -f /var/log/messages', - output_func=utils_misc.log_line, - output_params=(tailed_log_file)) + tailed_messages = aexpect.Tail(command='tail -f /var/log/messages') + logging.debug("Tail of log messages are logged in %s", + tailed_messages.output_filename) return tailed_messages def chk_on_shutdown(status_error, on_shutdown, parallel_shutdown, output): @@ -265,8 +264,11 @@ def cleanup_nfs_backend_guest(vmxml_backup): config = utils_config.LibvirtGuestsConfig() libvirt_guests_service = service.Factory.create_service("libvirt-guests") - if not libvirt_guests_service.status(): - libvirt_guests_service.start() + if (not libvirt_guests_service.status() + and libvirt_guests_service.start() == 0): + process.run("journalctl -u libvirt-guests", ignore_status=True) + test.error("libvirt-guests service failed to start. Please check logs") + vms = [main_vm] if main_vm.is_alive: @@ -319,7 +321,9 @@ def cleanup_nfs_backend_guest(vmxml_backup): # Even though libvirt-guests was designed to operate guests when # host shutdown. The purpose can also be fulfilled by restart the # libvirt-guests service. - libvirt_guests_service.restart() + if not libvirt_guests_service.restart() == 0: + process.run("journalctl -u libvirt-guests", ignore_status=True) + test.error("libvirt-guests failed to restart. Please check logs.") time.sleep(30) output = tail_messages.get_output() logging.debug("Get messages in /var/log/messages: %s" % output)