test_syndic.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. # -*- coding: utf-8 -*-
  2. '''
  3. :codeauthor: Pedro Algarvio (pedro@algarvio.me)
  4. tests.integration.shell.syndic
  5. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  6. '''
  7. # Import python libs
  8. from __future__ import absolute_import
  9. import logging
  10. # Import Salt Testing libs
  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 salt libs
  16. import salt.utils.files
  17. import salt.utils.yaml
  18. import salt.utils.platform
  19. log = logging.getLogger(__name__)
  20. SIGKILL = 9
  21. class SyndicTest(ShellCase, testprogram.TestProgramCase, ShellCaseCommonTestsMixin):
  22. '''
  23. Test the salt-syndic command
  24. '''
  25. @skipIf(salt.utils.platform.is_windows(), 'Skip on Windows OS')
  26. def test_exit_status_unknown_user(self):
  27. '''
  28. Ensure correct exit status when the syndic is configured to run as an unknown user.
  29. Skipped on windows because daemonization not supported
  30. '''
  31. syndic = testprogram.TestDaemonSaltSyndic(
  32. name='unknown_user',
  33. config_base={'user': 'some_unknown_user_xyz'},
  34. parent_dir=self._test_dir,
  35. )
  36. # Call setup here to ensure config and script exist
  37. syndic.setup()
  38. stdout, stderr, status = syndic.run(
  39. args=['-d'],
  40. catch_stderr=True,
  41. with_retcode=True,
  42. )
  43. try:
  44. self.assert_exit_status(
  45. status, 'EX_NOUSER',
  46. message='unknown user not on system',
  47. stdout=stdout, stderr=stderr
  48. )
  49. finally:
  50. # Although the start-up should fail, call shutdown() to set the
  51. # internal _shutdown flag and avoid the registered atexit calls to
  52. # cause timeout exceptions and respective traceback
  53. syndic.shutdown()
  54. # pylint: disable=invalid-name
  55. @skipIf(salt.utils.platform.is_windows(), 'Skip on Windows OS')
  56. def test_exit_status_unknown_argument(self):
  57. '''
  58. Ensure correct exit status when an unknown argument is passed to salt-syndic.
  59. Skipped on windows because daemonization not supported
  60. '''
  61. syndic = testprogram.TestDaemonSaltSyndic(
  62. name='unknown_argument',
  63. parent_dir=self._test_dir,
  64. )
  65. # Syndic setup here to ensure config and script exist
  66. syndic.setup()
  67. stdout, stderr, status = syndic.run(
  68. args=['-d', '--unknown-argument'],
  69. catch_stderr=True,
  70. with_retcode=True,
  71. )
  72. try:
  73. self.assert_exit_status(
  74. status, 'EX_USAGE',
  75. message='unknown argument',
  76. stdout=stdout, stderr=stderr
  77. )
  78. finally:
  79. # Although the start-up should fail, call shutdown() to set the
  80. # internal _shutdown flag and avoid the registered atexit calls to
  81. # cause timeout exceptions and respective traceback
  82. syndic.shutdown()
  83. @skipIf(salt.utils.platform.is_windows(), 'Skip on Windows OS')
  84. def test_exit_status_correct_usage(self):
  85. '''
  86. Ensure correct exit status when salt-syndic starts correctly.
  87. Skipped on windows because daemonization not supported
  88. '''
  89. syndic = testprogram.TestDaemonSaltSyndic(
  90. name='correct_usage',
  91. parent_dir=self._test_dir,
  92. )
  93. # Syndic setup here to ensure config and script exist
  94. syndic.setup()
  95. stdout, stderr, status = syndic.run(
  96. args=['-d', '-l', 'debug'],
  97. catch_stderr=True,
  98. with_retcode=True,
  99. )
  100. try:
  101. self.assert_exit_status(
  102. status, 'EX_OK',
  103. message='correct usage',
  104. stdout=stdout, stderr=stderr
  105. )
  106. finally:
  107. syndic.shutdown(wait_for_orphans=3)