1
0

conftest.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. proxy_minion_id = "proxytest"
  18. root_dir = salt_factories._get_root_dir_for_daemon(proxy_minion_id)
  19. conf_dir = root_dir.join("conf").ensure(dir=True)
  20. RUNTIME_VARS.TMP_PROXY_CONF_DIR = conf_dir.strpath
  21. with salt.utils.files.fopen(os.path.join(RUNTIME_VARS.CONF_DIR, "proxy")) as rfh:
  22. config_defaults = yaml.deserialize(rfh.read())
  23. config_defaults["hosts.file"] = os.path.join(RUNTIME_VARS.TMP, "hosts")
  24. config_defaults["aliases.file"] = os.path.join(RUNTIME_VARS.TMP, "aliases")
  25. config_defaults["transport"] = request.config.getoption("--transport")
  26. config_defaults["root_dir"] = root_dir
  27. yield salt_factories.spawn_proxy_minion(
  28. request, proxy_minion_id, master_id="master", config_defaults=config_defaults
  29. )
  30. proxy_key_file = os.path.join(
  31. salt_master.config["pki_dir"], "minions", proxy_minion_id
  32. )
  33. log.debug("Proxy minion %r KEY FILE: %s", proxy_minion_id, proxy_key_file)
  34. if os.path.exists(proxy_key_file):
  35. os.unlink(proxy_key_file)
  36. else:
  37. log.warning("The proxy minion key was not found at %s", proxy_key_file)