test_jobs.py 2.8 KB

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