Merge pull request #46337 from gtmanfred/2017.7

Fix using names with listen and listen_in
This commit is contained in:
Nicole Thomas 2018-03-12 14:49:59 -04:00 committed by GitHub
commit 22d753364b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 73 additions and 25 deletions

View file

@ -2489,14 +2489,13 @@ class State(object):
listeners = []
crefs = {}
for chunk in chunks:
crefs[(chunk['state'], chunk['name'])] = chunk
crefs[(chunk['state'], chunk['__id__'])] = chunk
crefs[(chunk['state'], chunk['__id__'], chunk['name'])] = chunk
if 'listen' in chunk:
listeners.append({(chunk['state'], chunk['__id__']): chunk['listen']})
listeners.append({(chunk['state'], chunk['__id__'], chunk['name']): chunk['listen']})
if 'listen_in' in chunk:
for l_in in chunk['listen_in']:
for key, val in six.iteritems(l_in):
listeners.append({(key, val): [{chunk['state']: chunk['__id__']}]})
listeners.append({(key, val, 'lookup'): [{chunk['state']: chunk['__id__']}]})
mod_watchers = []
errors = {}
for l_dict in listeners:
@ -2505,7 +2504,7 @@ class State(object):
if not isinstance(listen_to, dict):
continue
for lkey, lval in six.iteritems(listen_to):
if (lkey, lval) not in crefs:
if not any(lkey == cref[0] and lval in cref for cref in crefs):
rerror = {_l_tag(lkey, lval):
{
'comment': 'Referenced state {0}: {1} does not exist'.format(lkey, lval),
@ -2515,27 +2514,32 @@ class State(object):
}}
errors.update(rerror)
continue
to_tag = _gen_tag(crefs[(lkey, lval)])
if to_tag not in running:
continue
if running[to_tag]['changes']:
if key not in crefs:
rerror = {_l_tag(key[0], key[1]):
{'comment': 'Referenced state {0}: {1} does not exist'.format(key[0], key[1]),
'name': 'listen_{0}:{1}'.format(key[0], key[1]),
'result': False,
'changes': {}}}
errors.update(rerror)
to_tags = [
_gen_tag(data) for cref, data in six.iteritems(crefs) if lkey == cref[0] and lval in cref
]
for to_tag in to_tags:
if to_tag not in running:
continue
chunk = crefs[key]
low = chunk.copy()
low['sfun'] = chunk['fun']
low['fun'] = 'mod_watch'
low['__id__'] = 'listener_{0}'.format(low['__id__'])
for req in STATE_REQUISITE_KEYWORDS:
if req in low:
low.pop(req)
mod_watchers.append(low)
if running[to_tag]['changes']:
if not any(key[0] == cref[0] and key[1] in cref for cref in crefs):
rerror = {_l_tag(key[0], key[1]):
{'comment': 'Referenced state {0}: {1} does not exist'.format(key[0], key[1]),
'name': 'listen_{0}:{1}'.format(key[0], key[1]),
'result': False,
'changes': {}}}
errors.update(rerror)
continue
new_chunks = [data for cref, data in six.iteritems(crefs) if key[0] == cref[0] and key[1] in cref]
for chunk in new_chunks:
low = chunk.copy()
low['sfun'] = chunk['fun']
low['fun'] = 'mod_watch'
low['__id__'] = 'listener_{0}'.format(low['__id__'])
for req in STATE_REQUISITE_KEYWORDS:
if req in low:
low.pop(req)
mod_watchers.append(low)
ret = self.call_chunks(mod_watchers)
running.update(ret)
for err in errors:

View file

@ -0,0 +1,11 @@
test:
test.succeed_with_changes:
- name: test
- listen_in:
- test: service
service:
test.succeed_without_changes:
- names:
- nginx
- crond

View file

@ -0,0 +1,11 @@
test:
test.succeed_with_changes:
- name: test
service:
test.succeed_without_changes:
- names:
- nginx
- crond
- listen:
- test: test

View file

@ -1156,6 +1156,28 @@ class StateModuleTest(ModuleCase, SaltReturnAssertsMixin):
listener_state = 'cmd_|-listener_test_listening_resolution_two_|-echo "Successful listen resolution"_|-mod_watch'
self.assertIn(listener_state, state_run)
def test_listen_in_requisite_resolution_names(self):
'''
Verify listen_in requisite lookups use ID declaration to check for changes
and resolves magic names state variable
'''
# Only run the state once and keep the return data
state_run = self.run_function('state.sls', mods='requisites.listen_in_names')
self.assertIn('test_|-listener_service_|-nginx_|-mod_watch', state_run)
self.assertIn('test_|-listener_service_|-crond_|-mod_watch', state_run)
def test_listen_requisite_resolution_names(self):
'''
Verify listen requisite lookups use ID declaration to check for changes
and resolves magic names state variable
'''
# Only run the state once and keep the return data
state_run = self.run_function('state.sls', mods='requisites.listen_names')
self.assertIn('test_|-listener_service_|-nginx_|-mod_watch', state_run)
self.assertIn('test_|-listener_service_|-crond_|-mod_watch', state_run)
def test_issue_30820_requisite_in_match_by_name(self):
'''
This tests the case where a requisite_in matches by name instead of ID