mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge pull request #31471 from cachedout/issue_31427
Correct issue where duplicate items in grains list during state run will result in duplicate grains
This commit is contained in:
commit
625da0d261
3 changed files with 26 additions and 3 deletions
|
@ -128,14 +128,12 @@ def list_present(name, value, delimiter=DEFAULT_TARGET_DELIM):
|
|||
- web
|
||||
- dev
|
||||
'''
|
||||
|
||||
name = re.sub(delimiter, DEFAULT_TARGET_DELIM, name)
|
||||
ret = {'name': name,
|
||||
'changes': {},
|
||||
'result': True,
|
||||
'comment': ''}
|
||||
grain = __salt__['grains.get'](name)
|
||||
|
||||
if grain:
|
||||
# check whether grain is a list
|
||||
if not isinstance(grain, list):
|
||||
|
@ -146,6 +144,17 @@ def list_present(name, value, delimiter=DEFAULT_TARGET_DELIM):
|
|||
if set(value).issubset(set(__salt__['grains.get'](name))):
|
||||
ret['comment'] = 'Value {1} is already in grain {0}'.format(name, value)
|
||||
return ret
|
||||
elif name in __context__.get('pending_grains', {}):
|
||||
# elements common to both
|
||||
intersection = set(value).intersection(__context__.get('pending_grains', {})[name])
|
||||
if intersection:
|
||||
value = list(set(value).difference(__context__['pending_grains'][name]))
|
||||
ret['comment'] = 'Removed value {0} from update due to context found in "{1}".\n'.format(value, name)
|
||||
if 'pending_grains' not in __context__:
|
||||
__context__['pending_grains'] = {}
|
||||
if name not in __context__['pending_grains']:
|
||||
__context__['pending_grains'][name] = set()
|
||||
__context__['pending_grains'][name].update(value)
|
||||
else:
|
||||
if value in grain:
|
||||
ret['comment'] = 'Value {1} is already in grain {0}'.format(name, value)
|
||||
|
|
15
tests/integration/files/file/base/issue-31427.sls
Normal file
15
tests/integration/files/file/base/issue-31427.sls
Normal file
|
@ -0,0 +1,15 @@
|
|||
roles:
|
||||
grains.list_present:
|
||||
- name: roles
|
||||
- value:
|
||||
- elliptic
|
||||
- parabolic
|
||||
- hyperbolic
|
||||
|
||||
additional-roles:
|
||||
grains.list_present:
|
||||
- name: roles
|
||||
- value:
|
||||
- hyperbolic
|
||||
- diabolic
|
||||
|
|
@ -100,7 +100,6 @@ class TestModulesGrains(integration.ModuleCase):
|
|||
['level1:level2']),
|
||||
'foo')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
from integration import run_tests
|
||||
run_tests(TestModulesGrains)
|
||||
|
|
Loading…
Add table
Reference in a new issue