Skip to content

Commit

Permalink
Global enable/disable was being ignored
Browse files Browse the repository at this point in the history
  • Loading branch information
garethgreenaway committed Feb 26, 2019
1 parent 27dd9fb commit 72466a5
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 6 deletions.
24 changes: 18 additions & 6 deletions salt/utils/schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def _check_max_running(self, func, data, opts, now):
)
data['_skip_reason'] = 'maxrunning'
data['_skipped'] = True
data['_skip_time'] = now
data['_skipped_time'] = now
data['run'] = False
return data
return data
Expand Down Expand Up @@ -357,7 +357,7 @@ def add_job(self, data, persist=True):
# assume job is enabled.
for job in data:
if 'enabled' not in data[job]:
data[job]['enabled'] = True
data[job]['_enabled'] = True

new_job = next(six.iterkeys(data))

Expand Down Expand Up @@ -1378,8 +1378,10 @@ def _chop_ms(dt):
# Clear these out between runs
for item in ['_continue',
'_error',
'_enabled',
'_skipped',
'_skip_reason']:
'_skip_reason',
'_skipped_time']:
if item in data:
del data[item]
run = False
Expand Down Expand Up @@ -1598,12 +1600,22 @@ def _chop_ms(dt):
# If there is no job specific enabled available,
# grab the global which defaults to True.
if 'enabled' not in data:
data['enabled'] = self.enabled
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']:
log.debug('Job: %s is disabled', job_name)
data['_enabled'] = False
data['_skip_reason'] = 'disabled'
data['_skipped_time'] = now
data['_skipped'] = True
run = False

miss_msg = ''
Expand All @@ -1614,7 +1626,7 @@ def _chop_ms(dt):
try:
if run:
# Job is disabled, continue
if 'enabled' in data and not data['enabled']:
if '_enabled' in data and not data['_enabled']:
log.debug('Job: %s is disabled', job_name)
data['_skip_reason'] = 'disabled'
data['_skipped_time'] = now
Expand Down
26 changes: 26 additions & 0 deletions tests/integration/scheduler/test_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,32 @@ def test_eval_disabled(self):
self.assertNotIn('_last_run', ret)
self.assertEqual(ret['_skip_reason'], 'disabled')

def test_eval_global_disabled_job_enabled(self):
'''
verify that scheduled job does not run
'''
job_name = 'test_eval_global_disabled'
job = {
'schedule': {
'enabled': False,
job_name: {
'function': 'test.ping',
'when': '11/29/2017 4:00pm',
'enabled': True,
}
}
}
run_time1 = dateutil_parser.parse('11/29/2017 4:00pm')

# Add the job to the scheduler
self.schedule.opts.update(job)

# Evaluate 1 second at the run time
self.schedule.eval(now=run_time1)
ret = self.schedule.job_status(job_name)
self.assertNotIn('_last_run', ret)
self.assertEqual(ret['_skip_reason'], 'disabled')

def test_eval_run_on_start(self):
'''
verify that scheduled job is run when minion starts
Expand Down

0 comments on commit 72466a5

Please sign in to comment.