diff mbox series

[RFC,5/7] avocado: Add an optional flag 'login' to get_console()

Message ID 20180419164642.9536-6-f4bug@amsat.org
State New
Headers show
Series avocado: Add acceptance tests parsing the Linux boot console | expand

Commit Message

Philippe Mathieu-Daudé April 19, 2018, 4:46 p.m. UTC
Not all consoles require users to log in :/

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 tests/avocado/avocado_qemu/test.py | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)

Comments

Cleber Rosa May 1, 2018, 7:46 p.m. UTC | #1
On 04/19/2018 12:46 PM, Philippe Mathieu-Daudé wrote:
> Not all consoles require users to log in :/
> 

You're breaking a lot of assumptions here (in a good way) ;).

> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> ---
>  tests/avocado/avocado_qemu/test.py | 23 ++++++++++++-----------
>  1 file changed, 12 insertions(+), 11 deletions(-)
> 
> diff --git a/tests/avocado/avocado_qemu/test.py b/tests/avocado/avocado_qemu/test.py
> index 1ead917014..ac8ee6d250 100644
> --- a/tests/avocado/avocado_qemu/test.py
> +++ b/tests/avocado/avocado_qemu/test.py
> @@ -244,7 +244,7 @@ class _VM(qemu.QEMUMachine):
>          super(_VM, self).__init__(qemu_bin, name=self.name, arch=arch)
>          logging.getLogger('QMP').setLevel(logging.INFO)
>  
> -    def get_console(self, console_address=None, prompt=r"[\#\$] "):
> +    def get_console(self, console_address=None, prompt=r"[\#\$] ", login=True):
>          """
>          :param address: Socket address, can be either a unix socket path
>                          (string) or a tuple in the form (address, port)
> @@ -252,9 +252,6 @@ class _VM(qemu.QEMUMachine):
>          :param prompt: The regex to identify we reached the prompt.
>          """
>  
> -        if not all((self.username, self.password)):
> -            raise QEMULoginError('Username or password not set.')
> -
>          if not self.is_running():
>              raise QEMULoginError('VM is not running.')
>  
> @@ -272,13 +269,17 @@ class _VM(qemu.QEMUMachine):
>              nc_cmd += ' -U %s' % console_address
>  
>          console = aexpect.ShellSession(nc_cmd)
> -        try:
> -            logging.info('Console: Waiting login prompt...')
> -            _handle_prompts(console, self.username, self.password, prompt)
> -            logging.info('Console: Ready!')
> -        except:
> -            console.close()
> -            raise
> +        if login:
> +            if not all((self.username, self.password)):
> +                raise QEMULoginError('Username or password not set.')
> +
> +            try:
> +                logging.info('Console: Waiting login prompt...')
> +                _handle_prompts(console, self.username, self.password, prompt)
> +            except:
> +                console.close()
> +                raise
> +        logging.info('Console: Ready!')
>  
>          return console
>  
> 

Since having docstrings for new parameters is a minor issue and not a
requirement:

Acked-by: Cleber Rosa <crosa@redhat.com>
diff mbox series

Patch

diff --git a/tests/avocado/avocado_qemu/test.py b/tests/avocado/avocado_qemu/test.py
index 1ead917014..ac8ee6d250 100644
--- a/tests/avocado/avocado_qemu/test.py
+++ b/tests/avocado/avocado_qemu/test.py
@@ -244,7 +244,7 @@  class _VM(qemu.QEMUMachine):
         super(_VM, self).__init__(qemu_bin, name=self.name, arch=arch)
         logging.getLogger('QMP').setLevel(logging.INFO)
 
-    def get_console(self, console_address=None, prompt=r"[\#\$] "):
+    def get_console(self, console_address=None, prompt=r"[\#\$] ", login=True):
         """
         :param address: Socket address, can be either a unix socket path
                         (string) or a tuple in the form (address, port)
@@ -252,9 +252,6 @@  class _VM(qemu.QEMUMachine):
         :param prompt: The regex to identify we reached the prompt.
         """
 
-        if not all((self.username, self.password)):
-            raise QEMULoginError('Username or password not set.')
-
         if not self.is_running():
             raise QEMULoginError('VM is not running.')
 
@@ -272,13 +269,17 @@  class _VM(qemu.QEMUMachine):
             nc_cmd += ' -U %s' % console_address
 
         console = aexpect.ShellSession(nc_cmd)
-        try:
-            logging.info('Console: Waiting login prompt...')
-            _handle_prompts(console, self.username, self.password, prompt)
-            logging.info('Console: Ready!')
-        except:
-            console.close()
-            raise
+        if login:
+            if not all((self.username, self.password)):
+                raise QEMULoginError('Username or password not set.')
+
+            try:
+                logging.info('Console: Waiting login prompt...')
+                _handle_prompts(console, self.username, self.password, prompt)
+            except:
+                console.close()
+                raise
+        logging.info('Console: Ready!')
 
         return console