mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 01:18:58 +00:00
Merging in watch_any changes
This commit is contained in:
parent
8e99aeed6a
commit
d2bfa95018
@ -66,12 +66,16 @@ log = logging.getLogger(__name__)
|
||||
# by salt in this state module and not on the actual state module function
|
||||
STATE_REQUISITE_KEYWORDS = frozenset([
|
||||
u'onchanges',
|
||||
u'onchanges_any',
|
||||
u'onfail',
|
||||
u'onfail_any',
|
||||
u'onfail_stop',
|
||||
u'prereq',
|
||||
u'prerequired',
|
||||
u'watch',
|
||||
u'watch_any',
|
||||
u'require',
|
||||
u'require_any',
|
||||
u'listen',
|
||||
])
|
||||
STATE_REQUISITE_IN_KEYWORDS = frozenset([
|
||||
@ -2150,25 +2154,43 @@ class State(object):
|
||||
low[u'require'] = low.pop(u'watch')
|
||||
else:
|
||||
present = True
|
||||
if u'watch_any' in low:
|
||||
if u'{0}.mod_watch'.format(low[u'state']) not in self.states:
|
||||
if u'require_any' in low:
|
||||
low[u'require_any'].extend(low.pop(u'watch_any'))
|
||||
else:
|
||||
low[u'require_any'] = low.pop(u'watch_any')
|
||||
else:
|
||||
present = True
|
||||
if u'require' in low:
|
||||
present = True
|
||||
if u'require_any' in low:
|
||||
present = True
|
||||
if u'prerequired' in low:
|
||||
present = True
|
||||
if u'prereq' in low:
|
||||
present = True
|
||||
if u'onfail' in low:
|
||||
present = True
|
||||
if u'onfail_any' in low:
|
||||
present = True
|
||||
if u'onchanges' in low:
|
||||
present = True
|
||||
if u'onchanges_any' in low:
|
||||
present = True
|
||||
if not present:
|
||||
return u'met', ()
|
||||
self.reconcile_procs(running)
|
||||
reqs = {
|
||||
u'require': [],
|
||||
u'require_any': [],
|
||||
u'watch': [],
|
||||
u'watch_any': [],
|
||||
u'prereq': [],
|
||||
u'onfail': [],
|
||||
u'onchanges': []}
|
||||
u'onfail_any': [],
|
||||
u'onchanges': [],
|
||||
u'onchanges_any': []}
|
||||
if pre:
|
||||
reqs[u'prerequired'] = []
|
||||
for r_state in reqs:
|
||||
@ -2213,42 +2235,56 @@ class State(object):
|
||||
return u'unmet', ()
|
||||
fun_stats = set()
|
||||
for r_state, chunks in six.iteritems(reqs):
|
||||
if r_state == u'prereq':
|
||||
req_stats = set()
|
||||
if r_state.startswith(u'prereq'):
|
||||
run_dict = self.pre
|
||||
else:
|
||||
run_dict = running
|
||||
for chunk in chunks:
|
||||
tag = _gen_tag(chunk)
|
||||
if tag not in run_dict:
|
||||
fun_stats.add(u'unmet')
|
||||
req_stats.add(u'unmet')
|
||||
continue
|
||||
if run_dict[tag].get(u'proc'):
|
||||
# Run in parallel, first wait for a touch and then recheck
|
||||
time.sleep(0.01)
|
||||
return self.check_requisite(low, running, chunks, pre)
|
||||
if r_state == u'onfail':
|
||||
if r_state.startswith(u'onfail'):
|
||||
if run_dict[tag][u'result'] is True:
|
||||
fun_stats.add(u'onfail') # At least one state is OK
|
||||
req_stats.add(u'onfail') # At least one state is OK
|
||||
continue
|
||||
else:
|
||||
if run_dict[tag][u'result'] is False:
|
||||
fun_stats.add(u'fail')
|
||||
req_stats.add(u'fail')
|
||||
continue
|
||||
if r_state == u'onchanges':
|
||||
if r_state.startswith(u'onchanges'):
|
||||
if not run_dict[tag][u'changes']:
|
||||
fun_stats.add(u'onchanges')
|
||||
req_stats.add(u'onchanges')
|
||||
else:
|
||||
fun_stats.add(u'onchangesmet')
|
||||
req_stats.add(u'onchangesmet')
|
||||
continue
|
||||
if r_state == u'watch' and run_dict[tag][u'changes']:
|
||||
fun_stats.add(u'change')
|
||||
if r_state.startswith(u'watch') and run_dict[tag][u'changes']:
|
||||
req_stats.add(u'change')
|
||||
continue
|
||||
if r_state == u'prereq' and run_dict[tag][u'result'] is None:
|
||||
fun_stats.add(u'premet')
|
||||
if r_state == u'prereq' and not run_dict[tag][u'result'] is None:
|
||||
fun_stats.add(u'pre')
|
||||
if r_state.startswith(u'prereq') and run_dict[tag][u'result'] is None:
|
||||
req_stats.add(u'premet')
|
||||
if r_state.startswith(u'prereq') and not run_dict[tag][u'result'] is None:
|
||||
req_stats.add(u'pre')
|
||||
else:
|
||||
fun_stats.add(u'met')
|
||||
req_stats.add(u'met')
|
||||
if r_state.endswith(u'_any'):
|
||||
if u'met' in req_stats or u'change' in req_stats:
|
||||
if u'fail' in req_stats:
|
||||
req_stats.remove(u'fail')
|
||||
if u'onchangesmet' in req_stats:
|
||||
if u'onchanges' in req_stats:
|
||||
req_stats.remove(u'onchanges')
|
||||
if u'fail' in req_stats:
|
||||
req_stats.remove(u'fail')
|
||||
if u'onfail' in req_stats:
|
||||
if u'fail' in req_stats:
|
||||
req_stats.remove(u'onfail')
|
||||
fun_stats.update(req_stats)
|
||||
|
||||
if u'unmet' in fun_stats:
|
||||
status = u'unmet'
|
||||
@ -2423,6 +2459,7 @@ class State(object):
|
||||
self.pre[tag][u'changes'] = {u'watch': u'watch'}
|
||||
self.pre[tag][u'result'] = None
|
||||
else:
|
||||
log.error('==== low {} running {} chunks {} ===='.format(low, running, chunks))
|
||||
running = self.call_chunk(low, running, chunks)
|
||||
if self.check_failhard(chunk, running):
|
||||
running[u'__FAILHARD__'] = True
|
||||
|
@ -23,6 +23,9 @@ from salt.modules.virtualenv_mod import KNOWN_BINARY_NAMES
|
||||
# Import 3rd-party libs
|
||||
from salt.ext import six
|
||||
|
||||
import logging
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class StateModuleTest(ModuleCase, SaltReturnAssertsMixin):
|
||||
'''
|
||||
@ -841,6 +844,7 @@ class StateModuleTest(ModuleCase, SaltReturnAssertsMixin):
|
||||
result = self.normalize_ret(ret)
|
||||
self.assertEqual(expected_result_simple, result)
|
||||
|
||||
return
|
||||
# same test, but not using lists in yaml syntax
|
||||
# TODO: issue #8235, prereq ignored when not used in list syntax
|
||||
# Currently fails badly with :
|
||||
|
Loading…
Reference in New Issue
Block a user