1
0

test_cache.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. import logging
  10. log = logging.getLogger(__name__)
  11. class ManageTest(ShellCase):
  12. '''
  13. Test the manage runner
  14. '''
  15. def test_cache(self):
  16. '''
  17. Store, list, fetch, then flush data
  18. '''
  19. # Store the data
  20. ret = self.run_run_plus(
  21. 'cache.store',
  22. bank='cachetest/runner',
  23. key='test_cache',
  24. data='The time has come the walrus said',
  25. )
  26. # Make sure we can see the new key
  27. ret = self.run_run_plus('cache.list', bank='cachetest/runner')
  28. self.assertIn('test_cache', ret['return'])
  29. # Make sure we can see the new data
  30. ret = self.run_run_plus('cache.fetch', bank='cachetest/runner', key='test_cache')
  31. self.assertIn('The time has come the walrus said', ret['return'])
  32. # Make sure we can delete the data
  33. ret = self.run_run_plus('cache.flush', bank='cachetest/runner', key='test_cache')
  34. ret = self.run_run_plus('cache.list', bank='cachetest/runner')
  35. self.assertNotIn('test_cache', ret['return'])
  36. def test_cache_invalid(self):
  37. '''
  38. Store, list, fetch, then flush data
  39. '''
  40. # Store the data
  41. ret = self.run_run_plus(
  42. 'cache.store',
  43. )
  44. # Make sure we can see the new key
  45. expected = 'Passed invalid arguments:'
  46. self.assertIn(expected, ret['return'])
  47. def test_grains(self):
  48. '''
  49. Test cache.grains
  50. '''
  51. # Store the data
  52. ret = self.run_run_plus(
  53. 'cache.grains',
  54. tgt='minion'
  55. )
  56. self.assertIn('minion', ret['return'])
  57. def test_pillar(self):
  58. '''
  59. Test cache.pillar
  60. '''
  61. # Store the data
  62. ret = self.run_run_plus(
  63. 'cache.pillar',
  64. tgt='minion'
  65. )
  66. assert 'minion' in ret['return']
  67. assert 'sub_minion' not in ret['return']
  68. def test_pillar_no_tgt(self):
  69. '''
  70. Test cache.pillar when no tgt is
  71. supplied. This should return pillar
  72. data for all minions
  73. '''
  74. # Store the data
  75. ret = self.run_run_plus(
  76. 'cache.pillar',
  77. )
  78. assert all(x in ret['return'] for x in ['minion', 'sub_minion'])
  79. def test_pillar_minion_noexist(self):
  80. '''
  81. Test cache.pillar when the target does not exist
  82. '''
  83. ret = self.run_run_plus(
  84. 'cache.pillar',
  85. tgt='doesnotexist'
  86. )
  87. assert 'minion' not in ret['return']
  88. assert 'sub_minion' not in ret['return']
  89. def test_pillar_minion_tgt_type_pillar(self):
  90. '''
  91. Test cache.pillar when the target exists
  92. and tgt_type is pillar
  93. '''
  94. ret = self.run_run_plus(
  95. 'cache.pillar',
  96. tgt='monty:python',
  97. tgt_type='pillar',
  98. )
  99. assert all(x in ret['return'] for x in ['minion', 'sub_minion'])
  100. def test_mine(self):
  101. '''
  102. Test cache.mine
  103. '''
  104. # Store the data
  105. ret = self.run_run_plus(
  106. 'cache.mine',
  107. tgt='minion'
  108. )
  109. self.assertIn('minion', ret['return'])