mirror of
https://github.com/ansible/awx.git
synced 2026-03-19 09:57:33 -02:30
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:
@@ -1,8 +1,4 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import os
|
||||
import tempfile
|
||||
import shutil
|
||||
|
||||
import pytest
|
||||
from unittest import mock
|
||||
|
||||
@@ -32,13 +28,12 @@ from ansible_base.lib.workload_identity.controller import AutomationControllerJo
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def private_data_dir():
|
||||
private_data = tempfile.mkdtemp(prefix='awx_')
|
||||
def private_data_dir(tmp_path):
|
||||
private_data = tmp_path / 'awx_pdd'
|
||||
private_data.mkdir()
|
||||
for subfolder in ('inventory', 'env'):
|
||||
runner_subfolder = os.path.join(private_data, subfolder)
|
||||
os.makedirs(runner_subfolder, exist_ok=True)
|
||||
yield private_data
|
||||
shutil.rmtree(private_data, True)
|
||||
(private_data / subfolder).mkdir()
|
||||
return str(private_data)
|
||||
|
||||
|
||||
@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)
|
||||
job = mock.MagicMock(
|
||||
spec=Job,
|
||||
pk=1,
|
||||
id=1,
|
||||
use_fact_cache=True,
|
||||
project=proj,
|
||||
organization=org,
|
||||
@@ -170,6 +167,8 @@ def test_pre_post_run_hook_facts_deleted_sliced(
|
||||
|
||||
# Mock job object
|
||||
job = mock.MagicMock(spec=Job)
|
||||
job.pk = 2
|
||||
job.id = 2
|
||||
job.use_fact_cache = True
|
||||
job.project = proj
|
||||
job.organization = org
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
|
||||
import fcntl
|
||||
@@ -60,14 +58,12 @@ class TestJobExecution(object):
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def private_data_dir():
|
||||
private_data = tempfile.mkdtemp(prefix='awx_')
|
||||
def private_data_dir(tmp_path):
|
||||
private_data = tmp_path / 'awx_pdd'
|
||||
private_data.mkdir()
|
||||
for subfolder in ('inventory', 'env'):
|
||||
runner_subfolder = os.path.join(private_data, subfolder)
|
||||
if not os.path.exists(runner_subfolder):
|
||||
os.mkdir(runner_subfolder)
|
||||
yield private_data
|
||||
shutil.rmtree(private_data, True)
|
||||
(private_data / subfolder).mkdir()
|
||||
return str(private_data)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
import shutil
|
||||
import os
|
||||
from uuid import uuid4
|
||||
|
||||
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
|
||||
|
||||
|
||||
def test_symlink_isolation_dir(request):
|
||||
rand_str = str(uuid4())[:8]
|
||||
dst_path = f'/tmp/ee_{rand_str}_symlink_dst'
|
||||
src_path = f'/tmp/ee_{rand_str}_symlink_src'
|
||||
def test_symlink_isolation_dir(tmp_path):
|
||||
src_path = tmp_path / 'symlink_src'
|
||||
dst_path = tmp_path / 'symlink_dst'
|
||||
|
||||
def remove_folders():
|
||||
os.unlink(dst_path)
|
||||
shutil.rmtree(src_path)
|
||||
|
||||
request.addfinalizer(remove_folders)
|
||||
os.mkdir(src_path)
|
||||
src_path.mkdir()
|
||||
os.symlink(src_path, dst_path)
|
||||
|
||||
pdd = f'{dst_path}/awx_xxx'
|
||||
|
||||
Reference in New Issue
Block a user