1
0

conftest.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # -*- coding: utf-8 -*-
  2. """
  3. tests.integration.proxy.conftest
  4. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  5. Proxy related fixtures
  6. """
  7. from __future__ import absolute_import, unicode_literals
  8. import logging
  9. import os
  10. import pytest
  11. import salt.utils.files
  12. from salt.serializers import yaml
  13. from tests.support.runtests import RUNTIME_VARS
  14. log = logging.getLogger(__name__)
  15. @pytest.fixture(scope="package", autouse=True)
  16. def salt_proxy(request, salt_factories, salt_master):
  17. yield salt_factories.spawn_proxy_minion(request, "proxytest", master_id="master")
  18. proxy_key_file = os.path.join(salt_master.config["pki_dir"], "minions", "proxytest")
  19. log.warning("KEY FILE: %s", proxy_key_file)
  20. if os.path.exists(proxy_key_file):
  21. os.unlink(proxy_key_file)
  22. else:
  23. log.warning("The proxy minion key was not found at %s", proxy_key_file)
  24. def pytest_saltfactories_proxy_minion_configuration_defaults(
  25. request, factories_manager, root_dir, proxy_minion_id, master_port
  26. ):
  27. """
  28. Hook which should return a dictionary tailored for the provided proxy_minion_id
  29. Stops at the first non None result
  30. """
  31. if proxy_minion_id == "proxytest":
  32. with salt.utils.files.fopen(
  33. os.path.join(RUNTIME_VARS.CONF_DIR, "proxy")
  34. ) as rfh:
  35. opts = yaml.deserialize(rfh.read())
  36. opts["hosts.file"] = os.path.join(RUNTIME_VARS.TMP, "hosts")
  37. opts["aliases.file"] = os.path.join(RUNTIME_VARS.TMP, "aliases")
  38. opts["transport"] = request.config.getoption("--transport")
  39. RUNTIME_VARS.TMP_PROXY_CONF_DIR = root_dir.join("conf").strpath
  40. return opts