Stop writing tmp test files that are not cleaned up (#16358)

* Stop writing tmp test files that are not cleaned up
This commit is contained in:
Alan Rominger
2026-03-17 17:02:47 -04:00
committed by GitHub
parent 1646694258
commit cc2fbf332c
3 changed files with 18 additions and 31 deletions

View File

@@ -1,8 +1,4 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import os
import tempfile
import shutil
import pytest import pytest
from unittest import mock from unittest import mock
@@ -32,13 +28,12 @@ from ansible_base.lib.workload_identity.controller import AutomationControllerJo
@pytest.fixture @pytest.fixture
def private_data_dir(): def private_data_dir(tmp_path):
private_data = tempfile.mkdtemp(prefix='awx_') private_data = tmp_path / 'awx_pdd'
private_data.mkdir()
for subfolder in ('inventory', 'env'): for subfolder in ('inventory', 'env'):
runner_subfolder = os.path.join(private_data, subfolder) (private_data / subfolder).mkdir()
os.makedirs(runner_subfolder, exist_ok=True) return str(private_data)
yield private_data
shutil.rmtree(private_data, True)
@pytest.fixture @pytest.fixture
@@ -101,6 +96,8 @@ def test_pre_post_run_hook_facts(mock_create_partition, mock_facts_settings, pri
proj = mock.MagicMock(spec=Project, pk=1, organization=org) proj = mock.MagicMock(spec=Project, pk=1, organization=org)
job = mock.MagicMock( job = mock.MagicMock(
spec=Job, spec=Job,
pk=1,
id=1,
use_fact_cache=True, use_fact_cache=True,
project=proj, project=proj,
organization=org, organization=org,
@@ -170,6 +167,8 @@ def test_pre_post_run_hook_facts_deleted_sliced(
# Mock job object # Mock job object
job = mock.MagicMock(spec=Job) job = mock.MagicMock(spec=Job)
job.pk = 2
job.id = 2
job.use_fact_cache = True job.use_fact_cache = True
job.project = proj job.project = proj
job.organization = org job.organization = org

View File

@@ -1,8 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import json import json
import os import os
import shutil
import tempfile
from pathlib import Path from pathlib import Path
import fcntl import fcntl
@@ -60,14 +58,12 @@ class TestJobExecution(object):
@pytest.fixture @pytest.fixture
def private_data_dir(): def private_data_dir(tmp_path):
private_data = tempfile.mkdtemp(prefix='awx_') private_data = tmp_path / 'awx_pdd'
private_data.mkdir()
for subfolder in ('inventory', 'env'): for subfolder in ('inventory', 'env'):
runner_subfolder = os.path.join(private_data, subfolder) (private_data / subfolder).mkdir()
if not os.path.exists(runner_subfolder): return str(private_data)
os.mkdir(runner_subfolder)
yield private_data
shutil.rmtree(private_data, True)
@pytest.fixture @pytest.fixture

View File

@@ -1,6 +1,4 @@
import shutil
import os import os
from uuid import uuid4
import pytest import pytest
@@ -24,17 +22,11 @@ def test_switch_paths(container_path, host_path):
assert get_incontainer_path(host_path, private_data_dir) == container_path assert get_incontainer_path(host_path, private_data_dir) == container_path
def test_symlink_isolation_dir(request): def test_symlink_isolation_dir(tmp_path):
rand_str = str(uuid4())[:8] src_path = tmp_path / 'symlink_src'
dst_path = f'/tmp/ee_{rand_str}_symlink_dst' dst_path = tmp_path / 'symlink_dst'
src_path = f'/tmp/ee_{rand_str}_symlink_src'
def remove_folders(): src_path.mkdir()
os.unlink(dst_path)
shutil.rmtree(src_path)
request.addfinalizer(remove_folders)
os.mkdir(src_path)
os.symlink(src_path, dst_path) os.symlink(src_path, dst_path)
pdd = f'{dst_path}/awx_xxx' pdd = f'{dst_path}/awx_xxx'