1
0

test_minion_cache.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # -*- coding: utf-8 -*-
  2. from __future__ import absolute_import, unicode_literals
  3. import os
  4. import salt.loader
  5. import salt.minion
  6. import salt.utils.yaml
  7. from salt.utils.files import fopen
  8. from tests.support.case import ModuleCase
  9. from tests.support.helpers import with_tempdir
  10. from tests.support.mock import patch
  11. class BasePillarTest(ModuleCase):
  12. @with_tempdir()
  13. def test_minion_cache_should_cache_files(self, tempdir):
  14. pillar = {"this": {"is": {"some": "pillar data"}}}
  15. opts = {
  16. "file_client": "remote",
  17. "minion_pillar_cache": "true",
  18. "master_type": "local",
  19. "discovery": False,
  20. "master": "local",
  21. "__role": "",
  22. "id": "test",
  23. "saltenv": "base",
  24. "pillar_cache": True,
  25. "pillar_cache_backend": "disk",
  26. "pillar_cache_ttl": 3600,
  27. "cachedir": tempdir,
  28. "state_top": "top.sls",
  29. "pillar_roots": {"base": tempdir},
  30. "extension_modules": tempdir,
  31. "file_ignore_regex": [],
  32. "file_ignore_glob": [],
  33. "pillar": pillar,
  34. }
  35. with patch("salt.loader.grains", return_value={}), patch(
  36. "salt.minion.SMinion.gen_modules"
  37. ), patch("salt.minion.SMinion.eval_master"), patch(
  38. "salt.minion.install_zmq"
  39. ), patch(
  40. "salt.minion.ZMQDefaultLoop.current"
  41. ):
  42. minion = salt.minion.SMinion(opts)
  43. self.assertTrue("pillar" in os.listdir(tempdir))
  44. pillar_cache = os.path.join(tempdir, "pillar")
  45. self.assertTrue("top.sls" in os.listdir(pillar_cache))
  46. self.assertTrue("cache.sls" in os.listdir(pillar_cache))
  47. with fopen(os.path.join(pillar_cache, "cache.sls"), "rb") as f:
  48. cached_data = salt.utils.yaml.safe_load(f)
  49. assert cached_data == pillar