Acceptance tests: refactor wait_for_console_pattern

The same utility method is already present in two different test
files, so let's consolidate it into a single utility function.

Signed-off-by: Cleber Rosa <crosa@redhat.com>
Message-Id: <20190916164011.7653-1-crosa@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
[PMD: failure_message is optional]
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Aleksandar Markovic <amarkovic@wavecomp.com>
Message-Id: <20191028073441.6448-3-philmd@redhat.com>
Signed-off-by: Cleber Rosa <crosa@redhat.com>
This commit is contained in:
Cleber Rosa 2019-10-28 19:04:04 -04:00
parent 0858096702
commit 77bcd2487e
3 changed files with 33 additions and 37 deletions

View file

@ -8,6 +8,7 @@
# This work is licensed under the terms of the GNU GPL, version 2 or
# later. See the COPYING file in the top-level directory.
import logging
import os
import sys
import uuid
@ -54,6 +55,30 @@ def pick_default_qemu_bin(arch=None):
return qemu_bin_from_src_dir_path
def wait_for_console_pattern(test, success_message, failure_message=None):
"""
Waits for messages to appear on the console, while logging the content
:param test: an Avocado test containing a VM that will have its console
read and probed for a success or failure message
:type test: :class:`avocado_qemu.Test`
:param success_message: if this message appears, test succeeds
:param failure_message: if this message appears, test fails
"""
console = test.vm.console_socket.makefile()
console_logger = logging.getLogger('console')
while True:
msg = console.readline().strip()
if not msg:
continue
console_logger.debug(msg)
if success_message in msg:
break
if failure_message and failure_message in msg:
fail = 'Failure message found in console: %s' % failure_message
test.fail(fail)
class Test(avocado.Test):
def setUp(self):
self._vms = {}