1
0

test_clients.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. # -*- coding: utf-8 -*-
  2. import json
  3. import os
  4. import pytest
  5. import sys
  6. def test_local_bad_opts(pepper_cli):
  7. with pytest.raises(SystemExit):
  8. pepper_cli('*')
  9. with pytest.raises(SystemExit):
  10. pepper_cli('test.ping')
  11. with pytest.raises(SystemExit):
  12. pepper_cli('--client=ssh', 'test.ping')
  13. with pytest.raises(SystemExit):
  14. pepper_cli('--client=ssh', '*')
  15. @pytest.mark.xfail(
  16. pytest.config.getoption("--salt-api-backend") == "rest_tornado",
  17. reason="timeout kwarg isnt popped until next version of salt/tornado"
  18. )
  19. def test_runner_client(pepper_cli):
  20. ret = pepper_cli(
  21. '--timeout=123', '--client=runner', 'test.arg',
  22. 'one', 'two=what',
  23. 'three={0}'.format(json.dumps({"hello": "world"})),
  24. )
  25. assert ret == {"args": ["one"], "kwargs": {"three": {"hello": "world"}, "two": "what"}}
  26. @pytest.mark.xfail(
  27. pytest.config.getoption("--salt-api-backend") == "rest_tornado",
  28. reason="wheelClient unimplemented for now on tornado",
  29. )
  30. def test_wheel_client_arg(pepper_cli, session_minion_id):
  31. ret = pepper_cli('--client=wheel', 'minions.connected')
  32. assert ret == ['pytest-session-salt-minion-0']
  33. @pytest.mark.xfail(
  34. pytest.config.getoption("--salt-api-backend") == "rest_tornado",
  35. reason="wheelClient unimplemented for now on tornado",
  36. )
  37. def test_wheel_client_kwargs(pepper_cli, session_master_config_file):
  38. ret = pepper_cli(
  39. '--client=wheel', 'config.update_config', 'file_name=pepper',
  40. 'yaml_contents={0}'.format(json.dumps({"timeout": 5})),
  41. )
  42. assert ret == 'Wrote pepper.conf'
  43. assert os.path.isfile('{0}.d/pepper.conf'.format(session_master_config_file))
  44. @pytest.mark.xfail(
  45. pytest.config.getoption("--salt-api-backend") == "rest_tornado",
  46. reason="sshClient unimplemented for now on tornado",
  47. )
  48. @pytest.mark.xfail(sys.version_info >= (3, 0),
  49. reason='Broken with python3 right now')
  50. def test_ssh_client(pepper_cli, session_roster_config, session_roster_config_file):
  51. ret = pepper_cli('--client=ssh', '*', 'test.ping')
  52. assert ret['ssh']['localhost']['return'] is True
  53. def test_bad_client(pepper_cli):
  54. ret = pepper_cli('--client=whatever')
  55. assert ret == 1