test_proxy.py 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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.unit import skipIf
  14. log = logging.getLogger(__name__)
  15. @pytest.mark.windows_whitelisted
  16. class ProxyTest(testprogram.TestProgramCase):
  17. """
  18. Various integration tests for the salt-proxy executable.
  19. """
  20. @skipIf(True, "SLOWTEST skip")
  21. def test_exit_status_no_proxyid(self):
  22. """
  23. Ensure correct exit status when --proxyid argument is missing.
  24. """
  25. proxy = testprogram.TestDaemonSaltProxy(
  26. name="proxy-no_proxyid", 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,
  47. "EX_USAGE",
  48. message="no --proxyid specified",
  49. stdout=stdout,
  50. stderr=tests.integration.utils.decode_byte_list(stderr),
  51. )
  52. finally:
  53. # Although the start-up should fail, call shutdown() to set the
  54. # internal _shutdown flag and avoid the registered atexit calls to
  55. # cause timeout exceptions and respective traceback
  56. proxy.shutdown()
  57. # Hangs on Windows. You can add a timeout to the proxy.run command, but then
  58. # it just times out.
  59. @skipIf(salt.utils.platform.is_windows(), "Test hangs on Windows")
  60. @skipIf(True, "SLOWTEST skip")
  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,
  81. "EX_NOUSER",
  82. message="unknown user not on system",
  83. stdout=stdout,
  84. stderr=tests.integration.utils.decode_byte_list(stderr),
  85. )
  86. finally:
  87. # Although the start-up should fail, call shutdown() to set the
  88. # internal _shutdown flag and avoid the registered atexit calls to
  89. # cause timeout exceptions and respective traceback
  90. proxy.shutdown()
  91. @skipIf(True, "SLOWTEST skip")
  92. def test_exit_status_unknown_argument(self):
  93. """
  94. Ensure correct exit status when an unknown argument is passed to
  95. salt-proxy.
  96. """
  97. proxy = testprogram.TestDaemonSaltProxy(
  98. name="proxy-unknown_argument", 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, catch_stderr=True, with_retcode=True,
  107. )
  108. try:
  109. self.assert_exit_status(
  110. status,
  111. "EX_USAGE",
  112. message="unknown argument",
  113. stdout=stdout,
  114. 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. @skipIf(True, "SLOWTEST skip")
  125. def test_exit_status_correct_usage(self):
  126. """
  127. Ensure correct exit status when salt-proxy starts correctly.
  128. Skip on Windows because daemonization not supported
  129. """
  130. proxy = testprogram.TestDaemonSaltProxy(
  131. name="proxy-correct_usage", 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,
  143. "EX_OK",
  144. message="correct usage",
  145. stdout=stdout,
  146. stderr=tests.integration.utils.decode_byte_list(stderr),
  147. )
  148. finally:
  149. proxy.shutdown(wait_for_orphans=3)