[PATCH 2/7] tests/acceptance: Move exec_command to ConsoleMixIn

Wainer dos Santos Moschetta posted 7 patches 4 years, 9 months ago
Maintainers: Halil Pasic <pasic@linux.ibm.com>, Cornelia Huck <cohuck@redhat.com>, "Philippe Mathieu-Daudé" <philmd@redhat.com>, David Gibson <david@gibson.dropbear.id.au>, "Edgar E. Iglesias" <edgar.iglesias@gmail.com>, Wainer dos Santos Moschetta <wainersm@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>, "Hervé Poussineau" <hpoussin@reactos.org>, Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>, Fabien Chouteau <chouteau@adacore.com>, Andrzej Zaborowski <balrogg@gmail.com>, Antony Pavlov <antonynpavlov@gmail.com>, Huacai Chen <chenhuacai@kernel.org>, Peter Maydell <peter.maydell@linaro.org>, Christian Borntraeger <borntraeger@de.ibm.com>, Jiaxun Yang <jiaxun.yang@flygoat.com>, Cleber Rosa <crosa@redhat.com>, Pavel Dovgalyuk <pavel.dovgaluk@ispras.ru>, Greg Kurz <groug@kaod.org>, Aurelien Jarno <aurelien@aurel32.net>, KONRAD Frederic <frederic.konrad@adacore.com>, Yoshinori Sato <ysato@users.sourceforge.jp>, "Alex Bennée" <alex.bennee@linaro.org>
[PATCH 2/7] tests/acceptance: Move exec_command to ConsoleMixIn
Posted by Wainer dos Santos Moschetta 4 years, 9 months ago
This moved exec_command() to ConsoleMixIn class.

Only the multiprocess.py file were touched by that change, so its tests
were adapted.

Signed-off-by: Wainer dos Santos Moschetta <wainersm@redhat.com>
---
 tests/acceptance/avocado_qemu/__init__.py | 22 ++++++++++------------
 tests/acceptance/multiprocess.py          |  6 +++---
 2 files changed, 13 insertions(+), 15 deletions(-)

diff --git a/tests/acceptance/avocado_qemu/__init__.py b/tests/acceptance/avocado_qemu/__init__.py
index 6f4e0edfa3..4d3b869765 100644
--- a/tests/acceptance/avocado_qemu/__init__.py
+++ b/tests/acceptance/avocado_qemu/__init__.py
@@ -114,18 +114,6 @@ 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
-    :type command: str
-    """
-    _console_interaction(test, None, None, command + '\r')
-
 def exec_command_and_wait_for_pattern(test, command,
                                       success_message, failure_message=None):
     """
