test_extra_minion_data_in_pillar.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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.mixins import LoaderModuleMockMixin
  6. from tests.support.unit import TestCase
  7. from tests.support.mock import MagicMock
  8. # Import Salt Libs
  9. from salt.pillar import extra_minion_data_in_pillar
  10. class ExtraMinionDataInPillarTestCase(TestCase, LoaderModuleMockMixin):
  11. '''
  12. Test cases for salt.pillar.extra_minion_data_in_pillar
  13. '''
  14. def setup_loader_modules(self):
  15. return {
  16. extra_minion_data_in_pillar: {
  17. '__virtual__': True,
  18. }
  19. }
  20. def setUp(self):
  21. self.pillar = MagicMock()
  22. self.extra_minion_data = {'key1': {'subkey1': 'value1'},
  23. 'key2': {'subkey2': {'subsubkey2': 'value2'}},
  24. 'key3': 'value3',
  25. 'key4': {'subkey4': 'value4'}}
  26. def test_extra_values_none_or_empty(self):
  27. ret = extra_minion_data_in_pillar.ext_pillar('fake_id', self.pillar,
  28. 'fake_include', None)
  29. self.assertEqual(ret, {})
  30. ret = extra_minion_data_in_pillar.ext_pillar('fake_id', self.pillar,
  31. 'fake_include', {})
  32. self.assertEqual(ret, {})
  33. def test_include_all(self):
  34. for include_all in ['*', '<all>']:
  35. ret = extra_minion_data_in_pillar.ext_pillar(
  36. 'fake_id', self.pillar, include_all, self.extra_minion_data)
  37. self.assertEqual(ret, self.extra_minion_data)
  38. def test_include_specific_keys(self):
  39. # Tests partially existing key, key with and without subkey,
  40. ret = extra_minion_data_in_pillar.ext_pillar(
  41. 'fake_id', self.pillar,
  42. include=['key1:subkey1', 'key2:subkey3', 'key3', 'key4'],
  43. extra_minion_data=self.extra_minion_data)
  44. self.assertEqual(ret, {'key1': {'subkey1': 'value1'},
  45. 'key3': 'value3',
  46. 'key4': {'subkey4': 'value4'}})