test_master.py 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. # Import Salt Testing Libs
  7. from tests.support.unit import TestCase
  8. from tests.support.mock import patch
  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(tgt=minion,
  21. tgt_type='glob',
  22. opts=opts)
  23. grains_data = {minion: {'domain': ''}}
  24. pillar_data = {minion: {'test_pillar': 'foo'}}
  25. patch_grain = patch('salt.utils.master.MasterPillarUtil._get_minion_grains',
  26. return_value=grains_data)
  27. patch_pillar = patch('salt.utils.master.MasterPillarUtil._get_minion_pillar',
  28. return_value=pillar_data)
  29. patch_tgt_list = patch('salt.utils.master.MasterPillarUtil._tgt_to_list',
  30. return_value=[minion])
  31. with patch_grain, patch_pillar, patch_tgt_list:
  32. ret = pillar.get_minion_pillar()
  33. assert ret[minion] == pillar_data[minion]
  34. def test_get_minion_pillar_doesnotexist(self):
  35. '''
  36. test get_minion_pillar when
  37. target does not exist
  38. '''
  39. opts = {'test': False}
  40. minion = 'minion'
  41. pillar = salt.utils.master.MasterPillarUtil(tgt='doesnotexist',
  42. tgt_type='glob',
  43. opts=opts)
  44. grains_data = {minion: {'domain': ''}}
  45. pillar_data = {minion: {'test_pillar': 'foo'}}
  46. patch_grain = patch('salt.utils.master.MasterPillarUtil._get_minion_grains',
  47. return_value=grains_data)
  48. patch_pillar = patch('salt.utils.master.MasterPillarUtil._get_minion_pillar',
  49. return_value=pillar_data)
  50. patch_tgt_list = patch('salt.utils.master.MasterPillarUtil._tgt_to_list',
  51. return_value=[])
  52. with patch_grain, patch_pillar, patch_tgt_list:
  53. ret = pillar.get_minion_pillar()
  54. assert minion not in ret
  55. def test_get_minion_pillar_notgt(self):
  56. '''
  57. test get_minion_pillar when
  58. passing target None
  59. '''
  60. opts = {'test': False}
  61. minion = 'minion'
  62. pillar = salt.utils.master.MasterPillarUtil(tgt=None,
  63. tgt_type='glob',
  64. opts=opts)
  65. grains_data = {minion: {'domain': ''}}
  66. pillar_data = {minion: {'test_pillar': 'foo'}}
  67. patch_grain = patch('salt.utils.master.MasterPillarUtil._get_minion_grains',
  68. return_value=grains_data)
  69. patch_pillar = patch('salt.utils.master.MasterPillarUtil._get_minion_pillar',
  70. return_value=pillar_data)
  71. patch_tgt_list = patch('salt.utils.master.MasterPillarUtil._tgt_to_list',
  72. return_value=[])
  73. with patch_grain, patch_pillar, patch_tgt_list:
  74. ret = pillar.get_minion_pillar()
  75. assert minion in ret