summaryrefslogtreecommitdiffstats
path: root/meta/lib/oeqa/runtime/cases/ssh.py
blob: ae92bb34cd9c262ff51be3c3d82a8b2b8fdece9f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#
# Copyright OpenEmbedded Contributors
#
# SPDX-License-Identifier: MIT
#

import time

from oeqa.runtime.case import OERuntimeTestCase
from oeqa.core.decorator.depends import OETestDepends
from oeqa.runtime.decorator.package import OEHasPackage

class SSHTest(OERuntimeTestCase):

    @OETestDepends(['ping.PingTest.test_ping'])
    @OEHasPackage(['dropbear', 'openssh-sshd'])
    def test_ssh(self):
        for i in range(5):
          status, output = self.target.run("uname -a", timeout=5)
          if status == 0:
              break
          elif status == 255:
              # ssh returns 255 only if a ssh error occurs.  This could
              # be an issue with "Connection refused" because the port
              # isn't open yet, and this could check explicitly for that
              # here.  However, let's keep it simple and just retry for
              # all errors a limited amount of times with a sleep to
              # give it time for the port to open.
              time.sleep(5)
              continue
          else:
              self.fail("uname failed with \"%s\"" %output)
        if status == 255:
            self.fail("ssh error %s" %output)