1
0

test_syndic.py 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. from collections import OrderedDict
  10. import psutil
  11. import pytest
  12. import salt.utils.files
  13. import salt.utils.platform
  14. import salt.utils.yaml
  15. from tests.integration.utils import testprogram
  16. from tests.support.case import ShellCase
  17. from tests.support.mixins import ShellCaseCommonTestsMixin
  18. from tests.support.unit import skipIf
  19. log = logging.getLogger(__name__)
  20. # @pytest.fixture(scope='module', autouse=True)
  21. def session_salt_syndic(request, session_salt_master_of_masters, session_salt_syndic):
  22. request.session.stats_processes.update(
  23. OrderedDict(
  24. (
  25. (
  26. "Salt Syndic Master",
  27. psutil.Process(session_salt_master_of_masters.pid),
  28. ),
  29. ("Salt Syndic", psutil.Process(session_salt_syndic.pid)),
  30. )
  31. ).items()
  32. )
  33. yield session_salt_syndic
  34. request.session.stats_processes.pop("Salt Syndic Master")
  35. request.session.stats_processes.pop("Salt Syndic")
  36. # Stop daemons now(they would be stopped at the end of the test run session
  37. for daemon in (session_salt_syndic, session_salt_master_of_masters):
  38. try:
  39. daemon.terminate()
  40. except Exception as exc: # pylint: disable=broad-except
  41. log.warning("Failed to terminate daemon: %s", daemon.__class__.__name__)
  42. @pytest.mark.windows_whitelisted
  43. class SyndicTest(ShellCase, testprogram.TestProgramCase, ShellCaseCommonTestsMixin):
  44. """
  45. Test the salt-syndic command
  46. """
  47. _call_binary_ = "salt-syndic"
  48. @skipIf(salt.utils.platform.is_windows(), "Skip on Windows OS")
  49. @skipIf(True, "SLOWTEST skip")
  50. def test_exit_status_unknown_user(self):
  51. """
  52. Ensure correct exit status when the syndic is configured to run as an unknown user.
  53. Skipped on windows because daemonization not supported
  54. """
  55. syndic = testprogram.TestDaemonSaltSyndic(
  56. name="unknown_user",
  57. config_base={"user": "some_unknown_user_xyz"},
  58. parent_dir=self._test_dir,
  59. )
  60. # Call setup here to ensure config and script exist
  61. syndic.setup()
  62. stdout, stderr, status = syndic.run(
  63. args=["-d"], catch_stderr=True, with_retcode=True,
  64. )
  65. try:
  66. self.assert_exit_status(
  67. status,
  68. "EX_NOUSER",
  69. message="unknown user not on system",
  70. stdout=stdout,
  71. stderr=stderr,
  72. )
  73. finally:
  74. # Although the start-up should fail, call shutdown() to set the
  75. # internal _shutdown flag and avoid the registered atexit calls to
  76. # cause timeout exceptions and respective traceback
  77. syndic.shutdown()
  78. # pylint: disable=invalid-name
  79. @skipIf(salt.utils.platform.is_windows(), "Skip on Windows OS")
  80. @skipIf(True, "SLOWTEST skip")
  81. def test_exit_status_unknown_argument(self):
  82. """
  83. Ensure correct exit status when an unknown argument is passed to salt-syndic.
  84. Skipped on windows because daemonization not supported
  85. """
  86. syndic = testprogram.TestDaemonSaltSyndic(
  87. name="unknown_argument", parent_dir=self._test_dir,
  88. )
  89. # Syndic setup here to ensure config and script exist
  90. syndic.setup()
  91. stdout, stderr, status = syndic.run(
  92. args=["-d", "--unknown-argument"], catch_stderr=True, with_retcode=True,
  93. )
  94. try:
  95. self.assert_exit_status(
  96. status,
  97. "EX_USAGE",
  98. message="unknown argument",
  99. stdout=stdout,
  100. stderr=stderr,
  101. )
  102. finally:
  103. # Although the start-up should fail, call shutdown() to set the
  104. # internal _shutdown flag and avoid the registered atexit calls to
  105. # cause timeout exceptions and respective traceback
  106. syndic.shutdown()
  107. @skipIf(salt.utils.platform.is_windows(), "Skip on Windows OS")
  108. @skipIf(True, "SLOWTEST skip")
  109. def test_exit_status_correct_usage(self):
  110. """
  111. Ensure correct exit status when salt-syndic starts correctly.
  112. Skipped on windows because daemonization not supported
  113. """
  114. syndic = testprogram.TestDaemonSaltSyndic(
  115. name="correct_usage", parent_dir=self._test_dir,
  116. )
  117. # Syndic setup here to ensure config and script exist
  118. syndic.setup()
  119. stdout, stderr, status = syndic.run(
  120. args=["-d", "-l", "debug"], catch_stderr=True, with_retcode=True,
  121. )
  122. try:
  123. self.assert_exit_status(
  124. status, "EX_OK", message="correct usage", stdout=stdout, stderr=stderr
  125. )
  126. finally:
  127. syndic.shutdown(wait_for_orphans=3)