conftest.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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 os
  11. import logging
  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(request,
  18. session_salt_proxy,
  19. session_proxy_id,
  20. session_master_config):
  21. stats_key = ' Salt Proxy'
  22. request.session.stats_processes[stats_key] = psutil.Process(session_salt_proxy.pid)
  23. yield session_salt_proxy
  24. # Terminate Proxy now, we want to cleanup it's key before we move along
  25. session_salt_proxy.terminate()
  26. del request.session.stats_processes[stats_key]
  27. proxy_key_file = os.path.join(session_master_config['pki_dir'], 'minions', session_proxy_id)
  28. log.warning('KEY FILE: %s', proxy_key_file)
  29. if os.path.exists(proxy_key_file):
  30. os.unlink(proxy_key_file)
  31. else:
  32. log.warning('The proxy minion key was not found at %s', proxy_key_file)