conftest.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # -*- coding: utf-8 -*-
  2. """
  3. tests.integration.proxy.conftest
  4. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  5. Proxy related fixtures
  6. """
  7. # pylint: disable=unused-argument,redefined-outer-name
  8. # Import Python libs
  9. from __future__ import absolute_import, unicode_literals
  10. import logging
  11. import os
  12. # Import 3rd-party libs
  13. import psutil
  14. import pytest
  15. log = logging.getLogger(__name__)
  16. @pytest.fixture(scope="package", autouse=True)
  17. def session_salt_proxy(
  18. request, session_salt_proxy, session_proxy_id, session_master_config
  19. ):
  20. stats_key = " Salt Proxy"
  21. request.session.stats_processes[stats_key] = psutil.Process(session_salt_proxy.pid)
  22. yield session_salt_proxy
  23. # Terminate Proxy now, we want to cleanup its key before we move along
  24. session_salt_proxy.terminate()
  25. del request.session.stats_processes[stats_key]
  26. proxy_key_file = os.path.join(
  27. session_master_config["pki_dir"], "minions", session_proxy_id
  28. )
  29. log.warning("KEY FILE: %s", proxy_key_file)
  30. if os.path.exists(proxy_key_file):
  31. os.unlink(proxy_key_file)
  32. else:
  33. log.warning("The proxy minion key was not found at %s", proxy_key_file)