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

[release_2.1] Write auto-created private data dirs to pytest dir instead of /tmp (#916) #941

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
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)

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
Original file line number Diff line number Diff line change
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
7 changes: 7 additions & 0 deletions test/conftest.py
Original file line number Diff line number Diff line change
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))


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