Get rid of additional newline append

This looks like it was just incorrectly done before. writelines()
expects you to take care of newlines yourself, so each element should
end in a newline. But we were doing two separate writes, one with the
key=value pair and one with a newline
This commit is contained in:
Erik Johnson 2018-06-13 15:17:56 -05:00
parent 7427e192ba
commit db19636f56
No known key found for this signature in database
GPG key ID: 5E5583C437808F3F
2 changed files with 1 additions and 5 deletions

View file

@ -179,13 +179,10 @@ def persist(name, value, config='/etc/sysctl.conf', apply_change=False):
rest = rest[len(rest_v):]
if rest_v == value:
return 'Already set'
new_line = '{0}={1}\n'.format(name, value)
nlines.append(new_line)
nlines.append('\n')
nlines.append('{0}={1}\n'.format(name, value))
edited = True
if not edited:
nlines.append('{0}={1}\n'.format(name, value))
nlines.append('\n')
nlines = [salt.utils.stringutils.to_str(_l) for _l in nlines]
with salt.utils.files.fopen(config, 'w+') as ofile:
ofile.writelines(nlines)

View file

@ -96,7 +96,6 @@ class DarwinSysctlTestCase(TestCase, LoaderModuleMockMixin):
'# Kernel sysctl configuration\n',
'#\n',
'net.inet.icmp.icmplim=50\n',
'\n',
])]
with patch('salt.utils.files.fopen', mock_open(read_data=to_write)) as m_open, \
patch('os.path.isfile', MagicMock(return_value=True)):