mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Moving scheduler tests into a new location. Adding new TEST_SUITE to runtests.py. Add CLI flag to runtests.py so the scheduler tests can be run invidually.
This commit is contained in:
parent
2a2d54605f
commit
9797922c8b
5 changed files with 163 additions and 70 deletions
1
tests/integration/scheduler/__init__.py
Normal file
1
tests/integration/scheduler/__init__.py
Normal file
|
@ -0,0 +1 @@
|
|||
# -*- coding: utf-8 -*-
|
69
tests/integration/scheduler/test_eval.py
Normal file
69
tests/integration/scheduler/test_eval.py
Normal file
|
@ -0,0 +1,69 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Import Python libs
|
||||
from __future__ import absolute_import
|
||||
import copy
|
||||
import logging
|
||||
import os
|
||||
|
||||
# Import Salt Testing libs
|
||||
from tests.support.case import ModuleCase
|
||||
from tests.support.mixins import SaltReturnAssertsMixin
|
||||
|
||||
# Import Salt Testing Libs
|
||||
from tests.support.mock import MagicMock, patch
|
||||
import tests.integration as integration
|
||||
|
||||
# Import Salt libs
|
||||
import salt.utils.schedule
|
||||
|
||||
from salt.modules.test import ping as ping
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
ROOT_DIR = os.path.join(integration.TMP, 'schedule-unit-tests')
|
||||
SOCK_DIR = os.path.join(ROOT_DIR, 'test-socks')
|
||||
|
||||
DEFAULT_CONFIG = salt.config.minion_config(None)
|
||||
DEFAULT_CONFIG['conf_dir'] = ROOT_DIR
|
||||
DEFAULT_CONFIG['root_dir'] = ROOT_DIR
|
||||
DEFAULT_CONFIG['sock_dir'] = SOCK_DIR
|
||||
DEFAULT_CONFIG['pki_dir'] = os.path.join(ROOT_DIR, 'pki')
|
||||
DEFAULT_CONFIG['cachedir'] = os.path.join(ROOT_DIR, 'cache')
|
||||
|
||||
|
||||
class SchedulerEvalTest(ModuleCase, SaltReturnAssertsMixin):
|
||||
'''
|
||||
Validate the pkg module
|
||||
'''
|
||||
def setUp(self):
|
||||
with patch('salt.utils.schedule.clean_proc_dir', MagicMock(return_value=None)):
|
||||
functions = {'test.ping': ping}
|
||||
self.schedule = salt.utils.schedule.Schedule(copy.deepcopy(DEFAULT_CONFIG), functions, returners={})
|
||||
|
||||
def test_eval(self):
|
||||
'''
|
||||
verify that scheduled job runs
|
||||
'''
|
||||
job = {
|
||||
'schedule': {
|
||||
'job1': {
|
||||
'function': 'test.ping',
|
||||
'when': '11/29/2017 4pm',
|
||||
}
|
||||
}
|
||||
}
|
||||
run_time1 = 1512000000 - 1
|
||||
run_time2 = 1512000000
|
||||
|
||||
# Add the job to the scheduler
|
||||
self.schedule.opts.update(job)
|
||||
|
||||
# Evaluate 1 second before the run time
|
||||
self.schedule.eval(now=run_time1)
|
||||
ret = self.schedule.job_status('job1')
|
||||
self.assertNotIn('_last_run', ret)
|
||||
|
||||
# Evaluate 1 second at the run time
|
||||
self.schedule.eval(now=run_time2)
|
||||
ret = self.schedule.job_status('job1')
|
||||
self.assertEqual(ret['_last_run'], run_time2)
|
82
tests/integration/scheduler/test_postpone.py
Normal file
82
tests/integration/scheduler/test_postpone.py
Normal file
|
@ -0,0 +1,82 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Import Python libs
|
||||
from __future__ import absolute_import
|
||||
import copy
|
||||
import logging
|
||||
import os
|
||||
|
||||
# Import Salt Testing libs
|
||||
from tests.support.case import ModuleCase
|
||||
from tests.support.mixins import SaltReturnAssertsMixin
|
||||
|
||||
# Import Salt Testing Libs
|
||||
from tests.support.mock import MagicMock, patch
|
||||
import tests.integration as integration
|
||||
|
||||
# Import Salt libs
|
||||
import salt.utils.schedule
|
||||
|
||||
from salt.modules.test import ping as ping
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
ROOT_DIR = os.path.join(integration.TMP, 'schedule-unit-tests')
|
||||
SOCK_DIR = os.path.join(ROOT_DIR, 'test-socks')
|
||||
|
||||
DEFAULT_CONFIG = salt.config.minion_config(None)
|
||||
DEFAULT_CONFIG['conf_dir'] = ROOT_DIR
|
||||
DEFAULT_CONFIG['root_dir'] = ROOT_DIR
|
||||
DEFAULT_CONFIG['sock_dir'] = SOCK_DIR
|
||||
DEFAULT_CONFIG['pki_dir'] = os.path.join(ROOT_DIR, 'pki')
|
||||
DEFAULT_CONFIG['cachedir'] = os.path.join(ROOT_DIR, 'cache')
|
||||
|
||||
|
||||
class SchedulerPostponeTest(ModuleCase, SaltReturnAssertsMixin):
|
||||
'''
|
||||
Validate the pkg module
|
||||
'''
|
||||
def setUp(self):
|
||||
with patch('salt.utils.schedule.clean_proc_dir', MagicMock(return_value=None)):
|
||||
functions = {'test.ping': ping}
|
||||
self.schedule = salt.utils.schedule.Schedule(copy.deepcopy(DEFAULT_CONFIG), functions, returners={})
|
||||
|
||||
def test_postpone(self):
|
||||
'''
|
||||
verify that scheduled job is postponed until the specified time.
|
||||
'''
|
||||
job = {
|
||||
'schedule': {
|
||||
'job1': {
|
||||
'function': 'test.ping',
|
||||
'when': '11/29/2017 4pm',
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# 11/29/2017 4pm
|
||||
run_time = 1512000000
|
||||
|
||||
# 5 minute delay
|
||||
delay = 300
|
||||
|
||||
# Add job to schedule
|
||||
self.schedule.opts.update(job)
|
||||
|
||||
# Postpone the job by 5 minutes
|
||||
self.schedule.postpone_job('job1', {'time': run_time,
|
||||
'new_time': run_time + delay})
|
||||
|
||||
# Run at the original time
|
||||
self.schedule.eval(now=run_time)
|
||||
ret = self.schedule.job_status('job1')
|
||||
self.assertNotIn('_last_run', ret)
|
||||
|
||||
# Run 5 minutes later
|
||||
self.schedule.eval(now=run_time + delay)
|
||||
ret = self.schedule.job_status('job1')
|
||||
self.assertEqual(ret['_last_run'], run_time + delay)
|
||||
|
||||
# Run 6 minutes later
|
||||
self.schedule.eval(now=run_time + delay + 1)
|
||||
ret = self.schedule.job_status('job1')
|
||||
self.assertEqual(ret['_last_run'], run_time + delay)
|
|
@ -31,7 +31,7 @@ DEFAULT_CONFIG['pki_dir'] = os.path.join(ROOT_DIR, 'pki')
|
|||
DEFAULT_CONFIG['cachedir'] = os.path.join(ROOT_DIR, 'cache')
|
||||
|
||||
|
||||
class SchedulerTest(ModuleCase, SaltReturnAssertsMixin):
|
||||
class SchedulerSkipTest(ModuleCase, SaltReturnAssertsMixin):
|
||||
'''
|
||||
Validate the pkg module
|
||||
'''
|
||||
|
@ -40,34 +40,6 @@ class SchedulerTest(ModuleCase, SaltReturnAssertsMixin):
|
|||
functions = {'test.ping': ping}
|
||||
self.schedule = salt.utils.schedule.Schedule(copy.deepcopy(DEFAULT_CONFIG), functions, returners={})
|
||||
|
||||
def test_eval(self):
|
||||
'''
|
||||
verify that scheduled job runs
|
||||
'''
|
||||
job = {
|
||||
'schedule': {
|
||||
'job1': {
|
||||
'function': 'test.ping',
|
||||
'when': '11/29/2017 4pm',
|
||||
}
|
||||
}
|
||||
}
|
||||
run_time1 = 1512000000 - 1
|
||||
run_time2 = 1512000000
|
||||
|
||||
# Add the job to the scheduler
|
||||
self.schedule.opts.update(job)
|
||||
|
||||
# Evaluate 1 second before the run time
|
||||
self.schedule.eval(now=run_time1)
|
||||
ret = self.schedule.job_status('job1')
|
||||
self.assertNotIn('_last_run', ret)
|
||||
|
||||
# Evaluate 1 second at the run time
|
||||
self.schedule.eval(now=run_time2)
|
||||
ret = self.schedule.job_status('job1')
|
||||
self.assertEqual(ret['_last_run'], run_time2)
|
||||
|
||||
def test_skip(self):
|
||||
'''
|
||||
verify that scheduled job is skipped at the specified time
|
||||
|
@ -98,47 +70,6 @@ class SchedulerTest(ModuleCase, SaltReturnAssertsMixin):
|
|||
ret = self.schedule.job_status('job1')
|
||||
self.assertEqual(ret['_last_run'], run_time)
|
||||
|
||||
def test_postpone(self):
|
||||
'''
|
||||
verify that scheduled job is postponed until the specified time.
|
||||
'''
|
||||
job = {
|
||||
'schedule': {
|
||||
'job1': {
|
||||
'function': 'test.ping',
|
||||
'when': '11/29/2017 4pm',
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# 11/29/2017 4pm
|
||||
run_time = 1512000000
|
||||
|
||||
# 5 minute delay
|
||||
delay = 300
|
||||
|
||||
# Add job to schedule
|
||||
self.schedule.opts.update(job)
|
||||
|
||||
# Postpone the job by 5 minutes
|
||||
self.schedule.postpone_job('job1', {'time': run_time,
|
||||
'new_time': run_time + delay})
|
||||
|
||||
# Run at the original time
|
||||
self.schedule.eval(now=run_time)
|
||||
ret = self.schedule.job_status('job1')
|
||||
self.assertNotIn('_last_run', ret)
|
||||
|
||||
# Run 5 minutes later
|
||||
self.schedule.eval(now=run_time + delay)
|
||||
ret = self.schedule.job_status('job1')
|
||||
self.assertEqual(ret['_last_run'], run_time + delay)
|
||||
|
||||
# Run 6 minutes later
|
||||
self.schedule.eval(now=run_time + delay + 1)
|
||||
ret = self.schedule.job_status('job1')
|
||||
self.assertEqual(ret['_last_run'], run_time + delay)
|
||||
|
||||
def test_skip_during_range(self):
|
||||
'''
|
||||
verify that scheduled job is skipped during the specified range
|
|
@ -172,6 +172,9 @@ TEST_SUITES = {
|
|||
'daemons':
|
||||
{'display_name': 'Daemon',
|
||||
'path': 'integration/daemons'},
|
||||
'scheduler':
|
||||
{'display_name': 'Scheduler',
|
||||
'path': 'integration/scheduler'},
|
||||
}
|
||||
|
||||
|
||||
|
@ -479,6 +482,13 @@ class SaltTestsuiteParser(SaltCoverageTestingParser):
|
|||
default=False,
|
||||
help='Run salt/daemons/*.py tests'
|
||||
)
|
||||
self.test_selection_group.add_option(
|
||||
'--scheduler',
|
||||
dest='scheduler',
|
||||
action='store_true',
|
||||
default=False,
|
||||
help='Run scheduler integration tests'
|
||||
)
|
||||
|
||||
def validate_options(self):
|
||||
if self.options.cloud_provider or self.options.external_api:
|
||||
|
|
Loading…
Add table
Reference in a new issue