1
0

test_master.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. # -*- coding: utf-8 -*-
  2. # Import python libs
  3. from __future__ import absolute_import, unicode_literals
  4. # Import Salt Libs
  5. import salt.utils.master
  6. from tests.support.mock import patch
  7. # Import Salt Testing Libs
  8. from tests.support.unit import TestCase
  9. class MasterPillarUtilTestCase(TestCase):
  10. """
  11. TestCase for salt.utils.master.MasterPillarUtil methods
  12. """
  13. def test_get_minion_pillar(self):
  14. """
  15. test get_minion_pillar when
  16. target exists
  17. """
  18. opts = {"test": False}
  19. minion = "minion"
  20. pillar = salt.utils.master.MasterPillarUtil(
  21. tgt=minion, tgt_type="glob", opts=opts
  22. )
  23. grains_data = {minion: {"domain": ""}}
  24. pillar_data = {minion: {"test_pillar": "foo"}}
  25. patch_grain = patch(
  26. "salt.utils.master.MasterPillarUtil._get_minion_grains",
  27. return_value=grains_data,
  28. )
  29. patch_pillar = patch(
  30. "salt.utils.master.MasterPillarUtil._get_minion_pillar",
  31. return_value=pillar_data,
  32. )
  33. patch_tgt_list = patch(
  34. "salt.utils.master.MasterPillarUtil._tgt_to_list", return_value=[minion]
  35. )
  36. with patch_grain, patch_pillar, patch_tgt_list:
  37. ret = pillar.get_minion_pillar()
  38. assert ret[minion] == pillar_data[minion]
  39. def test_get_minion_pillar_doesnotexist(self):
  40. """
  41. test get_minion_pillar when
  42. target does not exist
  43. """
  44. opts = {"test": False}
  45. minion = "minion"
  46. pillar = salt.utils.master.MasterPillarUtil(
  47. tgt="doesnotexist", tgt_type="glob", opts=opts
  48. )
  49. grains_data = {minion: {"domain": ""}}
  50. pillar_data = {minion: {"test_pillar": "foo"}}
  51. patch_grain = patch(
  52. "salt.utils.master.MasterPillarUtil._get_minion_grains",
  53. return_value=grains_data,
  54. )
  55. patch_pillar = patch(
  56. "salt.utils.master.MasterPillarUtil._get_minion_pillar",
  57. return_value=pillar_data,
  58. )
  59. patch_tgt_list = patch(
  60. "salt.utils.master.MasterPillarUtil._tgt_to_list", return_value=[]
  61. )
  62. with patch_grain, patch_pillar, patch_tgt_list:
  63. ret = pillar.get_minion_pillar()
  64. assert minion not in ret
  65. def test_get_minion_pillar_notgt(self):
  66. """
  67. test get_minion_pillar when
  68. passing target None
  69. """
  70. opts = {"test": False}
  71. minion = "minion"
  72. pillar = salt.utils.master.MasterPillarUtil(
  73. tgt=None, tgt_type="glob", opts=opts
  74. )
  75. grains_data = {minion: {"domain": ""}}
  76. pillar_data = {minion: {"test_pillar": "foo"}}
  77. patch_grain = patch(
  78. "salt.utils.master.MasterPillarUtil._get_minion_grains",
  79. return_value=grains_data,
  80. )
  81. patch_pillar = patch(
  82. "salt.utils.master.MasterPillarUtil._get_minion_pillar",
  83. return_value=pillar_data,
  84. )
  85. patch_tgt_list = patch(
  86. "salt.utils.master.MasterPillarUtil._tgt_to_list", return_value=[]
  87. )
  88. with patch_grain, patch_pillar, patch_tgt_list:
  89. ret = pillar.get_minion_pillar()
  90. assert minion in ret