test_master.py 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. # -*- coding: utf-8 -*-
  2. """
  3. :codeauthor: Pedro Algarvio (pedro@algarvio.me)
  4. tests.integration.shell.master
  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
  14. log = logging.getLogger(__name__)
  15. @pytest.fixture(scope="package")
  16. def shell_tests_salt_master_config(request, salt_factories):
  17. return salt_factories.configure_master(
  18. request, "shell-tests-master", config_overrides={"user": "unknown-user"}
  19. )
  20. @pytest.mark.windows_whitelisted
  21. class TestSaltMasterCLI(object):
  22. @PRE_PYTEST_SKIP
  23. def test_exit_status_unknown_user(
  24. self, request, salt_factories, shell_tests_salt_master_config
  25. ):
  26. """
  27. Ensure correct exit status when the master is configured to run as an unknown user.
  28. """
  29. with pytest.raises(ProcessNotStarted) as exc:
  30. salt_factories.spawn_master(
  31. request, shell_tests_salt_master_config["id"], max_start_attempts=1
  32. )
  33. assert exc.value.exitcode == salt.defaults.exitcodes.EX_NOUSER, exc.value
  34. assert "The user is not available." in exc.value.stderr, exc.value
  35. def test_exit_status_unknown_argument(
  36. self, request, salt_factories, shell_tests_salt_master_config, tempdir
  37. ):
  38. """
  39. Ensure correct exit status when an unknown argument is passed to salt-master.
  40. """
  41. # We pass root_dir in order not to hit the max length socket path issue
  42. root_dir = tempdir.join("ex-st-unkn-arg-mst").ensure(dir=True)
  43. with pytest.raises(ProcessNotStarted) as exc:
  44. salt_factories.spawn_master(
  45. request,
  46. shell_tests_salt_master_config["id"],
  47. max_start_attempts=1,
  48. base_script_args=["--unknown-argument"],
  49. config_defaults={"root_dir": root_dir},
  50. )
  51. assert exc.value.exitcode == salt.defaults.exitcodes.EX_USAGE, exc.value
  52. assert "Usage" in exc.value.stderr, exc.value
  53. assert "no such option: --unknown-argument" in exc.value.stderr, exc.value
  54. @PRE_PYTEST_SKIP
  55. def test_exit_status_correct_usage(
  56. self, request, salt_factories, shell_tests_salt_master_config
  57. ):
  58. proc = salt_factories.spawn_master(
  59. request, shell_tests_salt_master_config["id"] + "-2"
  60. )
  61. assert proc.is_alive()
  62. time.sleep(1)
  63. ret = proc.terminate()
  64. assert ret.exitcode == salt.defaults.exitcodes.EX_OK, ret