test_jobs.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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.helpers import slowTest
  9. @pytest.mark.windows_whitelisted
  10. @pytest.mark.usefixtures("salt_sub_minion")
  11. class JobsTest(ShellCase):
  12. """
  13. Test the jobs runner.
  14. """
  15. @slowTest
  16. def test_master(self):
  17. """
  18. jobs.master
  19. """
  20. ret = self.run_run_plus("jobs.master", _output="json")
  21. self.assertEqual(ret["return"], [])
  22. self.assertEqual(ret["out"], [])
  23. @slowTest
  24. def test_active(self):
  25. """
  26. jobs.active
  27. """
  28. ret = self.run_run_plus("jobs.active", _output="json")
  29. self.assertEqual(ret["return"], {})
  30. self.assertEqual(ret["out"], {})
  31. @slowTest
  32. def test_lookup_jid(self):
  33. """
  34. jobs.lookup_jid
  35. """
  36. ret = self.run_run_plus("jobs.lookup_jid", "23974239742394", _output="json")
  37. self.assertEqual(ret["return"], {})
  38. self.assertEqual(ret["out"], {})
  39. @slowTest
  40. def test_lookup_jid_invalid(self):
  41. """
  42. jobs.lookup_jid
  43. """
  44. ret = self.run_run_plus("jobs.lookup_jid", _output="json")
  45. expected = "Passed invalid arguments:"
  46. self.assertIn(expected, ret["return"])
  47. @slowTest
  48. def test_list_jobs(self):
  49. """
  50. jobs.list_jobs
  51. """
  52. self.run_salt("minion test.echo test_list_jobs")
  53. ret = self.run_run_plus("jobs.list_jobs", _output="json")
  54. self.assertIsInstance(ret["return"], dict)
  55. for job in ret["return"].values():
  56. if job["Function"] != "test.echo":
  57. continue
  58. if job["Arguments"] != ["test_list_jobs"]:
  59. continue
  60. # We our job in the list, we're good with the test
  61. break
  62. else:
  63. self.fail("Did not our job from the jobs.list_jobs call")
  64. @pytest.mark.windows_whitelisted
  65. class LocalCacheTargetTest(ShellCase):
  66. """
  67. Test that a job stored in the local_cache has target information
  68. """
  69. @slowTest
  70. def test_target_info(self):
  71. """
  72. This is a test case for issue #48734
  73. PR #43454 fixed an issue where "jobs.lookup_jid" was not working
  74. correctly with external job caches. However, this fix for external
  75. job caches broke some inner workings of job storage when using the
  76. local_cache.
  77. We need to preserve the previous behavior for the local_cache, but
  78. keep the new behavior for other external job caches.
  79. If "savefstr" is called in the local cache, the target data does not
  80. get written to the local_cache, and the target-type gets listed as a
  81. "list" type instead of "glob".
  82. This is a regression test for fixing the local_cache behavior.
  83. """
  84. self.run_salt("minion test.echo target_info_test")
  85. ret = self.run_run_plus("jobs.list_jobs", _output="json")
  86. for item in ret["return"].values():
  87. if (
  88. item["Function"] == "test.echo"
  89. and item["Arguments"][0] == "target_info_test"
  90. ):
  91. job_ret = item
  92. tgt = job_ret["Target"]
  93. tgt_type = job_ret["Target-type"]
  94. assert tgt != "unknown-target"
  95. assert tgt in ["minion", "sub_minion"]
  96. assert tgt_type == "glob"