mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Check for duplicate grains during list insertion
Insert grains into context so that we can know if we're duplicating during multiple inserts in a state run. Refs #31427
This commit is contained in:
parent
42027e0d72
commit
3d2aec05e5
2 changed files with 20 additions and 0 deletions
|
@ -146,6 +146,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)
|
||||
|
|
|
@ -100,6 +100,15 @@ class TestModulesGrains(integration.ModuleCase):
|
|||
['level1:level2']),
|
||||
'foo')
|
||||
|
||||
def test_list_present_distinct(self):
|
||||
'''
|
||||
Test a case where two states are run and both attempt to update a list
|
||||
of grains, resulting in duplicate keys.
|
||||
|
||||
This issue is fully outlined in GitHub issue #31427
|
||||
'''
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
from integration import run_tests
|
||||
|
|
Loading…
Add table
Reference in a new issue