1
0

test_runner.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. # coding: utf-8
  2. from __future__ import absolute_import, print_function, unicode_literals
  3. import pytest
  4. import salt.runner
  5. from tests.support.helpers import slowTest
  6. from tests.support.mixins import AdaptedConfigurationTestCaseMixin
  7. from tests.support.unit import TestCase
  8. @pytest.mark.windows_whitelisted
  9. class RunnerModuleTest(TestCase, AdaptedConfigurationTestCaseMixin):
  10. # This is really an integration test since it needs a salt-master running
  11. eauth_creds = {
  12. "username": "saltdev_auto",
  13. "password": "saltdev",
  14. "eauth": "auto",
  15. }
  16. def setUp(self):
  17. """
  18. Configure an eauth user to test with
  19. """
  20. self.runner = salt.runner.RunnerClient(self.get_config("client_config"))
  21. @slowTest
  22. def test_eauth(self):
  23. """
  24. Test executing master_call with lowdata
  25. The choice of using error.error for this is arbitrary and should be
  26. changed to some mocked function that is more testing friendly.
  27. """
  28. low = {
  29. "client": "runner",
  30. "fun": "error.error",
  31. }
  32. low.update(self.eauth_creds)
  33. self.runner.master_call(**low)
  34. @slowTest
  35. def test_token(self):
  36. """
  37. Test executing master_call with lowdata
  38. The choice of using error.error for this is arbitrary and should be
  39. changed to some mocked function that is more testing friendly.
  40. """
  41. import salt.auth
  42. auth = salt.auth.LoadAuth(self.get_config("client_config"))
  43. token = auth.mk_token(self.eauth_creds)
  44. self.runner.master_call(
  45. **{"client": "runner", "fun": "error.error", "token": token["token"]}
  46. )
  47. @slowTest
  48. def test_cmd_sync(self):
  49. low = {
  50. "client": "runner",
  51. "fun": "error.error",
  52. }
  53. low.update(self.eauth_creds)
  54. self.runner.cmd_sync(low)
  55. @slowTest
  56. def test_cmd_async(self):
  57. low = {
  58. "client": "runner",
  59. "fun": "error.error",
  60. }
  61. low.update(self.eauth_creds)
  62. self.runner.cmd_async(low)
  63. @slowTest
  64. def test_cmd_sync_w_arg(self):
  65. low = {
  66. "fun": "test.arg",
  67. "foo": "Foo!",
  68. "bar": "Bar!",
  69. }
  70. low.update(self.eauth_creds)
  71. ret = self.runner.cmd_sync(low)
  72. self.assertEqual(ret["kwargs"]["foo"], "Foo!")
  73. self.assertEqual(ret["kwargs"]["bar"], "Bar!")
  74. @slowTest
  75. def test_wildcard_auth(self):
  76. low = {
  77. "username": "the_s0und_of_t3ch",
  78. "password": "willrockyou",
  79. "eauth": "auto",
  80. "fun": "test.arg",
  81. "foo": "Foo!",
  82. "bar": "Bar!",
  83. }
  84. self.runner.cmd_sync(low)
  85. @slowTest
  86. def test_full_return_kwarg(self):
  87. low = {"fun": "test.arg"}
  88. low.update(self.eauth_creds)
  89. ret = self.runner.cmd_sync(low, full_return=True)
  90. self.assertIn("success", ret["data"])
  91. @slowTest
  92. def test_cmd_sync_arg_kwarg_parsing(self):
  93. low = {
  94. "client": "runner",
  95. "fun": "test.arg",
  96. "arg": ["foo", "bar=off", "baz={qux: 123}"],
  97. "kwarg": {"quux": "Quux"},
  98. "quuz": "on",
  99. }
  100. low.update(self.eauth_creds)
  101. ret = self.runner.cmd_sync(low)
  102. self.assertEqual(
  103. ret,
  104. {
  105. "args": ["foo"],
  106. "kwargs": {
  107. "bar": False,
  108. "baz": {"qux": 123},
  109. "quux": "Quux",
  110. "quuz": "on",
  111. },
  112. },
  113. )
  114. @slowTest
  115. def test_invalid_kwargs_are_ignored(self):
  116. low = {
  117. "client": "runner",
  118. "fun": "test.metasyntactic",
  119. "thiskwargisbad": "justpretendimnothere",
  120. }
  121. low.update(self.eauth_creds)
  122. ret = self.runner.cmd_sync(low)
  123. self.assertEqual(ret[0], "foo")