1
0

test_salt_proxy.py 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. """
  2. :codeauthor: Thayne Harbaugh (tharbaug@adobe.com)
  3. tests.pytests.integration.cli.test_proxy
  4. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  5. Various integration tests for the salt-proxy executable.
  6. """
  7. import logging
  8. import time
  9. import pytest
  10. import salt.defaults.exitcodes
  11. from saltfactories.exceptions import FactoryNotStarted
  12. from saltfactories.utils import random_string
  13. from tests.support.helpers import PRE_PYTEST_SKIP_REASON, slowTest
  14. log = logging.getLogger(__name__)
  15. @pytest.fixture
  16. def proxy_minion_id(salt_factories, salt_master):
  17. _proxy_minion_id = random_string("proxy-minion-")
  18. try:
  19. yield _proxy_minion_id
  20. finally:
  21. # Remove stale key if it exists
  22. pytest.helpers.remove_stale_minion_key(salt_master, _proxy_minion_id)
  23. @slowTest
  24. def test_exit_status_no_proxyid(salt_master, proxy_minion_id):
  25. """
  26. Ensure correct exit status when --proxyid argument is missing.
  27. """
  28. with pytest.raises(FactoryNotStarted) as exc:
  29. factory = salt_master.get_salt_proxy_minion_daemon(
  30. proxy_minion_id, include_proxyid_cli_flag=False
  31. )
  32. factory.start(start_timeout=10, max_start_attempts=1)
  33. assert exc.value.exitcode == salt.defaults.exitcodes.EX_USAGE, exc.value
  34. assert "Usage" in exc.value.stderr, exc.value
  35. assert "error: salt-proxy requires --proxyid" in exc.value.stderr, exc.value
  36. @pytest.mark.skip_on_windows(reason="Windows does not do user checks")
  37. def test_exit_status_unknown_user(salt_master, proxy_minion_id):
  38. """
  39. Ensure correct exit status when the proxy is configured to run as an
  40. unknown user.
  41. """
  42. with pytest.raises(FactoryNotStarted) as exc:
  43. factory = salt_master.get_salt_proxy_minion_daemon(
  44. proxy_minion_id, config_overrides={"user": "unknown-user"}
  45. )
  46. factory.start(start_timeout=10, max_start_attempts=1)
  47. assert exc.value.exitcode == salt.defaults.exitcodes.EX_NOUSER, exc.value
  48. assert "The user is not available." in exc.value.stderr, exc.value
  49. @slowTest
  50. def test_exit_status_unknown_argument(salt_master, proxy_minion_id):
  51. """
  52. Ensure correct exit status when an unknown argument is passed to
  53. salt-proxy.
  54. """
  55. with pytest.raises(FactoryNotStarted) as exc:
  56. factory = salt_master.get_salt_proxy_minion_daemon(proxy_minion_id)
  57. factory.start("--unknown-argument", start_timeout=10, max_start_attempts=1)
  58. assert exc.value.exitcode == salt.defaults.exitcodes.EX_USAGE, exc.value
  59. assert "Usage" in exc.value.stderr, exc.value
  60. assert "no such option: --unknown-argument" in exc.value.stderr, exc.value
  61. # Hangs on Windows. You can add a timeout to the proxy.run command, but then
  62. # it just times out.
  63. @pytest.mark.skip_on_windows(reason=PRE_PYTEST_SKIP_REASON)
  64. def test_exit_status_correct_usage(salt_master, proxy_minion_id):
  65. """
  66. Ensure correct exit status when salt-proxy starts correctly.
  67. Skip on Windows because daemonization not supported
  68. """
  69. factory = salt_master.get_salt_proxy_minion_daemon(
  70. proxy_minion_id,
  71. extra_cli_arguments_after_first_start_failure=["--log-level=debug"],
  72. config_defaults={"transport": salt_master.config["transport"]},
  73. )
  74. factory.start()
  75. assert factory.is_running()
  76. time.sleep(0.5)
  77. ret = factory.terminate()
  78. assert ret.exitcode == salt.defaults.exitcodes.EX_OK, ret