Skip to content

Commit

Permalink
NAS-130986 / 25.04 / fix cronjob API test regressions (#14411)
Browse files Browse the repository at this point in the history
* fix cronjob API test regressions

* no reason to sleep, just run the job
  • Loading branch information
yocalebo authored Sep 4, 2024
1 parent 3102736 commit 8ad3f58
Showing 1 changed file with 19 additions and 31 deletions.
50 changes: 19 additions & 31 deletions tests/api2/test_cronjob.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,28 @@
from time import sleep

import pytest

from middlewared.test.integration.utils import call, ssh

TESTFILE = '/tmp/.testFileCreatedViaCronjob'


def test_create_check_update_verify_cron_job():
cronjob_dict = {}

# create job
results = call("cronjob.create", {
'user': 'root',
'command': f'touch "{TESTFILE}"',
'schedule': {'minute': '*/1'}
})
cronjob_dict.update(results)
TESTFILE = '/mnt/cronjob_testfile'

# verify job creation
id = cronjob_dict['id']
results = call('cronjob.query', [['id', '=', id]], {"get": True})
assert results['enabled'] is True

# wait so job can run
sleep(65)
def test_cron_job():
try:
id = call(
'cronjob.create',
{
'user': 'root',
'enabled': True,
'command': f'echo "yeah" > "{TESTFILE}"',
'schedule': {'minute': '*/1'}
}
)['id']
assert call('cronjob.query', [['id', '=', id]], {"get": True})['enabled'] is True
except Exception as e:
assert False, f'Unexpected failure: {str(e)}'

# disable job
id = cronjob_dict['id']
call('cronjob.update', id, {'enabled': False})
call('cronjob.run', id, job=True)
assert call('filesystem.statfs', TESTFILE)['blocksize']

# remove test file
results = ssh(f'rm "{TESTFILE}"', complete_response=True)
assert results['result'] is True, results['output']

# delete job
call('cronjob.delete', cronjob_dict['id'])
results = call('cronjob.query', [['id', '=', id]], {"get": True})
assert results.json() == []
call('cronjob.delete', id)
assert call('cronjob.query', [['id', '=', id]]) == []

0 comments on commit 8ad3f58

Please sign in to comment.