Skip to content

Commit

Permalink
libvirt-guests: Improve test logging
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
smitterl committed Sep 12, 2023
1 parent 9efa4d2 commit 4bf6076
Showing 1 changed file with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from avocado.utils import process

from virttest import utils_libguestfs
from virttest import data_dir
from virttest import utils_misc
from virttest import virsh
from virttest import utils_config
Expand Down Expand Up @@ -39,10 +38,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):
Expand Down Expand Up @@ -265,8 +263,10 @@ 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 not libvirt_guests_service.start()):
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:
Expand Down Expand Up @@ -319,7 +319,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():
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)
Expand Down

0 comments on commit 4bf6076

Please sign in to comment.