Merge pull request #28148 from basepi/fix.nodegroup.backwards.compat.24660

[2015.8] Only expand nodegroups to lists if there is a nested nodegroup
This commit is contained in:
Mike Place 2015-10-21 07:20:06 -06:00
commit dcd90363fe

View file

@ -100,11 +100,15 @@ def get_minion_data(minion, opts):
return minion if minion else None, None, None
def nodegroup_comp(nodegroup, nodegroups, skip=None):
def nodegroup_comp(nodegroup, nodegroups, skip=None, first_call=True):
'''
Recursively expand ``nodegroup`` from ``nodegroups``; ignore nodegroups in ``skip``
'''
If a top-level (non-recursive) call finds no nodegroups, return the original
nodegroup definition (for backwards compatibility). Keep track of recursive
calls via `first_call` argument
'''
expanded_nodegroup = False
if skip is None:
skip = set()
elif nodegroup in skip:
@ -134,7 +138,8 @@ def nodegroup_comp(nodegroup, nodegroups, skip=None):
if word in opers:
ret.append(word)
elif len(word) >= 3 and word.startswith('N@'):
ret.extend(nodegroup_comp(word[2:], nodegroups, skip=skip))
expanded_nodegroup = True
ret.extend(nodegroup_comp(word[2:], nodegroups, skip=skip, first_call=False))
else:
ret.append(word)
@ -145,7 +150,15 @@ def nodegroup_comp(nodegroup, nodegroups, skip=None):
skip.remove(nodegroup)
log.debug('nodegroup_comp({0}) => {1}'.format(nodegroup, ret))
return ret
# Only return list form if a nodegroup was expanded. Otherwise return
# the original string to conserve backwards compat
if expanded_nodegroup or not first_call:
return ret
else:
log.debug('No nested nodegroups detected. '
'Using original nodegroup definition: {0}'
.format(nodegroups[nodegroup]))
return nodegroups[nodegroup]
class CkMinions(object):