test_pillar.py 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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.runtests import RUNTIME_VARS
  6. @pytest.mark.windows_whitelisted
  7. class PillarModuleTest(ModuleCase):
  8. """
  9. Validate the pillar module
  10. """
  11. @pytest.mark.slow_test(seconds=30) # Test takes >10 and <=30 seconds
  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. @pytest.mark.slow_test(seconds=30) # Test takes >10 and <=30 seconds
  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. self.assertIn(
  33. RUNTIME_VARS.TMP_STATE_TREE,
  34. self.run_function("pillar.data")["master"]["file_roots"]["base"],
  35. )
  36. @pytest.mark.slow_test(seconds=30) # Test takes >10 and <=30 seconds
  37. def test_ext_cmd_yaml(self):
  38. """
  39. pillar.data for ext_pillar cmd.yaml
  40. """
  41. self.assertEqual(self.run_function("pillar.data")["ext_spam"], "eggs")
  42. @pytest.mark.slow_test(seconds=30) # Test takes >10 and <=30 seconds
  43. def test_issue_5951_actual_file_roots_in_opts(self):
  44. self.assertIn(
  45. RUNTIME_VARS.TMP_STATE_TREE,
  46. self.run_function("pillar.data")["ext_pillar_opts"]["file_roots"]["base"],
  47. )
  48. @pytest.mark.slow_test(seconds=30) # Test takes >10 and <=30 seconds
  49. def test_pillar_items(self):
  50. """
  51. Test to ensure we get expected output
  52. from pillar.items
  53. """
  54. get_items = self.run_function("pillar.items")
  55. self.assertDictContainsSubset({"monty": "python"}, get_items)
  56. self.assertDictContainsSubset(
  57. {"knights": ["Lancelot", "Galahad", "Bedevere", "Robin"]}, get_items
  58. )
  59. @pytest.mark.slow_test(seconds=30) # Test takes >10 and <=30 seconds
  60. def test_pillar_command_line(self):
  61. """
  62. Test to ensure when using pillar override
  63. on command line works
  64. """
  65. # test when pillar is overwriting previous pillar
  66. overwrite = self.run_function("pillar.items", pillar={"monty": "overwrite"})
  67. self.assertDictContainsSubset({"monty": "overwrite"}, overwrite)
  68. # test when using additional pillar
  69. additional = self.run_function("pillar.items", pillar={"new": "additional"})
  70. self.assertDictContainsSubset({"new": "additional"}, additional)