test_extra_minion_data_in_pillar.py 2.2 KB

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