mirror of
https://github.com/ansible/awx.git
synced 2026-01-21 14:38:00 -03:30
* Create a new pytest folder for live system testing with normal services (#15688) * PoC for running dev env tests * Replace in github actions * Move folder to better location * Further streamlining of new test folders * Consolidate fixture, add writeup docs * Use star import * Push the wait-for-job to the conftest Fix misused project cache identifier (#15690) Fix project cache identifiers for new updates Finish test and discover viable solution Add comment on related task code AAP-37989 Tests for exclude list with multiple jobs (#15722) * Tests for exclude list with multiple jobs Create test for using manual & file projects (#15754) * Create test for using a manual project * Chang default project factory to git, remove project files monkeypatch * skip update of factory project * Initial file scaffolding for feature * Fill in galaxy and names * Add README, describe project folders and dependencies Add ee cleanup tests * Adds cleanup tests to the live test. Fix rsyslog permission error in github ubuntu tests from apparmor (#15717) * Add test to detect rsyslog config problems * Get dmesg output * Disable apparmor for rsyslogd Make awx/main/tests/live dramatically faster (#15780) * Make awx/main/tests/live dramatically faster * Add new setting to exclude list * Fix rebase issues * Did not want to backport this
97 lines
3.0 KiB
Python
97 lines
3.0 KiB
Python
import pytest
|
|
import os
|
|
import tempfile
|
|
import shutil
|
|
|
|
from awx.main.tasks.jobs import RunJob
|
|
from awx.main.tasks.system import CleanupImagesAndFiles, execution_node_health_check
|
|
from awx.main.models import Instance, Job
|
|
|
|
|
|
@pytest.fixture
|
|
def scm_revision_file(tmpdir_factory):
|
|
# Returns path to temporary testing revision file
|
|
revision_file = tmpdir_factory.mktemp('revisions').join('revision.txt')
|
|
with open(str(revision_file), 'w') as f:
|
|
f.write('1234567890123456789012345678901234567890')
|
|
return os.path.join(revision_file.dirname, 'revision.txt')
|
|
|
|
|
|
@pytest.mark.django_db
|
|
@pytest.mark.parametrize('node_type', ('control. hybrid'))
|
|
def test_no_worker_info_on_AWX_nodes(node_type):
|
|
hostname = 'us-south-3-compute.invalid'
|
|
Instance.objects.create(hostname=hostname, node_type=node_type)
|
|
assert execution_node_health_check(hostname) is None
|
|
|
|
|
|
@pytest.fixture
|
|
def job_folder_factory(request):
|
|
def _rf(job_id='1234'):
|
|
pdd_path = tempfile.mkdtemp(prefix=f'awx_{job_id}_')
|
|
|
|
def test_folder_cleanup():
|
|
if os.path.exists(pdd_path):
|
|
shutil.rmtree(pdd_path)
|
|
|
|
request.addfinalizer(test_folder_cleanup)
|
|
|
|
return pdd_path
|
|
|
|
return _rf
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_job_folder(job_folder_factory):
|
|
return job_folder_factory()
|
|
|
|
|
|
@pytest.mark.django_db
|
|
def test_folder_cleanup_stale_file(mock_job_folder, mock_me):
|
|
CleanupImagesAndFiles.run()
|
|
assert os.path.exists(mock_job_folder) # grace period should protect folder from deletion
|
|
|
|
CleanupImagesAndFiles.run(grace_period=0)
|
|
assert not os.path.exists(mock_job_folder) # should be deleted
|
|
|
|
|
|
@pytest.mark.django_db
|
|
def test_folder_cleanup_running_job(mock_job_folder, me_inst):
|
|
job = Job.objects.create(id=1234, controller_node=me_inst.hostname, status='running')
|
|
CleanupImagesAndFiles.run(grace_period=0)
|
|
assert os.path.exists(mock_job_folder) # running job should prevent folder from getting deleted
|
|
|
|
job.status = 'failed'
|
|
job.save(update_fields=['status'])
|
|
CleanupImagesAndFiles.run(grace_period=0)
|
|
assert not os.path.exists(mock_job_folder) # job is finished and no grace period, should delete
|
|
|
|
|
|
@pytest.mark.django_db
|
|
def test_folder_cleanup_multiple_running_jobs(job_folder_factory, me_inst):
|
|
jobs = []
|
|
dirs = []
|
|
num_jobs = 3
|
|
|
|
for i in range(num_jobs):
|
|
job = Job.objects.create(controller_node=me_inst.hostname, status='running')
|
|
dirs.append(job_folder_factory(job.id))
|
|
jobs.append(job)
|
|
|
|
CleanupImagesAndFiles.run(grace_period=0)
|
|
|
|
assert [os.path.exists(d) for d in dirs] == [True for i in range(num_jobs)]
|
|
|
|
|
|
@pytest.mark.django_db
|
|
def test_does_not_run_reaped_job(mocker, mock_me):
|
|
job = Job.objects.create(status='failed', job_explanation='This job has been reaped.')
|
|
mock_run = mocker.patch('awx.main.tasks.jobs.ansible_runner.interface.run')
|
|
try:
|
|
RunJob().run(job.id)
|
|
except Exception:
|
|
pass
|
|
job.refresh_from_db()
|
|
assert job.status == 'failed'
|
|
mock_run.assert_not_called()
|