conftest.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. import logging
  2. import os
  3. import shutil
  4. import pytest
  5. log = logging.getLogger(__name__)
  6. @pytest.fixture(scope="package", autouse=True)
  7. def skip_on_tcp_transport(request):
  8. if request.config.getoption("--transport") == "tcp":
  9. pytest.skip("Multimaster under the TPC transport is not working. See #59053")
  10. @pytest.fixture(scope="package")
  11. def salt_mm_master_1(request, salt_factories):
  12. config_defaults = {
  13. "open_mode": True,
  14. "transport": request.config.getoption("--transport"),
  15. }
  16. factory = salt_factories.get_salt_master_daemon(
  17. "mm-master-1",
  18. config_defaults=config_defaults,
  19. extra_cli_arguments_after_first_start_failure=["--log-level=debug"],
  20. )
  21. with factory.started(start_timeout=120):
  22. yield factory
  23. @pytest.fixture(scope="package")
  24. def mm_master_1_salt_cli(salt_mm_master_1):
  25. return salt_mm_master_1.get_salt_cli(default_timeout=120)
  26. @pytest.fixture(scope="package")
  27. def salt_mm_master_2(salt_factories, salt_mm_master_1):
  28. config_defaults = {
  29. "open_mode": True,
  30. "transport": salt_mm_master_1.config["transport"],
  31. }
  32. factory = salt_factories.get_salt_master_daemon(
  33. "mm-master-2",
  34. config_defaults=config_defaults,
  35. extra_cli_arguments_after_first_start_failure=["--log-level=debug"],
  36. )
  37. # The secondary salt master depends on the primarily salt master fixture
  38. # because we need to clone the keys
  39. for keyfile in ("master.pem", "master.pub"):
  40. shutil.copyfile(
  41. os.path.join(salt_mm_master_1.config["pki_dir"], keyfile),
  42. os.path.join(factory.config["pki_dir"], keyfile),
  43. )
  44. with factory.started(start_timeout=120):
  45. yield factory
  46. @pytest.fixture(scope="package")
  47. def mm_master_2_salt_cli(salt_mm_master_2):
  48. return salt_mm_master_2.get_salt_cli(default_timeout=120)
  49. @pytest.fixture(scope="package")
  50. def salt_mm_minion_1(salt_mm_master_1, salt_mm_master_2):
  51. config_defaults = {
  52. "transport": salt_mm_master_1.config["transport"],
  53. }
  54. mm_master_1_port = salt_mm_master_1.config["ret_port"]
  55. mm_master_2_port = salt_mm_master_2.config["ret_port"]
  56. config_overrides = {
  57. "master": [
  58. "localhost:{}".format(mm_master_1_port),
  59. "localhost:{}".format(mm_master_2_port),
  60. ],
  61. "test.foo": "baz",
  62. }
  63. factory = salt_mm_master_1.get_salt_minion_daemon(
  64. "mm-minion-1",
  65. config_defaults=config_defaults,
  66. config_overrides=config_overrides,
  67. extra_cli_arguments_after_first_start_failure=["--log-level=debug"],
  68. )
  69. with factory.started(start_timeout=120):
  70. yield factory
  71. @pytest.fixture(scope="package")
  72. def salt_mm_minion_2(salt_mm_master_1, salt_mm_master_2):
  73. config_defaults = {
  74. "transport": salt_mm_master_1.config["transport"],
  75. }
  76. mm_master_1_port = salt_mm_master_1.config["ret_port"]
  77. mm_master_2_port = salt_mm_master_2.config["ret_port"]
  78. config_overrides = {
  79. "master": [
  80. "localhost:{}".format(mm_master_1_port),
  81. "localhost:{}".format(mm_master_2_port),
  82. ],
  83. "test.foo": "baz",
  84. }
  85. factory = salt_mm_master_2.get_salt_minion_daemon(
  86. "mm-minion-2",
  87. config_defaults=config_defaults,
  88. config_overrides=config_overrides,
  89. extra_cli_arguments_after_first_start_failure=["--log-level=debug"],
  90. )
  91. with factory.started(start_timeout=120):
  92. yield factory