1
0

test_jobs.py 2.6 KB

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