Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions salt/states/grains.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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)
Expand Down
15 changes: 15 additions & 0 deletions tests/integration/files/file/base/issue-31427.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
roles:
grains.list_present:
- name: roles
- value:
- elliptic
- parabolic
- hyperbolic

additional-roles:
grains.list_present:
- name: roles
- value:
- hyperbolic
- diabolic

1 change: 0 additions & 1 deletion tests/integration/modules/grains.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ def test_get(self):
['level1:level2']),
'foo')


if __name__ == '__main__':
from integration import run_tests
run_tests(TestModulesGrains)