mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Don't split multiline values into a list if wrapped inside "
Use salt.utils.dictupdate to merge dictionaries
This commit is contained in:
parent
ec95fe1cd0
commit
6ca1dbd65c
2 changed files with 14 additions and 17 deletions
|
@ -58,6 +58,7 @@ import logging
|
|||
import re
|
||||
|
||||
from salt.exceptions import CommandExecutionError
|
||||
from salt.utils.dictupdate import update as dict_merge
|
||||
|
||||
# Import third party libs
|
||||
try:
|
||||
|
@ -149,8 +150,11 @@ def pillar_format(ret, keys, value):
|
|||
'''
|
||||
if value is None:
|
||||
return ret
|
||||
array_data = value.split('\n')
|
||||
pillar_value = array_data[0] if len(array_data) == 1 else array_data
|
||||
if value[0] == value[-1] == '"':
|
||||
pillar_value = value[1:-1]
|
||||
else:
|
||||
array_data = value.split('\n')
|
||||
pillar_value = array_data[0] if len(array_data) == 1 else array_data
|
||||
keyvalue = keys.pop()
|
||||
pil = {keyvalue: pillar_value}
|
||||
keys.reverse()
|
||||
|
@ -160,19 +164,6 @@ def pillar_format(ret, keys, value):
|
|||
return dict_merge(ret, pil)
|
||||
|
||||
|
||||
def dict_merge(d1, d2):
|
||||
'''
|
||||
Take 2 dictionaries and deep merge them
|
||||
'''
|
||||
master = d1.copy()
|
||||
for (k, v) in d2.iteritems():
|
||||
if k in master and isinstance(master[k], dict):
|
||||
master[k] = dict_merge(master[k], v)
|
||||
else:
|
||||
master[k] = v
|
||||
return master
|
||||
|
||||
|
||||
def get_conn(opts, profile):
|
||||
|
||||
'''
|
||||
|
|
|
@ -29,6 +29,7 @@ PILLAR_DATA = [
|
|||
{'Value': None, 'Key': u'test-shared/sites/'},
|
||||
{'Value': 'Test User', 'Key': u'test-shared/user/full_name'},
|
||||
{'Value': 'adm\nwww-data\nmlocate', 'Key': u'test-shared/user/groups'},
|
||||
{'Value': '"adm\nwww-data\nmlocate"', 'Key': u'test-shared/user/dontsplit'},
|
||||
{'Value': None, 'Key': u'test-shared/user/blankvalue'},
|
||||
{'Value': 'test', 'Key': u'test-shared/user/login'},
|
||||
{'Value': None, 'Key': u'test-shared/user/'}
|
||||
|
@ -65,10 +66,15 @@ class ConsulPillarTestCase(TestCase):
|
|||
pillar_data = pillar.ext_pillar('testminion', {}, 'consul_config root=test-shared/')
|
||||
pillar.consul_fetch.assert_called_once_with('consul_connection', 'test-shared/')
|
||||
assert pillar_data.keys() == [u'user', u'sites']
|
||||
#print(type(pillar_data[u'user'][u'groups']))
|
||||
assert isinstance(pillar_data[u'user'][u'groups'], list)
|
||||
self.assertNotIn('blankvalue', pillar_data[u'user'])
|
||||
|
||||
def test_value_parsing(self):
|
||||
pillar = self.get_pillar()
|
||||
with patch.object(consul_pillar, 'consul_fetch', MagicMock(return_value=('2232', PILLAR_DATA))):
|
||||
pillar_data = pillar.ext_pillar('testminion', {}, 'consul_config root=test-shared/')
|
||||
assert isinstance(pillar_data[u'user'][u'groups'], list)
|
||||
assert isinstance(pillar_data[u'user'][u'dontsplit'], str)
|
||||
|
||||
def test_dict_merge(self):
|
||||
pillar = self.get_pillar()
|
||||
test_dict = {}
|
||||
|
|
Loading…
Add table
Reference in a new issue