mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
File state line ending fixes
This commit is contained in:
parent
8bda1e5ae3
commit
a7cfe355d7
3 changed files with 30 additions and 22 deletions
|
@ -4080,7 +4080,12 @@ def get_managed(
|
|||
urlparsed_source.netloc, urlparsed_source.path).rstrip(os.sep)
|
||||
unix_local_source = parsed_scheme in ('file', '')
|
||||
|
||||
if unix_local_source:
|
||||
if parsed_scheme == '':
|
||||
parsed_path = sfn = source
|
||||
if not os.path.exists(sfn):
|
||||
msg = 'Local file source {0} does not exist'.format(sfn)
|
||||
return '', {}, msg
|
||||
elif parsed_scheme == 'file':
|
||||
sfn = parsed_path
|
||||
if not os.path.exists(sfn):
|
||||
msg = 'Local file source {0} does not exist'.format(sfn)
|
||||
|
|
|
@ -2429,7 +2429,9 @@ 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(validated_contents)
|
||||
contents = os.linesep.join(
|
||||
[line.rstrip('\n').rstrip('\r') for line in validated_contents]
|
||||
)
|
||||
if contents_newline and not contents.endswith(os.linesep):
|
||||
contents += os.linesep
|
||||
if template:
|
||||
|
|
|
@ -904,6 +904,7 @@ class FileTest(ModuleCase, SaltReturnAssertsMixin):
|
|||
self.assertFalse(os.path.exists(strayfile2))
|
||||
self.assertTrue(os.path.exists(keepfile))
|
||||
|
||||
@skipIf(salt.utils.is_windows(), 'Skip on windows')
|
||||
@with_tempdir()
|
||||
def test_test_directory_clean_exclude(self, base_dir):
|
||||
'''
|
||||
|
@ -2595,8 +2596,8 @@ class BlockreplaceTest(ModuleCase, SaltReturnAssertsMixin):
|
|||
Test blockreplace when prepend_if_not_found=True and block doesn't
|
||||
exist in file.
|
||||
'''
|
||||
expected = self.marker_start + '\n' + self.content + \
|
||||
self.marker_end + '\n' + self.without_block
|
||||
expected = self.marker_start + os.linesep + self.content + \
|
||||
self.marker_end + os.linesep + self.without_block
|
||||
|
||||
# Pass 1: content ends in newline
|
||||
self._write(name, self.without_block)
|
||||
|
@ -2649,8 +2650,8 @@ class BlockreplaceTest(ModuleCase, SaltReturnAssertsMixin):
|
|||
exist in file. Test with append_newline explicitly set to True.
|
||||
'''
|
||||
# Pass 1: content ends in newline
|
||||
expected = self.marker_start + '\n' + self.content + \
|
||||
'\n' + self.marker_end + '\n' + self.without_block
|
||||
expected = self.marker_start + os.linesep + self.content + \
|
||||
os.linesep + self.marker_end + os.linesep + self.without_block
|
||||
self._write(name, self.without_block)
|
||||
ret = self.run_state('file.blockreplace',
|
||||
name=name,
|
||||
|
@ -2675,8 +2676,8 @@ class BlockreplaceTest(ModuleCase, SaltReturnAssertsMixin):
|
|||
self.assertEqual(self._read(name), expected)
|
||||
|
||||
# Pass 2: content does not end in newline
|
||||
expected = self.marker_start + '\n' + self.content + \
|
||||
self.marker_end + '\n' + self.without_block
|
||||
expected = self.marker_start + os.linesep + self.content + \
|
||||
self.marker_end + os.linesep + self.without_block
|
||||
self._write(name, self.without_block)
|
||||
ret = self.run_state('file.blockreplace',
|
||||
name=name,
|
||||
|
@ -2707,8 +2708,8 @@ class BlockreplaceTest(ModuleCase, SaltReturnAssertsMixin):
|
|||
exist in file. Test with append_newline explicitly set to False.
|
||||
'''
|
||||
# Pass 1: content ends in newline
|
||||
expected = self.marker_start + '\n' + self.content + \
|
||||
self.marker_end + '\n' + self.without_block
|
||||
expected = self.marker_start + os.linesep + self.content + \
|
||||
self.marker_end + os.linesep + self.without_block
|
||||
self._write(name, self.without_block)
|
||||
ret = self.run_state('file.blockreplace',
|
||||
name=name,
|
||||
|
@ -2733,8 +2734,8 @@ class BlockreplaceTest(ModuleCase, SaltReturnAssertsMixin):
|
|||
self.assertEqual(self._read(name), expected)
|
||||
|
||||
# Pass 2: content does not end in newline
|
||||
expected = self.marker_start + '\n' + \
|
||||
self.content.rstrip('\r\n') + self.marker_end + '\n' + \
|
||||
expected = self.marker_start + os.linesep + \
|
||||
self.content.rstrip('\r\n') + self.marker_end + os.linesep + \
|
||||
self.without_block
|
||||
self._write(name, self.without_block)
|
||||
ret = self.run_state('file.blockreplace',
|
||||
|
@ -2765,8 +2766,8 @@ class BlockreplaceTest(ModuleCase, SaltReturnAssertsMixin):
|
|||
Test blockreplace when append_if_not_found=True and block doesn't
|
||||
exist in file.
|
||||
'''
|
||||
expected = self.without_block + self.marker_start + '\n' + \
|
||||
self.content + self.marker_end + '\n'
|
||||
expected = self.without_block + self.marker_start + os.linesep + \
|
||||
self.content + self.marker_end + os.linesep
|
||||
|
||||
# Pass 1: content ends in newline
|
||||
self._write(name, self.without_block)
|
||||
|
@ -2819,8 +2820,8 @@ class BlockreplaceTest(ModuleCase, SaltReturnAssertsMixin):
|
|||
exist in file. Test with append_newline explicitly set to True.
|
||||
'''
|
||||
# Pass 1: content ends in newline
|
||||
expected = self.without_block + self.marker_start + '\n' + \
|
||||
self.content + '\n' + self.marker_end + '\n'
|
||||
expected = self.without_block + self.marker_start + os.linesep + \
|
||||
self.content + os.linesep + self.marker_end + os.linesep
|
||||
self._write(name, self.without_block)
|
||||
ret = self.run_state('file.blockreplace',
|
||||
name=name,
|
||||
|
@ -2845,8 +2846,8 @@ class BlockreplaceTest(ModuleCase, SaltReturnAssertsMixin):
|
|||
self.assertEqual(self._read(name), expected)
|
||||
|
||||
# Pass 2: content does not end in newline
|
||||
expected = self.without_block + self.marker_start + '\n' + \
|
||||
self.content + self.marker_end + '\n'
|
||||
expected = self.without_block + self.marker_start + os.linesep + \
|
||||
self.content + self.marker_end + os.linesep
|
||||
self._write(name, self.without_block)
|
||||
ret = self.run_state('file.blockreplace',
|
||||
name=name,
|
||||
|
@ -2877,8 +2878,8 @@ class BlockreplaceTest(ModuleCase, SaltReturnAssertsMixin):
|
|||
exist in file. Test with append_newline explicitly set to False.
|
||||
'''
|
||||
# Pass 1: content ends in newline
|
||||
expected = self.without_block + self.marker_start + '\n' + \
|
||||
self.content + self.marker_end + '\n'
|
||||
expected = self.without_block + self.marker_start + os.linesep + \
|
||||
self.content + self.marker_end + os.linesep
|
||||
self._write(name, self.without_block)
|
||||
ret = self.run_state('file.blockreplace',
|
||||
name=name,
|
||||
|
@ -2903,8 +2904,8 @@ class BlockreplaceTest(ModuleCase, SaltReturnAssertsMixin):
|
|||
self.assertEqual(self._read(name), expected)
|
||||
|
||||
# Pass 2: content does not end in newline
|
||||
expected = self.without_block + self.marker_start + '\n' + \
|
||||
self.content.rstrip('\r\n') + self.marker_end + '\n'
|
||||
expected = self.without_block + self.marker_start + os.linesep + \
|
||||
self.content.rstrip('\r\n') + self.marker_end + os.linesep
|
||||
self._write(name, self.without_block)
|
||||
ret = self.run_state('file.blockreplace',
|
||||
name=name,
|
||||
|
|
Loading…
Add table
Reference in a new issue