test_cache.py 3.3 KB

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