test_master.py 4.4 KB

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