test_proxy.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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 time
  10. import pytest
  11. import salt.defaults.exitcodes
  12. from saltfactories.exceptions import ProcessNotStarted
  13. from tests.support.helpers import PRE_PYTEST_SKIP_REASON
  14. log = logging.getLogger(__name__)
  15. @pytest.fixture(scope="module")
  16. def shell_tests_salt_master(request, salt_factories):
  17. return salt_factories.spawn_master(request, "proxy-minion-shell-tests")
  18. @pytest.fixture(scope="module")
  19. def shell_tests_salt_proxy_minion_config(
  20. request, salt_factories, shell_tests_salt_master
  21. ):
  22. return salt_factories.configure_proxy_minion(
  23. request,
  24. shell_tests_salt_master.config["id"],
  25. master_id=shell_tests_salt_master.config["id"],
  26. config_overrides={"user": "unknown-user"},
  27. )
  28. class TestProxyMinion:
  29. """
  30. Various integration tests for the salt-proxy executable.
  31. """
  32. def test_exit_status_no_proxyid(
  33. self, request, salt_factories, shell_tests_salt_proxy_minion_config
  34. ):
  35. """
  36. Ensure correct exit status when --proxyid argument is missing.
  37. """
  38. with pytest.raises(ProcessNotStarted) as exc:
  39. salt_factories.spawn_proxy_minion(
  40. request,
  41. shell_tests_salt_proxy_minion_config["id"],
  42. master_id=shell_tests_salt_proxy_minion_config["id"],
  43. max_start_attempts=1,
  44. include_proxyid_cli_flag=False,
  45. )
  46. assert exc.value.exitcode == salt.defaults.exitcodes.EX_USAGE, exc.value
  47. assert "Usage" in exc.value.stderr, exc.value
  48. assert "error: salt-proxy requires --proxyid" in exc.value.stderr, exc.value
  49. @pytest.mark.skip_on_windows(reason=PRE_PYTEST_SKIP_REASON)
  50. def test_exit_status_unknown_user(
  51. self, request, salt_factories, shell_tests_salt_proxy_minion_config
  52. ):
  53. """
  54. Ensure correct exit status when the proxy is configured to run as an
  55. unknown user.
  56. """
  57. with pytest.raises(ProcessNotStarted) as exc:
  58. salt_factories.spawn_proxy_minion(
  59. request,
  60. shell_tests_salt_proxy_minion_config["id"],
  61. master_id=shell_tests_salt_proxy_minion_config["id"],
  62. max_start_attempts=1,
  63. )
  64. assert exc.value.exitcode == salt.defaults.exitcodes.EX_NOUSER, exc.value
  65. assert "The user is not available." in exc.value.stderr, exc.value
  66. def test_exit_status_unknown_argument(
  67. self, request, salt_factories, shell_tests_salt_proxy_minion_config, tempdir
  68. ):
  69. """
  70. Ensure correct exit status when an unknown argument is passed to
  71. salt-proxy.
  72. """
  73. # We pass root_dir in order not to hit the max length socket path issue
  74. root_dir = tempdir.join("ex-st-unkn-arg-proxy").ensure(dir=True)
  75. with pytest.raises(ProcessNotStarted) as exc:
  76. salt_factories.spawn_proxy_minion(
  77. request,
  78. shell_tests_salt_proxy_minion_config["id"],
  79. master_id=shell_tests_salt_proxy_minion_config["id"],
  80. max_start_attempts=1,
  81. base_script_args=["--unknown-argument"],
  82. config_defaults={"root_dir": root_dir},
  83. )
  84. assert exc.value.exitcode == salt.defaults.exitcodes.EX_USAGE, exc.value
  85. assert "Usage" in exc.value.stderr, exc.value
  86. assert "no such option: --unknown-argument" in exc.value.stderr, exc.value
  87. @pytest.mark.skip_on_windows(reason=PRE_PYTEST_SKIP_REASON)
  88. def test_exit_status_correct_usage(
  89. self, request, salt_factories, shell_tests_salt_master
  90. ):
  91. """
  92. Ensure correct exit status when salt-proxy starts correctly.
  93. Skip on Windows because daemonization not supported
  94. """
  95. proc = salt_factories.spawn_proxy_minion(
  96. request,
  97. shell_tests_salt_master.config["id"] + "-2",
  98. master_id=shell_tests_salt_master.config["id"],
  99. )
  100. assert proc.is_alive()
  101. time.sleep(1)
  102. ret = proc.terminate()
  103. assert ret.exitcode == salt.defaults.exitcodes.EX_OK, ret