1
0

test_proxy.py 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. # -*- coding: utf-8 -*-
  2. '''
  3. :codeauthor: Thayne Harbaugh (tharbaug@adobe.com)
  4. tests.integration.shell.proxy
  5. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  6. '''
  7. # Import python libs
  8. from __future__ import absolute_import, print_function, unicode_literals
  9. import logging
  10. # Import salt tests libs
  11. import tests.integration.utils
  12. from tests.support.unit import skipIf
  13. from tests.integration.utils import testprogram
  14. import salt.utils.platform
  15. import pytest
  16. log = logging.getLogger(__name__)
  17. @pytest.mark.windows_whitelisted
  18. class ProxyTest(testprogram.TestProgramCase):
  19. '''
  20. Various integration tests for the salt-proxy executable.
  21. '''
  22. def test_exit_status_no_proxyid(self):
  23. '''
  24. Ensure correct exit status when --proxyid argument is missing.
  25. '''
  26. proxy = testprogram.TestDaemonSaltProxy(
  27. name='proxy-no_proxyid',
  28. parent_dir=self._test_dir,
  29. )
  30. # Call setup here to ensure config and script exist
  31. proxy.setup()
  32. # Needed due to verbatim_args=True
  33. args = ['--config-dir', proxy.abs_path(proxy.config_dir)]
  34. if not salt.utils.platform.is_windows():
  35. args.append('-d')
  36. stdout, stderr, status = proxy.run(
  37. args=args,
  38. # verbatim_args prevents --proxyid from being added automatically
  39. verbatim_args=True,
  40. catch_stderr=True,
  41. with_retcode=True,
  42. # The proxy minion had a bug where it would loop forever
  43. # without daemonizing - protect that with a timeout.
  44. timeout=60,
  45. )
  46. try:
  47. self.assert_exit_status(
  48. status, 'EX_USAGE',
  49. message='no --proxyid specified',
  50. stdout=stdout,
  51. stderr=tests.integration.utils.decode_byte_list(stderr)
  52. )
  53. finally:
  54. # Although the start-up should fail, call shutdown() to set the
  55. # internal _shutdown flag and avoid the registered atexit calls to
  56. # cause timeout exceptions and respective traceback
  57. proxy.shutdown()
  58. # Hangs on Windows. You can add a timeout to the proxy.run command, but then
  59. # it just times out.
  60. @skipIf(salt.utils.platform.is_windows(), 'Test hangs on Windows')
  61. def test_exit_status_unknown_user(self):
  62. '''
  63. Ensure correct exit status when the proxy is configured to run as an
  64. unknown user.
  65. '''
  66. proxy = testprogram.TestDaemonSaltProxy(
  67. name='proxy-unknown_user',
  68. config_base={'user': 'some_unknown_user_xyz'},
  69. parent_dir=self._test_dir,
  70. )
  71. # Call setup here to ensure config and script exist
  72. proxy.setup()
  73. stdout, stderr, status = proxy.run(
  74. args=['-d'] if not salt.utils.platform.is_windows() else [],
  75. catch_stderr=True,
  76. with_retcode=True,
  77. )
  78. try:
  79. self.assert_exit_status(
  80. status, 'EX_NOUSER',
  81. message='unknown user not on system',
  82. stdout=stdout,
  83. stderr=tests.integration.utils.decode_byte_list(stderr)
  84. )
  85. finally:
  86. # Although the start-up should fail, call shutdown() to set the
  87. # internal _shutdown flag and avoid the registered atexit calls to
  88. # cause timeout exceptions and respective traceback
  89. proxy.shutdown()
  90. # pylint: disable=invalid-name
  91. def test_exit_status_unknown_argument(self):
  92. '''
  93. Ensure correct exit status when an unknown argument is passed to
  94. salt-proxy.
  95. '''
  96. proxy = testprogram.TestDaemonSaltProxy(
  97. name='proxy-unknown_argument',
  98. parent_dir=self._test_dir,
  99. )
  100. # Call setup here to ensure config and script exist
  101. proxy.setup()
  102. args = ['--unknown-argument']
  103. if not salt.utils.platform.is_windows():
  104. args.append('-b')
  105. stdout, stderr, status = proxy.run(
  106. args=args,
  107. catch_stderr=True,
  108. with_retcode=True,
  109. )
  110. try:
  111. self.assert_exit_status(
  112. status, 'EX_USAGE',
  113. message='unknown argument',
  114. stdout=stdout, stderr=stderr
  115. )
  116. finally:
  117. # Although the start-up should fail, call shutdown() to set the
  118. # internal _shutdown flag and avoid the registered atexit calls to
  119. # cause timeout exceptions and respective traceback
  120. proxy.shutdown()
  121. # Hangs on Windows. You can add a timeout to the proxy.run command, but then
  122. # it just times out.
  123. @skipIf(salt.utils.platform.is_windows(), 'Test hangs on Windows')
  124. def test_exit_status_correct_usage(self):
  125. '''
  126. Ensure correct exit status when salt-proxy starts correctly.
  127. Skip on Windows because daemonization not supported
  128. '''
  129. proxy = testprogram.TestDaemonSaltProxy(
  130. name='proxy-correct_usage',
  131. parent_dir=self._test_dir,
  132. )
  133. # Call setup here to ensure config and script exist
  134. proxy.setup()
  135. stdout, stderr, status = proxy.run(
  136. args=['-d'] if not salt.utils.platform.is_windows() else [],
  137. catch_stderr=True,
  138. with_retcode=True,
  139. )
  140. try:
  141. self.assert_exit_status(
  142. status, 'EX_OK',
  143. message='correct usage',
  144. stdout=stdout,
  145. stderr=tests.integration.utils.decode_byte_list(stderr)
  146. )
  147. finally:
  148. proxy.shutdown(wait_for_orphans=3)