test_runner.py 4.4 KB

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