test_cache.py 3.7 KB

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