[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 1/7] tests/acceptance: Introduce the ConsoleMixIn class
From: |
Willian Rampazzo |
Subject: |
Re: [PATCH 1/7] tests/acceptance: Introduce the ConsoleMixIn class |
Date: |
Mon, 24 May 2021 15:14:34 -0300 |
Hi Wainer,
On Mon, May 3, 2021 at 7:43 PM Wainer dos Santos Moschetta
<wainersm@redhat.com> wrote:
>
> This created the ConsoleMixIn class to wrap the methods related with console
> interaction with the guest that currently are loose in the avocado_qemu
> package. It should be used as a mixin on the test classes.
>
> At this point only the interrupt_interactive_console_until_pattern() was moved
> to ConsoleMixIn. This method is only used in boot_linux_console.py tests, so
> there was needed to adapt them.
>
> Signed-off-by: Wainer dos Santos Moschetta <wainersm@redhat.com>
> ---
> tests/acceptance/avocado_qemu/__init__.py | 52 +++++++++++------------
> tests/acceptance/boot_linux_console.py | 10 ++---
> 2 files changed, 31 insertions(+), 31 deletions(-)
>
> diff --git a/tests/acceptance/avocado_qemu/__init__.py
> b/tests/acceptance/avocado_qemu/__init__.py
> index 83b1741ec8..6f4e0edfa3 100644
> --- a/tests/acceptance/avocado_qemu/__init__.py
> +++ b/tests/acceptance/avocado_qemu/__init__.py
> @@ -101,32 +101,6 @@ def _console_interaction(test, success_message,
> failure_message,
> (failure_message, success_message)
> test.fail(fail)
>
> -def interrupt_interactive_console_until_pattern(test, success_message,
> - failure_message=None,
> - interrupt_string='\r'):
> - """
> - Keep sending a string to interrupt a console prompt, while logging the
> - console output. Typical use case is to break a boot loader prompt, such:
> -
> - Press a key within 5 seconds to interrupt boot process.
> - 5
> - 4
> - 3
> - 2
> - 1
> - Booting default image...
> -
> - :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
> - :param interrupt_string: a string to send to the console before trying
> - to read a new line
> - """
> - _console_interaction(test, success_message, failure_message,
> - interrupt_string, True)
> -
> def wait_for_console_pattern(test, success_message, failure_message=None,
> vm=None):
> """
> @@ -168,6 +142,32 @@ def exec_command_and_wait_for_pattern(test, command,
> """
> _console_interaction(test, success_message, failure_message, command +
> '\r')
>
> +class ConsoleMixIn():
> + """Contains utilities for interacting with a guest via Console."""
> +
> + def interrupt_interactive_console_until_pattern(self, success_message,
> + failure_message=None,
> + interrupt_string='\r'):
> + """
> + Keep sending a string to interrupt a console prompt, while logging
> the
> + console output. Typical use case is to break a boot loader prompt,
> such:
> +
> + Press a key within 5 seconds to interrupt boot process.
> + 5
> + 4
> + 3
> + 2
> + 1
> + Booting default image...
> +
> + :param success_message: if this message appears, test succeeds
> + :param failure_message: if this message appears, test fails
> + :param interrupt_string: a string to send to the console before
> trying
> + to read a new line
> + """
> + _console_interaction(self, success_message, failure_message,
> + interrupt_string, True)
> +
> class Test(avocado.Test):
> def _get_unique_tag_val(self, tag_name):
> """
> diff --git a/tests/acceptance/boot_linux_console.py
> b/tests/acceptance/boot_linux_console.py
> index 1ca32ecf25..10317b232b 100644
> --- a/tests/acceptance/boot_linux_console.py
> +++ b/tests/acceptance/boot_linux_console.py
> @@ -17,7 +17,7 @@
> from avocado import skipUnless
> from avocado_qemu import Test
> from avocado_qemu import exec_command_and_wait_for_pattern
> -from avocado_qemu import interrupt_interactive_console_until_pattern
> +from avocado_qemu import ConsoleMixIn
> from avocado_qemu import wait_for_console_pattern
> from avocado.utils import process
> from avocado.utils import archive
> @@ -45,7 +45,7 @@ def image_pow2ceil_expand(path):
> with open(path, 'ab+') as fd:
> fd.truncate(size_aligned)
>
> -class LinuxKernelTest(Test):
> +class LinuxKernelTest(Test, ConsoleMixIn):
The Python class hierarchy is defined from right to left. This would
not cause a problem now but can result in unexpected behavior in the
future. In this case, my suggestion is to switch the order here and
make the Test class the last.
> KERNEL_COMMON_COMMAND_LINE = 'printk.time=0 '
>
> def wait_for_console_pattern(self, success_message, vm=None):
> @@ -626,8 +626,8 @@ def test_arm_quanta_gsj(self):
> self.wait_for_console_pattern('>Device: Poleg BMC NPCM730')
> self.wait_for_console_pattern('>Skip DDR init.')
> self.wait_for_console_pattern('U-Boot ')
> - interrupt_interactive_console_until_pattern(
> - self, 'Hit any key to stop autoboot:', 'U-Boot>')
> + self.interrupt_interactive_console_until_pattern(
> + 'Hit any key to stop autoboot:', 'U-Boot>')
> exec_command_and_wait_for_pattern(
> self, "setenv bootargs ${bootargs} " + kernel_command_line,
> 'U-Boot>')
> @@ -879,7 +879,7 @@ def test_arm_orangepi_uboot_netbsd9(self):
> '-no-reboot')
> self.vm.launch()
> wait_for_console_pattern(self, 'U-Boot 2020.01+dfsg-1')
> - interrupt_interactive_console_until_pattern(self,
> + self.interrupt_interactive_console_until_pattern(
> 'Hit any key to stop autoboot:',
> 'switch to partitions #0, OK')
>
> --
> 2.29.2
>
- [PATCH 0/7] tests/acceptance: Introducing the ConsoleMixIn, Wainer dos Santos Moschetta, 2021/05/03
- [PATCH 1/7] tests/acceptance: Introduce the ConsoleMixIn class, Wainer dos Santos Moschetta, 2021/05/03
- Re: [PATCH 1/7] tests/acceptance: Introduce the ConsoleMixIn class,
Willian Rampazzo <=
- [PATCH 2/7] tests/acceptance: Move exec_command to ConsoleMixIn, Wainer dos Santos Moschetta, 2021/05/03
- [PATCH 3/7] tests/acceptance: Move exec_command_and_wait_for_pattern to ConsoleMixIn, Wainer dos Santos Moschetta, 2021/05/03
- [PATCH 5/7] tests/acceptance: replay_kernel: Remove unused wait_for_console_pattern, Wainer dos Santos Moschetta, 2021/05/03
- [PATCH 4/7] tests/acceptance: Sun4uMachine: Remove dependency to LinuxKernelTest, Wainer dos Santos Moschetta, 2021/05/03