xref: /openbmc/openbmc/poky/meta/lib/oeqa/runtime/cases/ssh.py (revision 8460358c3d24c71d9d38fd126c745854a6301564)
1 #
2 # Copyright OpenEmbedded Contributors
3 #
4 # SPDX-License-Identifier: MIT
5 #
6 
7 import time
8 import signal
9 
10 from oeqa.runtime.case import OERuntimeTestCase
11 from oeqa.core.decorator.depends import OETestDepends
12 from oeqa.runtime.decorator.package import OEHasPackage
13 
14 class SSHTest(OERuntimeTestCase):
15 
16     @OETestDepends(['ping.PingTest.test_ping'])
17     @OEHasPackage(['dropbear', 'openssh-sshd'])
18     def test_ssh(self):
19         for i in range(5):
20           status, output = self.target.run("uname -a", timeout=30)
21           if status == 0:
22               break
23           elif status == 255 or status == -signal.SIGTERM:
24               # ssh returns 255 only if a ssh error occurs.  This could
25               # be an issue with "Connection refused" because the port
26               # isn't open yet, and this could check explicitly for that
27               # here.  However, let's keep it simple and just retry for
28               # all errors a limited amount of times with a sleep to
29               # give it time for the port to open.
30               # We sometimes see -15 (SIGTERM) on slow emulation machines too, likely
31               # from boot/init not being 100% complete, retry for these too.
32               time.sleep(5)
33               continue
34           else:
35               self.fail("uname failed with \"%s\" (exit code %s)" % (output, status))
36         if status != 0:
37             self.fail("ssh failed with \"%s\" (exit code %s)" % (output, status))
38