test_retcodes_fail_none.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. "saltstack.ezh.msk.ru": {
  12. "jid": "20180414193904158892",
  13. "ret": "/bin/sh: 123: command not found",
  14. "retcode": 127
  15. },
  16. "ezh.msk.ru": {
  17. "jid": "20180414193904158892",
  18. "ret": "Hello from SaltStack",
  19. }
  20. }
  21. ]
  22. }
  23. @patch('pepper.cli.PepperCli.login', MagicMock(side_effect=lambda arg: None))
  24. @patch('pepper.cli.PepperCli.low', MagicMock(side_effect=lambda api, load: PAYLOAD))
  25. def test_default():
  26. sys.argv = ['pepper', 'minion_id', 'request']
  27. ret_code = pepper.script.Pepper()()
  28. assert ret_code == 0
  29. @patch('pepper.cli.PepperCli.login', MagicMock(side_effect=lambda arg: None))
  30. @patch('pepper.cli.PepperCli.low', MagicMock(side_effect=lambda api, load: PAYLOAD))
  31. def test_fail_any():
  32. sys.argv = ['pepper', '--fail-any', 'minion_id', 'request']
  33. ret_code = pepper.script.Pepper()()
  34. assert ret_code == 127
  35. @patch('pepper.cli.PepperCli.login', MagicMock(side_effect=lambda arg: None))
  36. @patch('pepper.cli.PepperCli.low', MagicMock(side_effect=lambda api, load: PAYLOAD))
  37. def test_fail_any_none():
  38. sys.argv = ['pepper', '--fail-any-none', 'minion_id', 'request']
  39. ret_code = pepper.script.Pepper()()
  40. assert ret_code == 127
  41. @patch('pepper.cli.PepperCli.login', MagicMock(side_effect=lambda arg: None))
  42. @patch('pepper.cli.PepperCli.low', MagicMock(side_effect=lambda api, load: PAYLOAD))
  43. def test_fail_all():
  44. sys.argv = ['pepper', '--fail-all', 'minion_id', 'request']
  45. ret_code = pepper.script.Pepper()()
  46. assert ret_code == 127
  47. @patch('pepper.cli.PepperCli.login', MagicMock(side_effect=lambda arg: None))
  48. @patch('pepper.cli.PepperCli.low', MagicMock(side_effect=lambda api, load: PAYLOAD))
  49. def test_fail_all_none():
  50. sys.argv = ['pepper', '--fail-all-none', 'minion_id', 'request']
  51. ret_code = pepper.script.Pepper()()
  52. assert ret_code == 127