Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write auto-created private data dirs to pytest dir instead of /tmp #916

Merged
merged 3 commits into from Dec 14, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion ansible_runner/config/_base.py
Expand Up @@ -100,7 +100,7 @@ def __init__(self,
# attempt to compromise the directories via a race.
os.makedirs(self.private_data_dir, exist_ok=True, mode=0o700)
else:
self.private_data_dir = tempfile.mkdtemp(prefix=".ansible-runner-")
self.private_data_dir = tempfile.mkdtemp(prefix=defaults.auto_create_naming, dir=defaults.auto_create_dir)
AlanCoding marked this conversation as resolved.
Show resolved Hide resolved

if artifact_dir is None:
artifact_dir = os.path.join(self.private_data_dir, 'artifacts')
Expand Down
5 changes: 5 additions & 0 deletions ansible_runner/defaults.py
Expand Up @@ -4,3 +4,8 @@

# for ansible-runner worker cleanup command
GRACE_PERIOD_DEFAULT = 60 # minutes

# values passed to tempfile.mkdtemp to generate a private data dir
# when user did not provide one
auto_create_naming = '.ansible-runner-'
auto_create_dir = None
AlanCoding marked this conversation as resolved.
Show resolved Hide resolved
7 changes: 7 additions & 0 deletions test/conftest.py
Expand Up @@ -2,6 +2,8 @@

from distutils.version import LooseVersion

from ansible_runner import defaults

import pkg_resources
import pytest

Expand All @@ -17,6 +19,11 @@ def mock_env_user(monkeypatch):
monkeypatch.setenv("ANSIBLE_DEVEL_WARNING", "False")


@pytest.fixture(autouse=True)
def change_save_path(tmp_path, mocker):
mocker.patch.object(defaults, 'auto_create_dir', str(tmp_path))
AlanCoding marked this conversation as resolved.
Show resolved Hide resolved


@pytest.fixture(scope='session')
def is_pre_ansible28():
try:
Expand Down