test_pre_flight.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. # -*- coding: utf-8 -*-
  2. """
  3. Test for ssh_pre_flight roster option
  4. """
  5. from __future__ import absolute_import, print_function, unicode_literals
  6. import os
  7. import salt.utils.files
  8. from tests.support.case import SSHCase
  9. from tests.support.helpers import slowTest
  10. from tests.support.runtests import RUNTIME_VARS
  11. class SSHPreFlightTest(SSHCase):
  12. """
  13. Test ssh_pre_flight roster option
  14. """
  15. def setUp(self):
  16. super(SSHPreFlightTest, self).setUp()
  17. self.roster = os.path.join(RUNTIME_VARS.TMP, "pre_flight_roster")
  18. self.data = {
  19. "ssh_pre_flight": os.path.join(RUNTIME_VARS.TMP, "ssh_pre_flight.sh")
  20. }
  21. self.test_script = os.path.join(
  22. RUNTIME_VARS.TMP, "test-pre-flight-script-worked.txt"
  23. )
  24. def _create_roster(self):
  25. self.custom_roster(self.roster, self.data)
  26. with salt.utils.files.fopen(self.data["ssh_pre_flight"], "w") as fp_:
  27. fp_.write("touch {0}".format(self.test_script))
  28. @slowTest
  29. def test_ssh_pre_flight(self):
  30. """
  31. test ssh when ssh_pre_flight is set
  32. ensure the script runs successfully
  33. """
  34. self._create_roster()
  35. ret = self.run_function("test.ping", roster_file=self.roster)
  36. assert os.path.exists(self.test_script)
  37. @slowTest
  38. def test_ssh_run_pre_flight(self):
  39. """
  40. test ssh when --pre-flight is passed to salt-ssh
  41. to ensure the script runs successfully
  42. """
  43. self._create_roster()
  44. # make sure we previously ran a command so the thin dir exists
  45. self.run_function("test.ping", wipe=False)
  46. assert not os.path.exists(self.test_script)
  47. ret = self.run_function(
  48. "test.ping", ssh_opts="--pre-flight", roster_file=self.roster, wipe=False
  49. )
  50. assert os.path.exists(self.test_script)
  51. def tearDown(self):
  52. """
  53. make sure to clean up any old ssh directories
  54. """
  55. files = [self.roster, self.data["ssh_pre_flight"], self.test_script]
  56. for fp_ in files:
  57. if os.path.exists(fp_):
  58. os.remove(fp_)