Rework code that handles individual jobs being disabled and scheduler being globally being disabled. Previously disabling the schedule would result in individual jobs being disabled when they were run through eval. This change does not change schedule items.

This commit is contained in:
Gareth J. Greenaway 2019-09-30 16:15:28 -07:00
parent b61b30db7d
commit be15a286b0
No known key found for this signature in database
GPG key ID: 10B62F8A7CAD7A41
2 changed files with 10 additions and 24 deletions

View file

@ -1596,22 +1596,10 @@ class Schedule(object):
if '_continue' in data and data['_continue']:
run = False
# If there is no job specific enabled available,
# grab the global which defaults to True.
if 'enabled' not in data:
data['enabled'] = self.enabled
# If globally disabled, disable the job
if not self.enabled:
data['enabled'] = self.enabled
data['_skip_reason'] = 'disabled'
data['_skipped_time'] = now
data['_skipped'] = True
run = False
# Job is disabled, set run to False
if 'enabled' in data and not data['enabled']:
data['_enabled'] = False
# If globally disabled or job
# is diabled skip the job
if not self.enabled or not data.get('enabled', True):
log.trace('Job: %s is disabled', job_name)
data['_skip_reason'] = 'disabled'
data['_skipped_time'] = now
data['_skipped'] = True
@ -1624,14 +1612,6 @@ class Schedule(object):
try:
if run:
# Job is disabled, continue
if 'enabled' in data and not data['enabled']:
log.debug('Job: %s is disabled', job_name)
data['_skip_reason'] = 'disabled'
data['_skipped_time'] = now
data['_skipped'] = True
continue
if 'jid_include' not in data or data['jid_include']:
data['jid_include'] = True
log.debug('schedule: Job %s was scheduled with jid_include, '

View file

@ -506,6 +506,9 @@ class SchedulerEvalTest(ModuleCase, SaltReturnAssertsMixin):
self.assertNotIn('_last_run', ret)
self.assertEqual(ret['_skip_reason'], 'disabled')
# Ensure job data still matches
self.assertEqual(ret, job['schedule'][job_name])
def test_eval_global_disabled_job_enabled(self):
'''
verify that scheduled job does not run
@ -532,6 +535,9 @@ class SchedulerEvalTest(ModuleCase, SaltReturnAssertsMixin):
self.assertNotIn('_last_run', ret)
self.assertEqual(ret['_skip_reason'], 'disabled')
# Ensure job is still enabled
self.assertEqual(ret['enabled'], True)
def test_eval_run_on_start(self):
'''
verify that scheduled job is run when minion starts