test_retcodes_fail_fail.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. # -*- coding: utf-8 -*-
  2. # Import Python Libraries
  3. from __future__ import print_function, unicode_literals, absolute_import
  4. import sys
  5. # Import Pepper Libraries
  6. import pepper
  7. from mock import patch, MagicMock
  8. PAYLOAD = {
  9. "return": [
  10. {
  11. "ezh.msk.ru": {
  12. "jid": "20180414193904158892",
  13. "ret": "/bin/sh: 123: command not found",
  14. "retcode": 127
  15. },
  16. "saltstack.ezh.msk.ru": {
  17. "jid": "20180414193904158892",
  18. "ret": "/bin/sh: 1: 123: not found",
  19. "retcode": 127
  20. }
  21. }
  22. ]
  23. }
  24. @patch('pepper.cli.PepperCli.login', MagicMock(side_effect=lambda arg: None))
  25. @patch('pepper.cli.PepperCli.low', MagicMock(side_effect=lambda api, load: PAYLOAD))
  26. def test_default():
  27. sys.argv = ['pepper', 'minion_id', 'request']
  28. ret_code = pepper.script.Pepper()()
  29. assert ret_code == 0
  30. @patch('pepper.cli.PepperCli.login', MagicMock(side_effect=lambda arg: None))
  31. @patch('pepper.cli.PepperCli.low', MagicMock(side_effect=lambda api, load: PAYLOAD))
  32. def test_fail_any():
  33. sys.argv = ['pepper', '--fail-any', 'minion_id', 'request']
  34. ret_code = pepper.script.Pepper()()
  35. assert ret_code == 127
  36. @patch('pepper.cli.PepperCli.login', MagicMock(side_effect=lambda arg: None))
  37. @patch('pepper.cli.PepperCli.low', MagicMock(side_effect=lambda api, load: PAYLOAD))
  38. def test_fail_any_none():
  39. sys.argv = ['pepper', '--fail-any-none', 'minion_id', 'request']
  40. ret_code = pepper.script.Pepper()()
  41. assert ret_code == 127
  42. @patch('pepper.cli.PepperCli.login', MagicMock(side_effect=lambda arg: None))
  43. @patch('pepper.cli.PepperCli.low', MagicMock(side_effect=lambda api, load: PAYLOAD))
  44. def test_fail_all():
  45. sys.argv = ['pepper', '--fail-all', 'minion_id', 'request']
  46. ret_code = pepper.script.Pepper()()
  47. assert ret_code == 127
  48. @patch('pepper.cli.PepperCli.login', MagicMock(side_effect=lambda arg: None))
  49. @patch('pepper.cli.PepperCli.low', MagicMock(side_effect=lambda api, load: PAYLOAD))
  50. def test_fail_all_none():
  51. sys.argv = ['pepper', '--fail-all-none', 'minion_id', 'request']
  52. ret_code = pepper.script.Pepper()()
  53. assert ret_code == 127