test_pillar.py 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. # -*- coding: utf-8 -*-
  2. from __future__ import absolute_import, print_function, unicode_literals
  3. import pytest
  4. from tests.support.case import ModuleCase
  5. from tests.support.helpers import slowTest
  6. from tests.support.runtests import RUNTIME_VARS
  7. @pytest.mark.windows_whitelisted
  8. class PillarModuleTest(ModuleCase):
  9. """
  10. Validate the pillar module
  11. """
  12. @slowTest
  13. def test_data(self):
  14. """
  15. pillar.data
  16. """
  17. grains = self.run_function("grains.items")
  18. pillar = self.run_function("pillar.data")
  19. self.assertEqual(pillar["os"], grains["os"])
  20. self.assertEqual(pillar["monty"], "python")
  21. if grains["os"] == "Fedora":
  22. self.assertEqual(pillar["class"], "redhat")
  23. else:
  24. self.assertEqual(pillar["class"], "other")
  25. @slowTest
  26. def test_issue_5449_report_actual_file_roots_in_pillar(self):
  27. """
  28. pillar['master']['file_roots'] is overwritten by the master
  29. in order to use the fileclient interface to read the pillar
  30. files. We should restore the actual file_roots when we send
  31. the pillar back to the minion.
  32. """
  33. self.assertIn(
  34. RUNTIME_VARS.TMP_STATE_TREE,
  35. self.run_function("pillar.data")["master"]["file_roots"]["base"],
  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. self.assertIn(
  46. RUNTIME_VARS.TMP_STATE_TREE,
  47. self.run_function("pillar.data")["ext_pillar_opts"]["file_roots"]["base"],
  48. )
  49. @slowTest
  50. def test_pillar_items(self):
  51. """
  52. Test to ensure we get expected output
  53. from pillar.items
  54. """
  55. get_items = self.run_function("pillar.items")
  56. self.assertDictContainsSubset({"monty": "python"}, get_items)
  57. self.assertDictContainsSubset(
  58. {"knights": ["Lancelot", "Galahad", "Bedevere", "Robin"]}, get_items
  59. )
  60. @slowTest
  61. def test_pillar_command_line(self):
  62. """
  63. Test to ensure when using pillar override
  64. on command line works
  65. """
  66. # test when pillar is overwriting previous pillar
  67. overwrite = self.run_function("pillar.items", pillar={"monty": "overwrite"})
  68. self.assertDictContainsSubset({"monty": "overwrite"}, overwrite)
  69. # test when using additional pillar
  70. additional = self.run_function("pillar.items", pillar={"new": "additional"})
  71. self.assertDictContainsSubset({"new": "additional"}, additional)