mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 08:58:59 +00:00
Merge pull request #40631 from gtmanfred/grains
if grain is defined as None still convert in append
This commit is contained in:
commit
3aabd85e53
@ -400,7 +400,11 @@ def append(name, value, convert=False,
|
||||
'result': True,
|
||||
'comment': ''}
|
||||
grain = __salt__['grains.get'](name, None)
|
||||
if grain:
|
||||
|
||||
# Check if bool(grain) is False or if the grain is specified in the minions
|
||||
# grains. Grains can be set to a None value by omitting a value in the
|
||||
# definition.
|
||||
if grain or name in __grains__:
|
||||
if isinstance(grain, list):
|
||||
if value in grain:
|
||||
ret['comment'] = 'Value {1} is already in the list ' \
|
||||
@ -425,7 +429,7 @@ def append(name, value, convert=False,
|
||||
'added'.format(name, value)
|
||||
ret['changes'] = {'added': value}
|
||||
return ret
|
||||
grain = [grain]
|
||||
grain = [] if grain is None else [grain]
|
||||
grain.append(value)
|
||||
__salt__['grains.setval'](name, grain)
|
||||
ret['comment'] = 'Value {1} was added to grain {0}'\
|
||||
|
@ -828,6 +828,23 @@ class GrainsTestCase(TestCase):
|
||||
grains.__grains__,
|
||||
{'a': 'aval'})
|
||||
|
||||
def test_append_convert_to_list_empty(self):
|
||||
# Append to an existing list
|
||||
self.setGrains({'foo': None})
|
||||
ret = grains.append(
|
||||
name='foo',
|
||||
value='baz',
|
||||
convert=True)
|
||||
self.assertEqual(ret['result'], True)
|
||||
self.assertEqual(ret['comment'], 'Value baz was added to grain foo')
|
||||
self.assertEqual(ret['changes'], {'added': 'baz'})
|
||||
self.assertEqual(
|
||||
grains.__grains__,
|
||||
{'foo': ['baz']})
|
||||
self.assertGrainFileContent("foo:\n"
|
||||
+ "- baz\n"
|
||||
)
|
||||
|
||||
# 'list_present' function tests: 7
|
||||
|
||||
def test_list_present(self):
|
||||
|
Loading…
Reference in New Issue
Block a user