diff mbox series

[v2,1/2] avocado_qemu: add exec_command function

Message ID 20210225205907.223995-2-willianr@redhat.com
State New
Headers show
Series tests: Add functional test for out-of-process device emulation | expand

Commit Message

Willian Rampazzo Feb. 25, 2021, 8:59 p.m. UTC
Sometimes a test needs to send a command to a console without waiting
for a pattern as a result, or the command issued do not produce any kind
of output, like, for example, a `mount` command.

This introduces the `exec_command` function to the avocado_qemu,
allowing the test to send a command to the console without the need to
match a pattern produced as a result.

Signed-off-by: Willian Rampazzo <willianr@redhat.com>
---
 tests/acceptance/avocado_qemu/__init__.py | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

Comments

Wainer dos Santos Moschetta March 2, 2021, 3:38 p.m. UTC | #1
Hi,

On 2/25/21 5:59 PM, Willian Rampazzo wrote:
> Sometimes a test needs to send a command to a console without waiting
> for a pattern as a result, or the command issued do not produce any kind
> of output, like, for example, a `mount` command.
>
> This introduces the `exec_command` function to the avocado_qemu,
> allowing the test to send a command to the console without the need to
> match a pattern produced as a result.
>
> Signed-off-by: Willian Rampazzo <willianr@redhat.com>
> ---
>   tests/acceptance/avocado_qemu/__init__.py | 13 ++++++++++++-
>   1 file changed, 12 insertions(+), 1 deletion(-)
>
> diff --git a/tests/acceptance/avocado_qemu/__init__.py b/tests/acceptance/avocado_qemu/__init__.py
> index df167b142c..6ea94cc721 100644
> --- a/tests/acceptance/avocado_qemu/__init__.py
> +++ b/tests/acceptance/avocado_qemu/__init__.py
> @@ -93,7 +93,7 @@ def _console_interaction(test, success_message, failure_message,
>           if not msg:
>               continue
>           console_logger.debug(msg)
> -        if success_message in msg:
> +        if success_message is None or success_message in msg:
>               break
>           if failure_message and failure_message in msg:
>               console.close()
> @@ -139,6 +139,17 @@ def wait_for_console_pattern(test, success_message, failure_message=None,
>       """
>       _console_interaction(test, success_message, failure_message, None, vm=vm)
>   
> +def exec_command(test, command):
> +    """
> +    Send a command to a console (appending CRLF characters), while logging
> +    the content.
> +
> +    :param test: an Avocado test containing a VM.
> +    :type test: :class:`avocado_qemu.Test`
> +    :param command: the command to send

It's missing the command type. With that:

Reviewed-by: Wainer dos Santos Moschetta <wainersm@redhat.com>

> +    """
> +    _console_interaction(test, None, None, command + '\r')
> +
>   def exec_command_and_wait_for_pattern(test, command,
>                                         success_message, failure_message=None):
>       """
diff mbox series

Patch

diff --git a/tests/acceptance/avocado_qemu/__init__.py b/tests/acceptance/avocado_qemu/__init__.py
index df167b142c..6ea94cc721 100644
--- a/tests/acceptance/avocado_qemu/__init__.py
+++ b/tests/acceptance/avocado_qemu/__init__.py
@@ -93,7 +93,7 @@  def _console_interaction(test, success_message, failure_message,
         if not msg:
             continue
         console_logger.debug(msg)
-        if success_message in msg:
+        if success_message is None or success_message in msg:
             break
         if failure_message and failure_message in msg:
             console.close()
@@ -139,6 +139,17 @@  def wait_for_console_pattern(test, success_message, failure_message=None,
     """
     _console_interaction(test, success_message, failure_message, None, vm=vm)
 
+def exec_command(test, command):
+    """
+    Send a command to a console (appending CRLF characters), while logging
+    the content.
+
+    :param test: an Avocado test containing a VM.
+    :type test: :class:`avocado_qemu.Test`
+    :param command: the command to send
+    """
+    _console_interaction(test, None, None, command + '\r')
+
 def exec_command_and_wait_for_pattern(test, command,
                                       success_message, failure_message=None):
     """