Skip to content

Commit

Permalink
[release_2.0] Write auto-created private data dirs to pytest dir inst…
Browse files Browse the repository at this point in the history
…ead of /tmp (ansible#916) (ansible#942)

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

Backport of ansible#916 for Ansible Runner 2.0.

Reviewed-by: David Shrewsbury <None>
Reviewed-by: None <None>
  • Loading branch information
samdoran committed Dec 14, 2021
1 parent 17959b8 commit ce45e49
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ansible_runner/config/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,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
@@ -1,2 +1,7 @@
default_process_isolation_executable = 'podman'
default_container_image = 'quay.io/ansible/ansible-runner:devel'

# 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

0 comments on commit ce45e49

Please sign in to comment.