提交 a91ba1d3 编写于 作者: P Philippe Mathieu-Daudé 提交者: Philippe Mathieu-Daudé

Acceptance tests: Extract _console_interaction()

Since we are going to re-use the code shared between
wait_for_console_pattern() and exec_command_and_wait_for_pattern(),
extract the common part into a local function.
Tested-by: NNiek Linnenbank <nieklinnenbank@gmail.com>
Signed-off-by: NPhilippe Mathieu-Daudé <f4bug@amsat.org>
Reviewed-by: NLiam Merwick <liam.merwick@oracle.com>
Tested-by: NLiam Merwick <liam.merwick@oracle.com>
Reviewed-by: NWainer dos Santos Moschetta <wainersm@redhat.com>
Message-Id: <20200120235159.18510-3-f4bug@amsat.org>
Signed-off-by: NPhilippe Mathieu-Daudé <philmd@redhat.com>
上级 746f244d
......@@ -55,19 +55,14 @@ 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
"""
def _console_interaction(test, success_message, failure_message,
send_string):
console = test.vm.console_socket.makefile()
console_logger = logging.getLogger('console')
while True:
if send_string:
test.vm.console_socket.sendall(send_string.encode())
send_string = None # send only once
msg = console.readline().strip()
if not msg:
continue
......@@ -79,6 +74,17 @@ def wait_for_console_pattern(test, success_message, failure_message=None):
fail = 'Failure message found in console: %s' % failure_message
test.fail(fail)
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_interaction(test, success_message, failure_message, None)
def exec_command_and_wait_for_pattern(test, command,
success_message, failure_message=None):
......@@ -94,10 +100,7 @@ def exec_command_and_wait_for_pattern(test, command,
:param success_message: if this message appears, test succeeds
:param failure_message: if this message appears, test fails
"""
command += '\r'
test.vm.console_socket.sendall(command.encode())
wait_for_console_pattern(test, success_message, failure_message)
_console_interaction(test, success_message, failure_message, command + '\r')
class Test(avocado.Test):
def _get_unique_tag_val(self, tag_name):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册