test_syndic.py 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. # -*- coding: utf-8 -*-
  2. """
  3. :codeauthor: Pedro Algarvio (pedro@algarvio.me)
  4. tests.integration.shell.syndic
  5. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  6. """
  7. from __future__ import absolute_import
  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, "syndic-shell-tests-mom")
  18. @pytest.mark.windows_whitelisted
  19. class TestSaltSyndicCLI(object):
  20. @pytest.mark.skip_on_windows(reason=PRE_PYTEST_SKIP_REASON)
  21. def test_exit_status_unknown_user(
  22. self, request, salt_factories, shell_tests_salt_master
  23. ):
  24. """
  25. Ensure correct exit status when the syndic is configured to run as an unknown user.
  26. """
  27. with pytest.raises(ProcessNotStarted) as exc:
  28. salt_factories.spawn_syndic(
  29. request,
  30. "syndic-shell-tests-unknown-user",
  31. master_of_masters_id=shell_tests_salt_master.config["id"],
  32. max_start_attempts=1,
  33. config_overrides={"syndic": {"user": "unknown-user"}},
  34. )
  35. assert exc.value.exitcode == salt.defaults.exitcodes.EX_NOUSER, exc.value
  36. assert "The user is not available." in exc.value.stderr, exc.value
  37. @pytest.mark.skip_on_windows(reason=PRE_PYTEST_SKIP_REASON)
  38. def test_exit_status_unknown_argument(
  39. self, request, salt_factories, shell_tests_salt_master, tempdir
  40. ):
  41. """
  42. Ensure correct exit status when an unknown argument is passed to salt-syndic.
  43. """
  44. # We pass root_dir in order not to hit the max length socket path issue
  45. root_dir = tempdir.join("ex-st-unkn-arg-syndic").ensure(dir=True)
  46. with pytest.raises(ProcessNotStarted) as exc:
  47. salt_factories.spawn_syndic(
  48. request,
  49. "syndic-shell-tests-unknown-arguments",
  50. master_of_masters_id=shell_tests_salt_master.config["id"],
  51. max_start_attempts=1,
  52. base_script_args=["--unknown-argument"],
  53. config_defaults={"syndic": {"root_dir": root_dir}},
  54. )
  55. assert exc.value.exitcode == salt.defaults.exitcodes.EX_USAGE, exc.value
  56. assert "Usage" in exc.value.stderr, exc.value
  57. assert "no such option: --unknown-argument" in exc.value.stderr, exc.value
  58. @pytest.mark.skip_on_windows(reason=PRE_PYTEST_SKIP_REASON)
  59. def test_exit_status_correct_usage(
  60. self, request, salt_factories, shell_tests_salt_master
  61. ):
  62. proc = salt_factories.spawn_syndic(
  63. request,
  64. "syndic-shell-tests",
  65. master_of_masters_id=shell_tests_salt_master.config["id"],
  66. )
  67. assert proc.is_alive()
  68. time.sleep(1)
  69. ret = proc.terminate()
  70. assert ret.exitcode == salt.defaults.exitcodes.EX_OK, ret