test_pillar_include.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. """
  2. Pillar include tests
  3. """
  4. import pytest
  5. @pytest.fixture(scope="module")
  6. def pillar_include_tree(base_env_pillar_tree_root_dir, salt_minion, salt_call_cli):
  7. top_file = """
  8. base:
  9. '{}':
  10. - include
  11. - glob-include
  12. """.format(
  13. salt_minion.id
  14. )
  15. include_pillar_file = """
  16. include:
  17. - include-a:
  18. key: element:a
  19. - include-b:
  20. key: element:b
  21. """
  22. include_a_pillar_file = """
  23. a:
  24. - 'Entry A'
  25. """
  26. include_b_pillar_file = """
  27. b:
  28. - 'Entry B'
  29. """
  30. top_tempfile = pytest.helpers.temp_file(
  31. "top.sls", top_file, base_env_pillar_tree_root_dir
  32. )
  33. include_tempfile = pytest.helpers.temp_file(
  34. "include.sls", include_pillar_file, base_env_pillar_tree_root_dir
  35. )
  36. include_a_tempfile = pytest.helpers.temp_file(
  37. "include-a.sls", include_a_pillar_file, base_env_pillar_tree_root_dir
  38. )
  39. include_b_tempfile = pytest.helpers.temp_file(
  40. "include-b.sls", include_b_pillar_file, base_env_pillar_tree_root_dir
  41. )
  42. glob_include_pillar_file = """
  43. include:
  44. - 'glob-include-*'
  45. """
  46. glob_include_a_pillar_file = """
  47. glob-a:
  48. - 'Entry A'
  49. """
  50. glob_include_b_pillar_file = """
  51. glob-b:
  52. - 'Entry B'
  53. """
  54. top_tempfile = pytest.helpers.temp_file(
  55. "top.sls", top_file, base_env_pillar_tree_root_dir
  56. )
  57. glob_include_tempfile = pytest.helpers.temp_file(
  58. "glob-include.sls", glob_include_pillar_file, base_env_pillar_tree_root_dir
  59. )
  60. glob_include_a_tempfile = pytest.helpers.temp_file(
  61. "glob-include-a.sls", glob_include_a_pillar_file, base_env_pillar_tree_root_dir
  62. )
  63. glob_include_b_tempfile = pytest.helpers.temp_file(
  64. "glob-include-b.sls", glob_include_b_pillar_file, base_env_pillar_tree_root_dir
  65. )
  66. try:
  67. with top_tempfile, include_tempfile, include_a_tempfile, include_b_tempfile:
  68. with glob_include_tempfile, glob_include_a_tempfile, glob_include_b_tempfile:
  69. ret = salt_call_cli.run("saltutil.refresh_pillar", wait=True)
  70. assert ret.exitcode == 0
  71. assert ret.json is True
  72. yield
  73. finally:
  74. # Refresh pillar again to cleaup the temp pillar
  75. ret = salt_call_cli.run("saltutil.refresh_pillar", wait=True)
  76. assert ret.exitcode == 0
  77. assert ret.json is True
  78. def test_pillar_include(pillar_include_tree, salt_call_cli):
  79. """
  80. Test pillar include
  81. """
  82. ret = salt_call_cli.run("pillar.items")
  83. assert ret.exitcode == 0
  84. assert ret.json
  85. assert "element" in ret.json
  86. assert "a" in ret.json["element"]
  87. assert ret.json["element"]["a"] == {"a": ["Entry A"]}
  88. assert "b" in ret.json["element"]
  89. assert ret.json["element"]["b"] == {"b": ["Entry B"]}
  90. def test_pillar_glob_include(pillar_include_tree, salt_call_cli):
  91. """
  92. Test pillar include via glob pattern
  93. """
  94. ret = salt_call_cli.run("pillar.items")
  95. assert ret.exitcode == 0
  96. assert ret.json
  97. assert "glob-a" in ret.json
  98. assert ret.json["glob-a"] == ["Entry A"]
  99. assert "glob-b" in ret.json
  100. assert ret.json["glob-b"] == ["Entry B"]