[PATCH 4/6] avocado_qemu: tweak ssh connect method

Willian Rampazzo posted 6 patches 4 years, 4 months ago
Maintainers: Wainer dos Santos Moschetta <wainersm@redhat.com>, "Philippe Mathieu-Daudé" <philmd@redhat.com>, Cleber Rosa <crosa@redhat.com>
[PATCH 4/6] avocado_qemu: tweak ssh connect method
Posted by Willian Rampazzo 4 years, 4 months ago
The current implementation will crash if the connection fails as the
`time` module is not imported. This fixes the import problem and tweaks
the connection to wait progressively when the connection fails.

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

diff --git a/tests/acceptance/avocado_qemu/__init__.py b/tests/acceptance/avocado_qemu/__init__.py
index edb9ed7485..c3613f9262 100644
--- a/tests/acceptance/avocado_qemu/__init__.py
+++ b/tests/acceptance/avocado_qemu/__init__.py
@@ -13,6 +13,7 @@
 import shutil
 import sys
 import tempfile
+import time
 import uuid
 
 import avocado
@@ -305,8 +306,7 @@ def ssh_connect(self, username, credential, credential_is_key=True):
                 self.ssh_session.connect()
                 return
             except:
-                time.sleep(4)
-                pass
+                time.sleep(i)
         self.fail('ssh connection timeout')
 
     def ssh_command(self, command):
-- 
2.31.1


Re: [PATCH 4/6] avocado_qemu: tweak ssh connect method
Posted by Philippe Mathieu-Daudé 4 years, 4 months ago
On 9/20/21 22:49, Willian Rampazzo wrote:
> The current implementation will crash if the connection fails as the
> `time` module is not imported. This fixes the import problem and tweaks
> the connection to wait progressively when the connection fails.
> 
> Signed-off-by: Willian Rampazzo <willianr@redhat.com>
> ---
>  tests/acceptance/avocado_qemu/__init__.py | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/tests/acceptance/avocado_qemu/__init__.py b/tests/acceptance/avocado_qemu/__init__.py
> index edb9ed7485..c3613f9262 100644
> --- a/tests/acceptance/avocado_qemu/__init__.py
> +++ b/tests/acceptance/avocado_qemu/__init__.py
> @@ -13,6 +13,7 @@
>  import shutil
>  import sys
>  import tempfile
> +import time
>  import uuid
>  
>  import avocado
> @@ -305,8 +306,7 @@ def ssh_connect(self, username, credential, credential_is_key=True):
>                  self.ssh_session.connect()
>                  return
>              except:
> -                time.sleep(4)

10 * 4 = 40

> -                pass
> +                time.sleep(i)

sum([0..10[) = 45

The described tweak. Almost the same, OK.

>          self.fail('ssh connection timeout')
>  
>      def ssh_command(self, command):
> 


Re: [PATCH 4/6] avocado_qemu: tweak ssh connect method
Posted by Willian Rampazzo 4 years, 4 months ago
On Mon, Sep 27, 2021 at 11:12 AM Philippe Mathieu-Daudé
<philmd@redhat.com> wrote:
>
> On 9/20/21 22:49, Willian Rampazzo wrote:
> > The current implementation will crash if the connection fails as the
> > `time` module is not imported. This fixes the import problem and tweaks
> > the connection to wait progressively when the connection fails.
> >
> > Signed-off-by: Willian Rampazzo <willianr@redhat.com>
> > ---
> >  tests/acceptance/avocado_qemu/__init__.py | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/tests/acceptance/avocado_qemu/__init__.py b/tests/acceptance/avocado_qemu/__init__.py
> > index edb9ed7485..c3613f9262 100644
> > --- a/tests/acceptance/avocado_qemu/__init__.py
> > +++ b/tests/acceptance/avocado_qemu/__init__.py
> > @@ -13,6 +13,7 @@
> >  import shutil
> >  import sys
> >  import tempfile
> > +import time
> >  import uuid
> >
> >  import avocado
> > @@ -305,8 +306,7 @@ def ssh_connect(self, username, credential, credential_is_key=True):
> >                  self.ssh_session.connect()
> >                  return
> >              except:
> > -                time.sleep(4)
>
> 10 * 4 = 40
>
> > -                pass
> > +                time.sleep(i)
>
> sum([0..10[) = 45
>
> The described tweak. Almost the same, OK.
>

The idea is that, hopefully, the connection will complete in one of
the first tries, so the overall wait time will be less than using a
fixed number. In the worst case, it will wait 5 seconds more than the
original code.

> >          self.fail('ssh connection timeout')
> >
> >      def ssh_command(self, command):
> >
>