mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 17:09:03 +00:00
peserve newlines from pillar data for file.managed
This commit is contained in:
parent
c8db7e3751
commit
1840af9c00
@ -2421,7 +2421,6 @@ def managed(name,
|
||||
'to True to allow the managed file to be empty.'
|
||||
.format(contents_id)
|
||||
)
|
||||
|
||||
if isinstance(use_contents, six.binary_type) and b'\0' in use_contents:
|
||||
contents = use_contents
|
||||
elif isinstance(use_contents, six.text_type) and str('\0') in use_contents:
|
||||
@ -2435,11 +2434,13 @@ def managed(name,
|
||||
'contents_grains is not a string or list of strings, and '
|
||||
'is not binary data. SLS is likely malformed.'
|
||||
)
|
||||
contents = os.linesep.join(
|
||||
[line.rstrip('\n').rstrip('\r') for line in validated_contents]
|
||||
)
|
||||
contents = ''
|
||||
for part in validated_contents:
|
||||
for line in part.splitlines():
|
||||
contents += line.rstrip('\n').rstrip('\r') + os.linesep
|
||||
if contents_newline and not contents.endswith(os.linesep):
|
||||
contents += os.linesep
|
||||
log.error("USE CONTENTS %s %s %s", repr(use_contents), repr(validated_contents), repr(contents))
|
||||
if template:
|
||||
contents = __salt__['file.apply_template_on_contents'](
|
||||
contents,
|
||||
|
@ -743,6 +743,12 @@ class TestDaemon(object):
|
||||
master_opts['root_dir'] = os.path.join(TMP, 'rootdir')
|
||||
master_opts['pki_dir'] = os.path.join(TMP, 'rootdir', 'pki', 'master')
|
||||
master_opts['syndic_master'] = 'localhost'
|
||||
file_tree = {
|
||||
'root_dir': os.path.join(FILES, 'pillar', 'base', 'file_tree'),
|
||||
'follow_dir_links': False,
|
||||
'keep_newline': True,
|
||||
}
|
||||
master_opts['ext_pillar'].append({'file_tree': file_tree})
|
||||
|
||||
# This is the syndic for master
|
||||
# Let's start with a copy of the syndic master configuration
|
||||
|
3
tests/integration/files/file/base/issue-50221.sls
Normal file
3
tests/integration/files/file/base/issue-50221.sls
Normal file
@ -0,0 +1,3 @@
|
||||
{{ pillar['name'] }}:
|
||||
file.managed:
|
||||
- contents_pillar: issue-50221
|
@ -0,0 +1,3 @@
|
||||
abc
|
||||
|
||||
|
@ -2530,6 +2530,25 @@ class FileTest(ModuleCase, SaltReturnAssertsMixin):
|
||||
'',
|
||||
]).encode('utf-8'))
|
||||
|
||||
@with_tempfile()
|
||||
def test_issue_50221(self, name):
|
||||
ret = self.run_function(
|
||||
'pillar.get',
|
||||
['issue-50221']
|
||||
)
|
||||
assert ret == 'abc\n\n\n'
|
||||
ret = self.run_function(
|
||||
'state.apply',
|
||||
['issue-50221'],
|
||||
pillar={
|
||||
'name': name
|
||||
},
|
||||
)
|
||||
self.assertSaltTrueReturn(ret)
|
||||
with salt.utils.files.fopen(name, 'rb') as fp:
|
||||
contents = fp.read()
|
||||
assert contents == b'abc\n\n\n'
|
||||
|
||||
|
||||
class BlockreplaceTest(ModuleCase, SaltReturnAssertsMixin):
|
||||
marker_start = '# start'
|
||||
|
Loading…
Reference in New Issue
Block a user