test_standard.py 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. # -*- coding: utf-8 -*-
  2. from __future__ import absolute_import, print_function, unicode_literals
  3. import os
  4. import pytest
  5. import salt.utils.files
  6. import salt.utils.platform
  7. from tests.support.case import ModuleCase
  8. from tests.support.unit import skipIf
  9. @pytest.mark.windows_whitelisted
  10. class StdTest(ModuleCase):
  11. """
  12. Test standard client calls
  13. """
  14. def setUp(self):
  15. self.TIMEOUT = 600 if salt.utils.platform.is_windows() else 10
  16. @skipIf(True, "SLOWTEST skip")
  17. def test_cli(self):
  18. """
  19. Test cli function
  20. """
  21. cmd_iter = self.client.cmd_cli("minion", "test.ping", timeout=20,)
  22. for ret in cmd_iter:
  23. self.assertTrue(ret["minion"])
  24. # make sure that the iter waits for long running jobs too
  25. cmd_iter = self.client.cmd_cli("minion", "test.sleep", [6], timeout=20,)
  26. num_ret = 0
  27. for ret in cmd_iter:
  28. num_ret += 1
  29. self.assertTrue(ret["minion"])
  30. assert num_ret > 0
  31. # ping a minion that doesn't exist, to make sure that it doesn't hang forever
  32. # create fake minion
  33. key_file = os.path.join(self.master_opts["pki_dir"], "minions", "footest")
  34. # touch the file
  35. with salt.utils.files.fopen(key_file, "a"):
  36. pass
  37. # ping that minion and ensure it times out
  38. try:
  39. cmd_iter = self.client.cmd_cli("footest", "test.ping", timeout=20,)
  40. num_ret = 0
  41. for ret in cmd_iter:
  42. num_ret += 1
  43. self.assertTrue(ret["minion"])
  44. assert num_ret == 0
  45. finally:
  46. os.unlink(key_file)
  47. @skipIf(True, "SLOWTEST skip")
  48. def test_iter(self):
  49. """
  50. test cmd_iter
  51. """
  52. cmd_iter = self.client.cmd_iter("minion", "test.ping",)
  53. for ret in cmd_iter:
  54. self.assertTrue(ret["minion"])
  55. @skipIf(True, "SLOWTEST skip")
  56. def test_iter_no_block(self):
  57. """
  58. test cmd_iter_no_block
  59. """
  60. cmd_iter = self.client.cmd_iter_no_block("minion", "test.ping",)
  61. for ret in cmd_iter:
  62. if ret is None:
  63. continue
  64. self.assertTrue(ret["minion"])
  65. @skipIf(True, "SLOWTEST skip")
  66. def test_batch(self):
  67. """
  68. test cmd_batch
  69. """
  70. cmd_batch = self.client.cmd_batch("minion", "test.ping",)
  71. for ret in cmd_batch:
  72. self.assertTrue(ret["minion"])
  73. @skipIf(True, "SLOWTEST skip")
  74. def test_batch_raw(self):
  75. """
  76. test cmd_batch with raw option
  77. """
  78. cmd_batch = self.client.cmd_batch("minion", "test.ping", raw=True,)
  79. for ret in cmd_batch:
  80. self.assertTrue(ret["data"]["success"])
  81. @skipIf(True, "SLOWTEST skip")
  82. def test_full_returns(self):
  83. """
  84. test cmd_iter
  85. """
  86. ret = self.client.cmd_full_return("minion", "test.ping", timeout=20,)
  87. self.assertIn("minion", ret)
  88. self.assertEqual({"ret": True, "success": True}, ret["minion"])
  89. @skipIf(True, "SLOWTEST skip")
  90. def test_disconnected_return(self):
  91. """
  92. Test return/messaging on a disconnected minion
  93. """
  94. test_ret = "Minion did not return. [No response]"
  95. test_out = "no_return"
  96. # Create a minion key, but do not start the "fake" minion. This mimics
  97. # a disconnected minion.
  98. key_file = os.path.join(self.master_opts["pki_dir"], "minions", "disconnected")
  99. with salt.utils.files.fopen(key_file, "a"):
  100. pass
  101. # ping disconnected minion and ensure it times out and returns with correct message
  102. try:
  103. cmd_iter = self.client.cmd_cli(
  104. "disconnected", "test.ping", show_timeout=True
  105. )
  106. num_ret = 0
  107. for ret in cmd_iter:
  108. num_ret += 1
  109. assert ret["disconnected"]["ret"].startswith(test_ret), ret[
  110. "disconnected"
  111. ]["ret"]
  112. assert ret["disconnected"]["out"] == test_out, ret["disconnected"][
  113. "out"
  114. ]
  115. # Ensure that we entered the loop above
  116. self.assertEqual(num_ret, 1)
  117. finally:
  118. os.unlink(key_file)
  119. @skipIf(True, "SLOWTEST skip")
  120. def test_missing_minion_list(self):
  121. """
  122. test cmd with missing minion in nodegroup
  123. """
  124. ret = self.client.cmd("minion,ghostminion", "test.ping", tgt_type="list")
  125. assert "minion" in ret
  126. assert "ghostminion" in ret
  127. assert ret["minion"] is True
  128. assert ret["ghostminion"].startswith(
  129. "Minion did not return. [No response]"
  130. ), ret["ghostminion"]
  131. @skipIf(True, "SLOWTEST skip")
  132. def test_missing_minion_nodegroup(self):
  133. """
  134. test cmd with missing minion in nodegroup
  135. """
  136. ret = self.client.cmd("missing_minion", "test.ping", tgt_type="nodegroup")
  137. assert "minion" in ret
  138. assert "ghostminion" in ret
  139. assert ret["minion"] is True
  140. assert ret["ghostminion"].startswith(
  141. "Minion did not return. [No response]"
  142. ), ret["ghostminion"]