Merge pull request #51340 from Ch3LL/bp-51252

Backport #51252 into 2018.3.4
This commit is contained in:
Daniel Wozniak 2019-01-27 16:42:48 -07:00 committed by GitHub
commit 7656aa5f66
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 36 additions and 4 deletions

View file

@ -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,9 +2434,10 @@ 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
if template:

View file

@ -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

View file

@ -0,0 +1,3 @@
{{ pillar['name'] }}:
file.managed:
- contents_pillar: issue-50221

View file

@ -2530,6 +2530,26 @@ class FileTest(ModuleCase, SaltReturnAssertsMixin):
'',
]).encode('utf-8'))
@with_tempfile()
def test_issue_50221(self, name):
expected = 'abc{0}{0}{0}'.format(os.linesep)
ret = self.run_function(
'pillar.get',
['issue-50221']
)
assert ret == expected
ret = self.run_function(
'state.apply',
['issue-50221'],
pillar={
'name': name
},
)
self.assertSaltTrueReturn(ret)
with salt.utils.files.fopen(name, 'r') as fp:
contents = fp.read()
assert contents == expected
class BlockreplaceTest(ModuleCase, SaltReturnAssertsMixin):
marker_start = '# start'