1
0

test_master.py 4.5 KB

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