1
0

test_salt_master.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. """
  2. :codeauthor: Pedro Algarvio (pedro@algarvio.me)
  3. tests.integration.shell.master
  4. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  5. """
  6. import logging
  7. import time
  8. import pytest
  9. import salt.defaults.exitcodes
  10. from saltfactories.exceptions import FactoryNotStarted
  11. from saltfactories.utils import random_string
  12. from tests.support.helpers import PRE_PYTEST_SKIP_REASON, slowTest
  13. log = logging.getLogger(__name__)
  14. pytestmark = pytest.mark.windows_whitelisted
  15. @pytest.fixture
  16. def master_id():
  17. return random_string("master-")
  18. @slowTest
  19. def test_exit_status_unknown_user(salt_factories, master_id):
  20. """
  21. Ensure correct exit status when the master is configured to run as an unknown user.
  22. """
  23. with pytest.raises(FactoryNotStarted) as exc:
  24. factory = salt_factories.get_salt_master_daemon(
  25. master_id, config_overrides={"user": "unknown-user"}
  26. )
  27. factory.start(start_timeout=10, max_start_attempts=1)
  28. assert exc.value.exitcode == salt.defaults.exitcodes.EX_NOUSER, exc.value
  29. assert "The user is not available." in exc.value.stderr, exc.value
  30. @slowTest
  31. def test_exit_status_unknown_argument(salt_factories, master_id):
  32. """
  33. Ensure correct exit status when an unknown argument is passed to salt-master.
  34. """
  35. with pytest.raises(FactoryNotStarted) as exc:
  36. factory = salt_factories.get_salt_master_daemon(master_id)
  37. factory.start("--unknown-argument", start_timeout=10, max_start_attempts=1)
  38. assert exc.value.exitcode == salt.defaults.exitcodes.EX_USAGE, exc.value
  39. assert "Usage" in exc.value.stderr, exc.value
  40. assert "no such option: --unknown-argument" in exc.value.stderr, exc.value
  41. @slowTest
  42. @pytest.mark.skip_on_windows(reason=PRE_PYTEST_SKIP_REASON)
  43. def test_exit_status_correct_usage(salt_factories, master_id):
  44. factory = salt_factories.get_salt_master_daemon(master_id)
  45. factory.start()
  46. assert factory.is_running()
  47. time.sleep(0.5)
  48. ret = factory.terminate()
  49. assert ret.exitcode == salt.defaults.exitcodes.EX_OK, ret