1
0

test_runner.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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.unit import TestCase
  6. from tests.support.mixins import AdaptedConfigurationTestCaseMixin
  7. # Import Salt libs
  8. import salt.runner
  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. 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. def test_token(self):
  34. '''
  35. Test executing master_call with lowdata
  36. The choice of using error.error for this is arbitrary and should be
  37. changed to some mocked function that is more testing friendly.
  38. '''
  39. import salt.auth
  40. auth = salt.auth.LoadAuth(self.get_config('client_config'))
  41. token = auth.mk_token(self.eauth_creds)
  42. self.runner.master_call(**{
  43. 'client': 'runner',
  44. 'fun': 'error.error',
  45. 'token': token['token'],
  46. })
  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. def test_cmd_async(self):
  55. low = {
  56. 'client': 'runner',
  57. 'fun': 'error.error',
  58. }
  59. low.update(self.eauth_creds)
  60. self.runner.cmd_async(low)
  61. def test_cmd_sync_w_arg(self):
  62. low = {
  63. 'fun': 'test.arg',
  64. 'foo': 'Foo!',
  65. 'bar': 'Bar!',
  66. }
  67. low.update(self.eauth_creds)
  68. ret = self.runner.cmd_sync(low)
  69. self.assertEqual(ret['kwargs']['foo'], 'Foo!')
  70. self.assertEqual(ret['kwargs']['bar'], 'Bar!')
  71. def test_wildcard_auth(self):
  72. low = {
  73. 'username': 'the_s0und_of_t3ch',
  74. 'password': 'willrockyou',
  75. 'eauth': 'auto',
  76. 'fun': 'test.arg',
  77. 'foo': 'Foo!',
  78. 'bar': 'Bar!',
  79. }
  80. self.runner.cmd_sync(low)
  81. def test_full_return_kwarg(self):
  82. low = {'fun': 'test.arg'}
  83. low.update(self.eauth_creds)
  84. ret = self.runner.cmd_sync(low, full_return=True)
  85. self.assertIn('success', ret['data'])
  86. def test_cmd_sync_arg_kwarg_parsing(self):
  87. low = {
  88. 'client': 'runner',
  89. 'fun': 'test.arg',
  90. 'arg': [
  91. 'foo',
  92. 'bar=off',
  93. 'baz={qux: 123}'
  94. ],
  95. 'kwarg': {
  96. 'quux': 'Quux',
  97. },
  98. 'quuz': 'on',
  99. }
  100. low.update(self.eauth_creds)
  101. ret = self.runner.cmd_sync(low)
  102. self.assertEqual(ret, {
  103. 'args': ['foo'],
  104. 'kwargs': {
  105. 'bar': False,
  106. 'baz': {
  107. 'qux': 123,
  108. },
  109. 'quux': 'Quux',
  110. 'quuz': 'on',
  111. },
  112. })
  113. def test_invalid_kwargs_are_ignored(self):
  114. low = {
  115. 'client': 'runner',
  116. 'fun': 'test.metasyntactic',
  117. 'thiskwargisbad': 'justpretendimnothere',
  118. }
  119. low.update(self.eauth_creds)
  120. ret = self.runner.cmd_sync(low)
  121. self.assertEqual(ret[0], 'foo')