test_ssh.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import os
  2. import shutil
  3. import tests.download.sshd
  4. import infra
  5. class SSHTestBase(infra.basetest.BRConfigTest):
  6. config = infra.basetest.MINIMAL_CONFIG + '''
  7. BR2_BACKUP_SITE=""
  8. '''
  9. sshd_test_dir = infra.filepath("tests/download/sshd")
  10. sshd = None
  11. def setUp(self):
  12. super(SSHTestBase, self).setUp()
  13. self.show_msg("Generating keys")
  14. tests.download.sshd.generate_keys(self.builddir, self.logtofile)
  15. self.show_msg("Starting sshd")
  16. self.sshd = tests.download.sshd.OpenSSHDaemon(self.builddir,
  17. self.logtofile)
  18. def tearDown(self):
  19. self.show_msg("Stopping sshd")
  20. if self.sshd:
  21. self.sshd.stop()
  22. super(SSHTestBase, self).tearDown()
  23. def download_package(self, package):
  24. self.show_msg("Downloading {}".format(package))
  25. # store downloaded tarball inside the output dir so the test infra
  26. # cleans it up at the end
  27. dl_dir = os.path.join(self.builddir, "dl")
  28. ssh_identity = os.path.join(self.builddir,
  29. tests.download.sshd.SSH_CLIENT_KEY)
  30. # enforce that we test the download
  31. if os.path.exists(dl_dir):
  32. shutil.rmtree(dl_dir)
  33. env = {"BR2_DL_DIR": dl_dir,
  34. "SSHD_PORT_NUMBER": str(self.sshd.port),
  35. "SSHD_TEST_DIR": self.sshd_test_dir,
  36. "SSH_IDENTITY": ssh_identity}
  37. self.b.build(["{}-dirclean".format(package),
  38. "{}-source".format(package)],
  39. env)
  40. class TestSCP(SSHTestBase):
  41. br2_external = [infra.filepath("tests/download/br2-external/ssh")]
  42. def test_run(self):
  43. self.download_package("scp")
  44. class TestSFTP(SSHTestBase):
  45. br2_external = [infra.filepath("tests/download/br2-external/ssh")]
  46. def test_run(self):
  47. self.download_package("sftp")