test_pillar.py 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. # -*- coding: utf-8 -*-
  2. # Import Python Libs
  3. from __future__ import absolute_import, print_function, unicode_literals
  4. # Import Salt Testing libs
  5. from tests.support.runtests import RUNTIME_VARS
  6. from tests.support.case import ModuleCase
  7. import pytest
  8. @pytest.mark.windows_whitelisted
  9. class PillarModuleTest(ModuleCase):
  10. '''
  11. Validate the pillar module
  12. '''
  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. 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. def test_ext_cmd_yaml(self):
  37. '''
  38. pillar.data for ext_pillar cmd.yaml
  39. '''
  40. self.assertEqual(
  41. self.run_function('pillar.data')['ext_spam'], 'eggs'
  42. )
  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. def test_pillar_items(self):
  49. '''
  50. Test to ensure we get expected output
  51. from pillar.items
  52. '''
  53. get_items = self.run_function('pillar.items')
  54. self.assertDictContainsSubset({'monty': 'python'}, get_items)
  55. self.assertDictContainsSubset(
  56. {'knights': ['Lancelot', 'Galahad', 'Bedevere', 'Robin']},
  57. get_items)
  58. def test_pillar_command_line(self):
  59. '''
  60. Test to ensure when using pillar override
  61. on command line works
  62. '''
  63. # test when pillar is overwriting previous pillar
  64. overwrite = self.run_function('pillar.items', pillar={"monty":
  65. "overwrite"})
  66. self.assertDictContainsSubset({'monty': 'overwrite'}, overwrite)
  67. # test when using additional pillar
  68. additional = self.run_function('pillar.items', pillar={"new":
  69. "additional"})
  70. self.assertDictContainsSubset({'new': 'additional'}, additional)