test_jobs.py 3.1 KB

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