1
0

test_proxy.py 5.6 KB

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