test_clients.py 2.1 KB

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