1
0

test_publish.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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.case import ModuleCase
  6. from tests.support.mixins import SaltReturnAssertsMixin
  7. import pytest
  8. @pytest.mark.windows_whitelisted
  9. class PublishModuleTest(ModuleCase, SaltReturnAssertsMixin):
  10. '''
  11. Validate the publish module
  12. '''
  13. def test_publish(self):
  14. '''
  15. publish.publish
  16. '''
  17. ret = self.run_function(
  18. 'publish.publish',
  19. ['minion', 'test.ping'],
  20. f_timeout=50
  21. )
  22. self.assertEqual(ret, {'minion': True})
  23. ret = self.run_function(
  24. 'publish.publish',
  25. ['minion', 'test.kwarg'],
  26. f_arg='cheese=spam',
  27. f_timeout=50
  28. )
  29. ret = ret['minion']
  30. check_true = (
  31. 'cheese',
  32. '__pub_arg',
  33. '__pub_fun',
  34. '__pub_id',
  35. '__pub_jid',
  36. '__pub_ret',
  37. '__pub_tgt',
  38. '__pub_tgt_type',
  39. )
  40. for name in check_true:
  41. if name not in ret:
  42. print(name)
  43. self.assertTrue(name in ret)
  44. self.assertEqual(ret['cheese'], 'spam')
  45. self.assertEqual(ret['__pub_arg'], [{'cheese': 'spam'}])
  46. self.assertEqual(ret['__pub_id'], 'minion')
  47. self.assertEqual(ret['__pub_fun'], 'test.kwarg')
  48. def test_publish_yaml_args(self):
  49. '''
  50. test publish.publish yaml args formatting
  51. '''
  52. ret = self.run_function(
  53. 'publish.publish',
  54. ['minion', 'test.ping'],
  55. f_timeout=50
  56. )
  57. self.assertEqual(ret, {'minion': True})
  58. test_args_list = ['saltines, si', 'crackers, nein', 'cheese, indeed']
  59. test_args = '["{args[0]}", "{args[1]}", "{args[2]}"]'.format(args=test_args_list)
  60. ret = self.run_function(
  61. 'publish.publish',
  62. ['minion', 'test.arg', test_args],
  63. f_timeout=50
  64. )
  65. ret = ret['minion']
  66. check_true = (
  67. '__pub_arg',
  68. '__pub_fun',
  69. '__pub_id',
  70. '__pub_jid',
  71. '__pub_ret',
  72. '__pub_tgt',
  73. '__pub_tgt_type',
  74. )
  75. for name in check_true:
  76. if name not in ret['kwargs']:
  77. print(name)
  78. self.assertTrue(name in ret['kwargs'])
  79. self.assertEqual(ret['args'], test_args_list)
  80. self.assertEqual(ret['kwargs']['__pub_id'], 'minion')
  81. self.assertEqual(ret['kwargs']['__pub_fun'], 'test.arg')
  82. def test_full_data(self):
  83. '''
  84. publish.full_data
  85. '''
  86. ret = self.run_function(
  87. 'publish.full_data',
  88. ['minion', 'test.fib', 20],
  89. f_timeout=50
  90. )
  91. self.assertTrue(ret)
  92. self.assertEqual(ret['minion']['ret'][0], 6765)
  93. def test_kwarg(self):
  94. '''
  95. Verify that the pub data is making it to the minion functions
  96. '''
  97. ret = self.run_function(
  98. 'publish.full_data',
  99. ['minion', 'test.kwarg'],
  100. f_arg='cheese=spam',
  101. f_timeout=50
  102. )
  103. ret = ret['minion']['ret']
  104. check_true = (
  105. 'cheese',
  106. '__pub_arg',
  107. '__pub_fun',
  108. '__pub_id',
  109. '__pub_jid',
  110. '__pub_ret',
  111. '__pub_tgt',
  112. '__pub_tgt_type',
  113. )
  114. for name in check_true:
  115. if name not in ret:
  116. print(name)
  117. self.assertTrue(name in ret)
  118. self.assertEqual(ret['cheese'], 'spam')
  119. self.assertEqual(ret['__pub_arg'], [{'cheese': 'spam'}])
  120. self.assertEqual(ret['__pub_id'], 'minion')
  121. self.assertEqual(ret['__pub_fun'], 'test.kwarg')
  122. ret = self.run_function(
  123. 'publish.full_data',
  124. ['minion', 'test.kwarg'],
  125. cheese='spam',
  126. f_timeout=50
  127. )
  128. self.assertIn(
  129. 'The following keyword arguments are not valid', ret
  130. )
  131. def test_reject_minion(self):
  132. '''
  133. Test bad authentication
  134. '''
  135. ret = self.run_function(
  136. 'publish.publish',
  137. ['minion', 'cmd.run', ['echo foo']],
  138. f_timeout=50
  139. )
  140. self.assertEqual(ret, {})