test_jobs.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. # -*- coding: utf-8 -*-
  2. """
  3. Tests for the salt-run command
  4. """
  5. from __future__ import absolute_import, print_function, unicode_literals
  6. import pytest
  7. from tests.support.case import ShellCase
  8. from tests.support.unit import skipIf
  9. @pytest.mark.windows_whitelisted
  10. @pytest.mark.usefixtures("salt_sub_minion")
  11. class ManageTest(ShellCase):
  12. """
  13. Test the manage runner
  14. """
  15. @pytest.mark.slow_test(seconds=30) # Test takes >10 and <=30 seconds
  16. def test_active(self):
  17. """
  18. jobs.active
  19. """
  20. ret = self.run_run_plus("jobs.active")
  21. self.assertEqual(ret["return"], {})
  22. self.assertEqual(ret["out"], [])
  23. @pytest.mark.slow_test(seconds=10) # Test takes >5 and <=10 seconds
  24. def test_lookup_jid(self):
  25. """
  26. jobs.lookup_jid
  27. """
  28. ret = self.run_run_plus("jobs.lookup_jid", "23974239742394")
  29. self.assertEqual(ret["return"], {})
  30. self.assertEqual(ret["out"], [])
  31. @pytest.mark.slow_test(seconds=5) # Test takes >1 and <=5 seconds
  32. def test_lookup_jid_invalid(self):
  33. """
  34. jobs.lookup_jid
  35. """
  36. ret = self.run_run_plus("jobs.lookup_jid")
  37. expected = "Passed invalid arguments:"
  38. self.assertIn(expected, ret["return"])
  39. @skipIf(True, "to be re-enabled when #23623 is merged")
  40. def test_list_jobs(self):
  41. """
  42. jobs.list_jobs
  43. """
  44. ret = self.run_run_plus("jobs.list_jobs")
  45. self.assertIsInstance(ret["return"], dict)
  46. @pytest.mark.windows_whitelisted
  47. class LocalCacheTargetTest(ShellCase):
  48. """
  49. Test that a job stored in the local_cache has target information
  50. """
  51. @pytest.mark.slow_test(seconds=30) # Test takes >10 and <=30 seconds
  52. def test_target_info(self):
  53. """
  54. This is a test case for issue #48734
  55. PR #43454 fixed an issue where "jobs.lookup_jid" was not working
  56. correctly with external job caches. However, this fix for external
  57. job caches broke some inner workings of job storage when using the
  58. local_cache.
  59. We need to preserve the previous behavior for the local_cache, but
  60. keep the new behavior for other external job caches.
  61. If "savefstr" is called in the local cache, the target data does not
  62. get written to the local_cache, and the target-type gets listed as a
  63. "list" type instead of "glob".
  64. This is a regression test for fixing the local_cache behavior.
  65. """
  66. self.run_salt("minion test.echo target_info_test")
  67. ret = self.run_run_plus("jobs.list_jobs")
  68. for item in ret["return"].values():
  69. if (
  70. item["Function"] == "test.echo"
  71. and item["Arguments"][0] == "target_info_test"
  72. ):
  73. job_ret = item
  74. tgt = job_ret["Target"]
  75. tgt_type = job_ret["Target-type"]
  76. assert tgt != "unknown-target"
  77. assert tgt in ["minion", "sub_minion"]
  78. assert tgt_type == "glob"