1
0

test_proxy.py 5.5 KB

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