Fixing a bug that occurs if the "enabled" key is present in the scheduler items dictionary. Adding a test to ensure scheduler runs as expected when that key is present.

This commit is contained in:
Gareth J. Greenaway 2018-08-08 11:44:13 -07:00
parent b87bf905c2
commit 8935c08141
No known key found for this signature in database
GPG key ID: 10B62F8A7CAD7A41
2 changed files with 35 additions and 3 deletions

View file

@ -843,15 +843,15 @@ class Schedule(object):
'skip_during_range']
for job, data in six.iteritems(schedule):
if job in _hidden:
continue
# Clear out _skip_reason from previous runs
if '_skip_reason' in data:
del data['_skip_reason']
run = False
if job in _hidden:
continue
if not isinstance(data, dict):
log.error(
'Scheduled job "%s" should have a dict value, not %s',

View file

@ -397,3 +397,35 @@ class SchedulerEvalTest(ModuleCase, SaltReturnAssertsMixin):
self.schedule.eval(now=run_time)
ret = self.schedule.job_status('job1')
self.assertEqual(ret['_last_run'], run_time)
def test_eval_enabled(self):
'''
verify that scheduled job runs
when the enabled key is in place
https://github.com/saltstack/salt/issues/47695
'''
job = {
'schedule': {
'enabled': True,
'job1': {
'function': 'test.ping',
'when': '11/29/2017 4:00pm',
}
}
}
run_time2 = dateutil_parser.parse('11/29/2017 4:00pm')
run_time1 = run_time2 - datetime.timedelta(seconds=1)
# 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)