test_master.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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 pytest
  9. import tests.integration.utils
  10. from tests.integration.utils import testprogram
  11. from tests.support.case import ShellCase
  12. from tests.support.mixins import ShellCaseCommonTestsMixin
  13. from tests.support.unit import skipIf
  14. @skipIf(True, "This test file should be in an isolated test space.")
  15. @pytest.mark.windows_whitelisted
  16. class MasterTest(ShellCase, testprogram.TestProgramCase, ShellCaseCommonTestsMixin):
  17. _call_binary_ = "salt-master"
  18. def test_exit_status_unknown_user(self):
  19. """
  20. Ensure correct exit status when the master is configured to run as an unknown user.
  21. """
  22. master = testprogram.TestDaemonSaltMaster(
  23. name="unknown_user",
  24. configs={"master": {"map": {"user": "some_unknown_user_xyz"}}},
  25. parent_dir=self._test_dir,
  26. )
  27. # Call setup here to ensure config and script exist
  28. master.setup()
  29. stdout, stderr, status = master.run(
  30. args=["-d"], catch_stderr=True, with_retcode=True,
  31. )
  32. try:
  33. self.assert_exit_status(
  34. status,
  35. "EX_NOUSER",
  36. message="unknown user not on system",
  37. stdout=stdout,
  38. stderr=tests.integration.utils.decode_byte_list(stderr),
  39. )
  40. finally:
  41. # Although the start-up should fail, call shutdown() to set the
  42. # internal _shutdown flag and avoid the registered atexit calls to
  43. # cause timeout exceptions and respective traceback
  44. master.shutdown()
  45. def test_exit_status_unknown_argument(self):
  46. """
  47. Ensure correct exit status when an unknown argument is passed to salt-master.
  48. """
  49. master = testprogram.TestDaemonSaltMaster(
  50. name="unknown_argument", parent_dir=self._test_dir,
  51. )
  52. # Call setup here to ensure config and script exist
  53. master.setup()
  54. stdout, stderr, status = master.run(
  55. args=["-d", "--unknown-argument"], catch_stderr=True, with_retcode=True,
  56. )
  57. try:
  58. self.assert_exit_status(
  59. status,
  60. "EX_USAGE",
  61. message="unknown argument",
  62. stdout=stdout,
  63. stderr=tests.integration.utils.decode_byte_list(stderr),
  64. )
  65. finally:
  66. # Although the start-up should fail, call shutdown() to set the
  67. # internal _shutdown flag and avoid the registered atexit calls to
  68. # cause timeout exceptions and respective traceback
  69. master.shutdown()
  70. def test_exit_status_correct_usage(self):
  71. """
  72. Ensure correct exit status when salt-master starts correctly.
  73. """
  74. master = testprogram.TestDaemonSaltMaster(
  75. name="correct_usage", parent_dir=self._test_dir,
  76. )
  77. # Call setup here to ensure config and script exist
  78. master.setup()
  79. stdout, stderr, status = master.run(
  80. args=["-d"], catch_stderr=True, with_retcode=True,
  81. )
  82. try:
  83. self.assert_exit_status(
  84. status,
  85. "EX_OK",
  86. message="correct usage",
  87. stdout=stdout,
  88. stderr=tests.integration.utils.decode_byte_list(stderr),
  89. )
  90. finally:
  91. master.shutdown(wait_for_orphans=3)
  92. # Do the test again to check does master shut down correctly
  93. # **Due to some underlying subprocessing issues with Minion._thread_return, this
  94. # part of the test has been commented out. Once these underlying issues have
  95. # been addressed, this part of the test should be uncommented. Work for this
  96. # issue is being tracked in https://github.com/saltstack/salt-jenkins/issues/378
  97. # stdout, stderr, status = master.run(
  98. # args=['-d'],
  99. # catch_stderr=True,
  100. # with_retcode=True,
  101. # )
  102. # try:
  103. # self.assert_exit_status(
  104. # status, 'EX_OK',
  105. # message='correct usage',
  106. # stdout=stdout,
  107. # stderr=tests.integration.utils.decode_byte_list(stderr)
  108. # )
  109. # finally:
  110. # master.shutdown(wait_for_orphans=3)