1
0

test_publish.py 4.2 KB

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