test_pillar.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import pathlib
  2. import pytest
  3. from tests.support.case import ModuleCase
  4. from tests.support.helpers import slowTest
  5. from tests.support.runtests import RUNTIME_VARS
  6. @pytest.mark.windows_whitelisted
  7. class PillarModuleTest(ModuleCase):
  8. """
  9. Validate the pillar module
  10. """
  11. @slowTest
  12. def test_data(self):
  13. """
  14. pillar.data
  15. """
  16. grains = self.run_function("grains.items")
  17. pillar = self.run_function("pillar.data")
  18. self.assertEqual(pillar["os"], grains["os"])
  19. self.assertEqual(pillar["monty"], "python")
  20. if grains["os"] == "Fedora":
  21. self.assertEqual(pillar["class"], "redhat")
  22. else:
  23. self.assertEqual(pillar["class"], "other")
  24. @slowTest
  25. def test_issue_5449_report_actual_file_roots_in_pillar(self):
  26. """
  27. pillar['master']['file_roots'] is overwritten by the master
  28. in order to use the fileclient interface to read the pillar
  29. files. We should restore the actual file_roots when we send
  30. the pillar back to the minion.
  31. """
  32. file_roots = self.run_function("pillar.data")["master"]["file_roots"]["base"]
  33. self.assertIn(
  34. pathlib.Path(RUNTIME_VARS.TMP_STATE_TREE).resolve(),
  35. [pathlib.Path(p).resolve() for p in file_roots],
  36. )
  37. @slowTest
  38. def test_ext_cmd_yaml(self):
  39. """
  40. pillar.data for ext_pillar cmd.yaml
  41. """
  42. self.assertEqual(self.run_function("pillar.data")["ext_spam"], "eggs")
  43. @slowTest
  44. def test_issue_5951_actual_file_roots_in_opts(self):
  45. pillar_data = self.run_function("pillar.data")
  46. file_roots = pillar_data["ext_pillar_opts"]["file_roots"]["base"]
  47. self.assertIn(
  48. pathlib.Path(RUNTIME_VARS.TMP_STATE_TREE).resolve(),
  49. [pathlib.Path(p).resolve() for p in file_roots],
  50. )
  51. @slowTest
  52. def test_pillar_items(self):
  53. """
  54. Test to ensure we get expected output
  55. from pillar.items
  56. """
  57. get_items = self.run_function("pillar.items")
  58. self.assertDictContainsSubset({"monty": "python"}, get_items)
  59. self.assertDictContainsSubset(
  60. {"knights": ["Lancelot", "Galahad", "Bedevere", "Robin"]}, get_items
  61. )
  62. @slowTest
  63. def test_pillar_command_line(self):
  64. """
  65. Test to ensure when using pillar override
  66. on command line works
  67. """
  68. # test when pillar is overwriting previous pillar
  69. overwrite = self.run_function("pillar.items", pillar={"monty": "overwrite"})
  70. self.assertDictContainsSubset({"monty": "overwrite"}, overwrite)
  71. # test when using additional pillar
  72. additional = self.run_function("pillar.items", pillar={"new": "additional"})
  73. self.assertDictContainsSubset({"new": "additional"}, additional)