test_master.py 4.5 KB

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