test_ssh.py 1.8 KB

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