ssh.py 1.5 KB

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