From: Wainer dos Santos Moschetta <wainersm@redhat.com>
To: qemu-devel@nongnu.org
Cc: willianr@redhat.com, philmd@redhat.com, crosa@redhat.com
Subject: [PATCH 7/7] tests/acceptance: Move _console_interaction to ConsoleMixIn
Date: Mon, 3 May 2021 19:43:26 -0300 [thread overview]
Message-ID: <20210503224326.206208-8-wainersm@redhat.com> (raw)
In-Reply-To: <20210503224326.206208-1-wainersm@redhat.com>
This moved the last remaining _console_interaction() to ConsoleMixIn.
None tests call it directly, so only the other methods in ConsoleMixIn
needed to be adapted.
Signed-off-by: Wainer dos Santos Moschetta <wainersm@redhat.com>
---
tests/acceptance/avocado_qemu/__init__.py | 57 +++++++++++------------
1 file changed, 28 insertions(+), 29 deletions(-)
diff --git a/tests/acceptance/avocado_qemu/__init__.py b/tests/acceptance/avocado_qemu/__init__.py
index b21f9ea3ff..a6de3fe11a 100644
--- a/tests/acceptance/avocado_qemu/__init__.py
+++ b/tests/acceptance/avocado_qemu/__init__.py
@@ -76,34 +76,33 @@ def pick_default_qemu_bin(arch=None):
if is_readable_executable_file(qemu_bin_from_bld_dir_path):
return qemu_bin_from_bld_dir_path
-
-def _console_interaction(test, success_message, failure_message,
- send_string, keep_sending=False, vm=None):
- assert not keep_sending or send_string
- if vm is None:
- vm = test.vm
- console = vm.console_socket.makefile()
- console_logger = logging.getLogger('console')
- while True:
- if send_string:
- vm.console_socket.sendall(send_string.encode())
- if not keep_sending:
- send_string = None # send only once
- msg = console.readline().strip()
- if not msg:
- continue
- console_logger.debug(msg)
- if success_message is None or success_message in msg:
- break
- if failure_message and failure_message in msg:
- console.close()
- fail = 'Failure message found in console: "%s". Expected: "%s"' % \
- (failure_message, success_message)
- test.fail(fail)
-
class ConsoleMixIn():
"""Contains utilities for interacting with a guest via Console."""
+ def _console_interaction(self, success_message, failure_message,
+ send_string, keep_sending=False, vm=None):
+ assert not keep_sending or send_string
+ if vm is None:
+ vm = self.vm
+ console = vm.console_socket.makefile()
+ console_logger = logging.getLogger('console')
+ while True:
+ if send_string:
+ vm.console_socket.sendall(send_string.encode())
+ if not keep_sending:
+ send_string = None # send only once
+ msg = console.readline().strip()
+ if not msg:
+ continue
+ console_logger.debug(msg)
+ if success_message is None or success_message in msg:
+ break
+ if failure_message and failure_message in msg:
+ console.close()
+ fail = 'Failure message found in console: "%s". Expected: "%s"' % \
+ (failure_message, success_message)
+ self.fail(fail)
+
def exec_command(self, command):
"""
Send a command to a console (appending CRLF characters), while logging
@@ -112,7 +111,7 @@ def exec_command(self, command):
:param command: the command to send
:type command: str
"""
- _console_interaction(self, None, None, command + '\r')
+ self._console_interaction(None, None, command + '\r')
def exec_command_and_wait_for_pattern(self, command,
success_message, failure_message=None):
@@ -125,7 +124,7 @@ def exec_command_and_wait_for_pattern(self, command,
:param success_message: if this message appears, test succeeds
:param failure_message: if this message appears, test fails
"""
- _console_interaction(self, success_message, failure_message, command + '\r')
+ self._console_interaction(success_message, failure_message, command + '\r')
def interrupt_interactive_console_until_pattern(self, success_message,
failure_message=None,
@@ -147,7 +146,7 @@ def interrupt_interactive_console_until_pattern(self, success_message,
:param interrupt_string: a string to send to the console before trying
to read a new line
"""
- _console_interaction(self, success_message, failure_message,
+ self._console_interaction(success_message, failure_message,
interrupt_string, True)
def wait_for_console_pattern(self, success_message, failure_message=None,
@@ -158,7 +157,7 @@ def wait_for_console_pattern(self, success_message, failure_message=None,
:param success_message: if this message appears, test succeeds
:param failure_message: if this message appears, test fails
"""
- _console_interaction(self, success_message, failure_message, None, vm=vm)
+ self._console_interaction(success_message, failure_message, None, vm=vm)
class Test(avocado.Test):
def _get_unique_tag_val(self, tag_name):
--
2.29.2
next prev parent reply other threads:[~2021-05-03 23:23 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-03 22:43 [PATCH 0/7] tests/acceptance: Introducing the ConsoleMixIn Wainer dos Santos Moschetta
2021-05-03 22:43 ` [PATCH 1/7] tests/acceptance: Introduce the ConsoleMixIn class Wainer dos Santos Moschetta
2021-05-24 18:14 ` Willian Rampazzo
2021-05-03 22:43 ` [PATCH 2/7] tests/acceptance: Move exec_command to ConsoleMixIn Wainer dos Santos Moschetta
2021-05-24 18:16 ` Willian Rampazzo
2021-05-03 22:43 ` [PATCH 3/7] tests/acceptance: Move exec_command_and_wait_for_pattern " Wainer dos Santos Moschetta
2021-05-24 18:21 ` Willian Rampazzo
2021-05-03 22:43 ` [PATCH 4/7] tests/acceptance: Sun4uMachine: Remove dependency to LinuxKernelTest Wainer dos Santos Moschetta
2021-05-04 16:01 ` Philippe Mathieu-Daudé
2021-05-24 18:30 ` Willian Rampazzo
2021-05-24 18:54 ` Willian Rampazzo
2021-05-24 18:24 ` Willian Rampazzo
2021-05-03 22:43 ` [PATCH 5/7] tests/acceptance: replay_kernel: Remove unused wait_for_console_pattern Wainer dos Santos Moschetta
2021-05-24 18:32 ` Willian Rampazzo
2021-05-03 22:43 ` [PATCH 6/7] tests/acceptance: Move wait_for_console_pattern to ConsoleMixIn Wainer dos Santos Moschetta
2021-05-24 20:52 ` Willian Rampazzo
2021-05-03 22:43 ` Wainer dos Santos Moschetta [this message]
2021-05-24 18:37 ` [PATCH 7/7] tests/acceptance: Move _console_interaction " Willian Rampazzo
2021-05-24 20:58 ` [PATCH 0/7] tests/acceptance: Introducing the ConsoleMixIn Willian Rampazzo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210503224326.206208-8-wainersm@redhat.com \
--to=wainersm@redhat.com \
--cc=crosa@redhat.com \
--cc=philmd@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=willianr@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).