conftest.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. """
  2. tests.pytests.integration.conftest
  3. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. PyTest fixtures
  5. """
  6. import pytest
  7. @pytest.fixture(scope="package")
  8. def salt_master(salt_master_factory):
  9. """
  10. A running salt-master fixture
  11. """
  12. with salt_master_factory.started():
  13. yield salt_master_factory
  14. @pytest.fixture(scope="package")
  15. def salt_minion(salt_master, salt_minion_factory):
  16. """
  17. A running salt-minion fixture
  18. """
  19. assert salt_master.is_running()
  20. with salt_minion_factory.started():
  21. # Sync All
  22. salt_call_cli = salt_minion_factory.get_salt_call_cli()
  23. ret = salt_call_cli.run("saltutil.sync_all", _timeout=120)
  24. assert ret.exitcode == 0, ret
  25. yield salt_minion_factory
  26. @pytest.fixture(scope="module")
  27. def salt_sub_minion(salt_master, salt_sub_minion_factory):
  28. """
  29. A second running salt-minion fixture
  30. """
  31. assert salt_master.is_running()
  32. with salt_sub_minion_factory.started():
  33. # Sync All
  34. salt_call_cli = salt_sub_minion_factory.get_salt_call_cli()
  35. ret = salt_call_cli.run("saltutil.sync_all", _timeout=120)
  36. assert ret.exitcode == 0, ret
  37. yield salt_sub_minion_factory
  38. @pytest.fixture(scope="package")
  39. def salt_proxy(salt_master, salt_proxy_factory):
  40. """
  41. A running salt-proxy fixture
  42. """
  43. assert salt_master.is_running()
  44. with salt_proxy_factory.started():
  45. yield salt_proxy_factory
  46. @pytest.fixture(scope="package")
  47. def salt_cli(salt_master):
  48. """
  49. The ``salt`` CLI as a fixture against the running master
  50. """
  51. assert salt_master.is_running()
  52. return salt_master.get_salt_cli()
  53. @pytest.fixture(scope="package")
  54. def salt_call_cli(salt_minion):
  55. """
  56. The ``salt-call`` CLI as a fixture against the running minion
  57. """
  58. assert salt_minion.is_running()
  59. return salt_minion.get_salt_call_cli()
  60. @pytest.fixture(scope="package")
  61. def salt_cp_cli(salt_master):
  62. """
  63. The ``salt-cp`` CLI as a fixture against the running master
  64. """
  65. assert salt_master.is_running()
  66. return salt_master.get_salt_cp_cli()
  67. @pytest.fixture(scope="package")
  68. def salt_key_cli(salt_master):
  69. """
  70. The ``salt-key`` CLI as a fixture against the running master
  71. """
  72. assert salt_master.is_running()
  73. return salt_master.get_salt_key_cli()
  74. @pytest.fixture(scope="package")
  75. def salt_run_cli(salt_master):
  76. """
  77. The ``salt-run`` CLI as a fixture against the running master
  78. """
  79. assert salt_master.is_running()
  80. return salt_master.get_salt_run_cli()
  81. @pytest.fixture(scope="module")
  82. def salt_ssh_cli(salt_master, salt_ssh_roster_file, sshd_config_dir):
  83. """
  84. The ``salt-ssh`` CLI as a fixture against the running master
  85. """
  86. assert salt_master.is_running()
  87. return salt_master.get_salt_ssh_cli(
  88. default_timeout=180,
  89. roster_file=salt_ssh_roster_file,
  90. target_host="localhost",
  91. client_key=str(sshd_config_dir / "client_key"),
  92. base_script_args=["--ignore-host-keys"],
  93. )