@@ -145,6 +133,16 @@ def exec_command_and_wait_for_pattern(test, command,
 class ConsoleMixIn():
     """Contains utilities for interacting with a guest via Console."""
 
+    def exec_command(self, command):
+        """
+        Send a command to a console (appending CRLF characters), while logging
+        the content.
+
+        :param command: the command to send
+        :type command: str
+        """
+        _console_interaction(self, None, None, command + '\r')
+
     def interrupt_interactive_console_until_pattern(self, success_message,
                                                     failure_message=None,
                                                     interrupt_string='\r'):
diff --git a/tests/acceptance/multiprocess.py b/tests/acceptance/multiprocess.py
index 96627f022a..41d3e51164 100644
--- a/tests/acceptance/multiprocess.py
+++ b/tests/acceptance/multiprocess.py
@@ -9,10 +9,10 @@
 
 from avocado_qemu import Test
 from avocado_qemu import wait_for_console_pattern
-from avocado_qemu import exec_command
+from avocado_qemu import ConsoleMixIn
 from avocado_qemu import exec_command_and_wait_for_pattern
 
-class Multiprocess(Test):
+class Multiprocess(Test, ConsoleMixIn):
     """
     :avocado: tags=multiprocess
     """
@@ -59,7 +59,7 @@ def do_test(self, kernel_url, initrd_url, kernel_command_line,
         self.vm.launch()
         wait_for_console_pattern(self, 'as init process',
                                  'Kernel panic - not syncing')
-        exec_command(self, 'mount -t sysfs sysfs /sys')
+        self.exec_command('mount -t sysfs sysfs /sys')
         exec_command_and_wait_for_pattern(self,
                                           'cat /sys/bus/pci/devices/*/uevent',
                                           'PCI_ID=1000:0012')
-- 
2.29.2


Re: [PATCH 2/7] tests/acceptance: Move exec_command to ConsoleMixIn
Posted by Willian Rampazzo 4 years, 8 months ago
On Mon, May 3, 2021 at 7:43 PM Wainer dos Santos Moschetta
<wainersm@redhat.com> wrote:
>
> This moved exec_command() to ConsoleMixIn class.
>
> Only the multiprocess.py file were touched by that change, so its tests
> were adapted.
>
> Signed-off-by: Wainer dos Santos Moschetta <wainersm@redhat.com>
> ---
>  tests/acceptance/avocado_qemu/__init__.py | 22 ++++++++++------------
>  tests/acceptance/multiprocess.py          |  6 +++---
>  2 files changed, 13 insertions(+), 15 deletions(-)
>
> diff --git a/tests/acceptance/avocado_qemu/__init__.py b/tests/acceptance/avocado_qemu/__init__.py
> index 6f4e0edfa3..4d3b869765 100644
> --- a/tests/acceptance/avocado_qemu/__init__.py
> +++ b/tests/acceptance/avocado_qemu/__init__.py
> @@ -114,18 +114,6 @@ 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
> -    :type command: str
> -    """
> -    _console_interaction(test, None, None, command + '\r')
> -
>  def exec_command_and_wait_for_pattern(test, command,
>                                        success_message, failure_message=None):
>      """
> @@ -145,6 +133,16 @@ def exec_command_and_wait_for_pattern(test, command,
>  class ConsoleMixIn():
>      """Contains utilities for interacting with a guest via Console."""
>
> +    def exec_command(self, command):
> +        """
> +        Send a command to a console (appending CRLF characters), while logging
> +        the content.
> +
> +        :param command: the command to send
> +        :type command: str
> +        """
> +        _console_interaction(self, None, None, command + '\r')
> +
>      def interrupt_interactive_console_until_pattern(self, success_message,
>                                                      failure_message=None,
>                                                      interrupt_string='\r'):
> diff --git a/tests/acceptance/multiprocess.py b/tests/acceptance/multiprocess.py
> index 96627f022a..41d3e51164 100644
> --- a/tests/acceptance/multiprocess.py
> +++ b/tests/acceptance/multiprocess.py
> @@ -9,10 +9,10 @@
>
>  from avocado_qemu import Test
>  from avocado_qemu import wait_for_console_pattern
> -from avocado_qemu import exec_command
> +from avocado_qemu import ConsoleMixIn
>  from avocado_qemu import exec_command_and_wait_for_pattern
>
> -class Multiprocess(Test):
> +class Multiprocess(Test, ConsoleMixIn):

Same comment here from the previous patch regarding the order of classes.

>      """
>      :avocado: tags=multiprocess
>      """
> @@ -59,7 +59,7 @@ def do_test(self, kernel_url, initrd_url, kernel_command_line,
>          self.vm.launch()
>          wait_for_console_pattern(self, 'as init process',
>                                   'Kernel panic - not syncing')
> -        exec_command(self, 'mount -t sysfs sysfs /sys')
> +        self.exec_command('mount -t sysfs sysfs /sys')
>          exec_command_and_wait_for_pattern(self,
>                                            'cat /sys/bus/pci/devices/*/uevent',
>                                            'PCI_ID=1000:0012')
> --
> 2.29.2
>