diff mbox series

[3/8] tests/vm: change wait_ssh to optionally wait for root.

Message ID 20200124165335.422-4-robert.foley@linaro.org (mailing list archive)
State New, archived
Headers show
Series tests/vm: Add support for aarch64 VMs | expand

Commit Message

Robert Foley Jan. 24, 2020, 4:53 p.m. UTC
Allow wait_ssh to wait for root user to be ready.
This solves the issue where we perform a wait_ssh()
successfully, but the root user is not yet ready
to be logged in.

Signed-off-by: Robert Foley <robert.foley@linaro.org>
Reviewed-by: Peter Puhov <peter.puhov@linaro.org>
---
 tests/vm/basevm.py | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

Comments

Alex Bennée Jan. 27, 2020, 11:06 a.m. UTC | #1
Robert Foley <robert.foley@linaro.org> writes:

> Allow wait_ssh to wait for root user to be ready.
> This solves the issue where we perform a wait_ssh()
> successfully, but the root user is not yet ready
> to be logged in.

So in the case it's the root user we care about...

> Signed-off-by: Robert Foley <robert.foley@linaro.org>
> Reviewed-by: Peter Puhov <peter.puhov@linaro.org>
> ---
>  tests/vm/basevm.py | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/tests/vm/basevm.py b/tests/vm/basevm.py
> index 86908f58ec..3b4403ddcb 100755
> --- a/tests/vm/basevm.py
> +++ b/tests/vm/basevm.py
> @@ -310,12 +310,17 @@ class BaseVM(object):
>      def print_step(self, text):
>          sys.stderr.write("### %s ...\n" % text)
>  
> -    def wait_ssh(self, seconds=600):
> +    def wait_ssh(self, wait_root=False, seconds=600):
>          starttime = datetime.datetime.now()
>          endtime = starttime + datetime.timedelta(seconds=seconds)
>          guest_up = False
>          while datetime.datetime.now() < endtime:
> -            if self.ssh("exit 0") == 0:
> +            if wait_root:
> +                if self.ssh("exit 0") == 0 and\
> +                   self.ssh_root("exit 0") == 0:

...why do we need to test both here? 

> +                    guest_up = True
> +                    break
> +            elif self.ssh("exit 0") == 0:

Is this simpler?

    def wait_ssh(self, wait_root=False, seconds=600):
        starttime = datetime.datetime.now()
        endtime = starttime + datetime.timedelta(seconds=seconds)
        guest_up = False
        while datetime.datetime.now() < endtime:
            if wait_root and self.ssh_root("exit 0") == 0:
                guest_up = True
                break
            elif self.ssh("exit 0") == 0:
                guest_up = True
                break
            seconds = (endtime - datetime.datetime.now()).total_seconds()
            logging.debug("%ds before timeout", seconds)
            time.sleep(1)
        if not guest_up:
            raise Exception("Timeout while waiting for guest ssh")


>                  guest_up = True
>                  break
>              seconds = (endtime - datetime.datetime.now()).total_seconds()
Robert Foley Jan. 27, 2020, 12:59 p.m. UTC | #2
On Mon, 27 Jan 2020 at 06:06, Alex Bennée <alex.bennee@linaro.org> wrote:
> > Allow wait_ssh to wait for root user to be ready.
> > This solves the issue where we perform a wait_ssh()
> > successfully, but the root user is not yet ready
> > to be logged in.
>
> So in the case it's the root user we care about...
We care about both the root and guest users.  See below.
> >  tests/vm/basevm.py | 9 +++++++--
> >  1 file changed, 7 insertions(+), 2 deletions(-)
> >
> > diff --git a/tests/vm/basevm.py b/tests/vm/basevm.py
> > index 86908f58ec..3b4403ddcb 100755
> > --- a/tests/vm/basevm.py
> > +++ b/tests/vm/basevm.py
> > @@ -310,12 +310,17 @@ class BaseVM(object):
> >      def print_step(self, text):
> >          sys.stderr.write("### %s ...\n" % text)
> >
> > -    def wait_ssh(self, seconds=600):
> > +    def wait_ssh(self, wait_root=False, seconds=600):
> >          starttime = datetime.datetime.now()
> >          endtime = starttime + datetime.timedelta(seconds=seconds)
> >          guest_up = False
> >          while datetime.datetime.now() < endtime:
> > -            if self.ssh("exit 0") == 0:
> > +            if wait_root:
> > +                if self.ssh("exit 0") == 0 and\
> > +                   self.ssh_root("exit 0") == 0:
>
> ...why do we need to test both here?
We want to make sure the root user is up in
addition to the normal/guest user.  We're trying to add on the root user
since the issue we saw is that the guest user was up, (wait_ssh() completed),
but then when the root user tries to do something we get an error,
since root is not ready yet.

> > +                    guest_up = True
> > +                    break
> > +            elif self.ssh("exit 0") == 0:
>
> Is this simpler?
Certainly simpler.  :)
And simpler seems like the right call here.  But we'll need to call
into wait_ssh() twice,
once with the wait_root option and once without.  But I think this is better
since it makes the code on the caller side more explicit and clear in
that we will
explicitly wait for the guest user and then wait for the root user.

Thanks,
-Rob Foley
>     def wait_ssh(self, wait_root=False, seconds=600):
>         starttime = datetime.datetime.now()
>         endtime = starttime + datetime.timedelta(seconds=seconds)
>         guest_up = False
>         while datetime.datetime.now() < endtime:
>             if wait_root and self.ssh_root("exit 0") == 0:
>                 guest_up = True
>                 break
>             elif self.ssh("exit 0") == 0:
>                 guest_up = True
>                 break
>             seconds = (endtime - datetime.datetime.now()).total_seconds()
>             logging.debug("%ds before timeout", seconds)
>             time.sleep(1)
>         if not guest_up:
>             raise Exception("Timeout while waiting for guest ssh")
>
>
> >                  guest_up = True
> >                  break
> >              seconds = (endtime - datetime.datetime.now()).total_seconds()
>
>
> --
> Alex Bennée
diff mbox series

Patch

diff --git a/tests/vm/basevm.py b/tests/vm/basevm.py
index 86908f58ec..3b4403ddcb 100755
--- a/tests/vm/basevm.py
+++ b/tests/vm/basevm.py
@@ -310,12 +310,17 @@  class BaseVM(object):
     def print_step(self, text):
         sys.stderr.write("### %s ...\n" % text)
 
-    def wait_ssh(self, seconds=600):
+    def wait_ssh(self, wait_root=False, seconds=600):
         starttime = datetime.datetime.now()
         endtime = starttime + datetime.timedelta(seconds=seconds)
         guest_up = False
         while datetime.datetime.now() < endtime:
-            if self.ssh("exit 0") == 0:
+            if wait_root:
+                if self.ssh("exit 0") == 0 and\
+                   self.ssh_root("exit 0") == 0:
+                    guest_up = True
+                    break
+            elif self.ssh("exit 0") == 0:
                 guest_up = True
                 break
             seconds = (endtime - datetime.datetime.now()).total_seconds()