test_extra_minion_data_in_pillar.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. # -*- coding: utf-8 -*-
  2. # Import python libs
  3. from __future__ import absolute_import, print_function, unicode_literals
  4. # Import Salt Libs
  5. from salt.pillar import extra_minion_data_in_pillar
  6. # Import Salt Testing libs
  7. from tests.support.mixins import LoaderModuleMockMixin
  8. from tests.support.mock import MagicMock
  9. from tests.support.unit import TestCase
  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 {extra_minion_data_in_pillar: {"__virtual__": True}}
  16. def setUp(self):
  17. self.pillar = MagicMock()
  18. self.extra_minion_data = {
  19. "key1": {"subkey1": "value1"},
  20. "key2": {"subkey2": {"subsubkey2": "value2"}},
  21. "key3": "value3",
  22. "key4": {"subkey4": "value4"},
  23. }
  24. def test_extra_values_none_or_empty(self):
  25. ret = extra_minion_data_in_pillar.ext_pillar(
  26. "fake_id", self.pillar, "fake_include", None
  27. )
  28. self.assertEqual(ret, {})
  29. ret = extra_minion_data_in_pillar.ext_pillar(
  30. "fake_id", self.pillar, "fake_include", {}
  31. )
  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. )
  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",
  43. self.pillar,
  44. include=["key1:subkey1", "key2:subkey3", "key3", "key4"],
  45. extra_minion_data=self.extra_minion_data,
  46. )
  47. self.assertEqual(
  48. ret,
  49. {
  50. "key1": {"subkey1": "value1"},
  51. "key3": "value3",
  52. "key4": {"subkey4": "value4"},
  53. },
  54. )