1
0

test_pillar.py 2.7 KB

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