test_pillar_include.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. # -*- coding: utf-8 -*-
  2. """
  3. Pillar include tests
  4. """
  5. from __future__ import absolute_import, unicode_literals
  6. import pytest
  7. @pytest.fixture(scope="module")
  8. def create_pillar_tree():
  9. glob_include_fname = "glob_include.sls"
  10. glob_include_contents = """
  11. include:
  12. - 'glob_include*'
  13. """
  14. glob_include_a_fname = "glob_include_a.sls"
  15. glob_include_a_contents = """
  16. glob-a:
  17. - 'Entry A'
  18. """
  19. glob_include_b_fname = "glob_include_b.sls"
  20. glob_include_b_contents = """
  21. glob-b:
  22. - 'Entry B'
  23. """
  24. include_fname = "include.sls"
  25. include_contents = """
  26. include:
  27. - include-a:
  28. key: element:a
  29. - include-b:
  30. key: element:b
  31. """
  32. include_a_fname = "include-a.sls"
  33. include_a_contents = """
  34. a:
  35. - 'Entry A'
  36. """
  37. include_b_fname = "include-b.sls"
  38. include_b_contents = """
  39. b:
  40. - 'Entry B'
  41. """
  42. top_contents = """
  43. base:
  44. 'minion':
  45. - include
  46. - glob_include
  47. """
  48. with pytest.helpers.temp_pillar_file(
  49. "top.sls", top_contents
  50. ), pytest.helpers.temp_pillar_file(
  51. glob_include_fname, glob_include_contents
  52. ), pytest.helpers.temp_pillar_file(
  53. glob_include_a_fname, glob_include_a_contents
  54. ), pytest.helpers.temp_pillar_file(
  55. glob_include_b_fname, glob_include_b_contents
  56. ), pytest.helpers.temp_pillar_file(
  57. include_fname, include_contents
  58. ), pytest.helpers.temp_pillar_file(
  59. include_a_fname, include_a_contents
  60. ), pytest.helpers.temp_pillar_file(
  61. include_b_fname, include_b_contents
  62. ):
  63. yield
  64. @pytest.fixture(scope="module")
  65. def pillar_items(salt_cli, create_pillar_tree):
  66. ret = salt_cli.run("pillar.items", minion_tgt="minion")
  67. assert ret.exitcode == 0, ret
  68. return ret.json
  69. class TestPillarIncludeTest(object):
  70. def test_pillar_include(self, pillar_items):
  71. """
  72. Test pillar include
  73. """
  74. assert "a" in pillar_items["element"]
  75. assert pillar_items["element"]["a"] == {"a": ["Entry A"]}
  76. assert "b" in pillar_items["element"]
  77. assert pillar_items["element"]["b"] == {"b": ["Entry B"]}
  78. def test_pillar_glob_include(self, pillar_items):
  79. """
  80. Test pillar include via glob pattern
  81. """
  82. assert "glob-a" in pillar_items
  83. assert pillar_items["glob-a"] == ["Entry A"]
  84. assert "glob-b" in pillar_items
  85. assert pillar_items["glob-b"] == ["Entry B"]