mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 17:09:03 +00:00
Merge pull request #48612 from rallytime/merge-develop
[develop] Merge forward from 2018.3 to develop
This commit is contained in:
commit
52666edb7a
@ -192,14 +192,10 @@ def returner(ret):
|
||||
logoption = logoption | getattr(syslog, opt)
|
||||
|
||||
# Open syslog correctly based on options and tag
|
||||
try:
|
||||
if 'tag' in _options:
|
||||
syslog.openlog(ident=_options['tag'], logoption=logoption)
|
||||
else:
|
||||
syslog.openlog(logoption=logoption)
|
||||
except TypeError:
|
||||
# Python 2.6 syslog.openlog does not accept keyword args
|
||||
syslog.openlog(_options.get('tag', 'salt-minion'), logoption)
|
||||
if 'tag' in _options:
|
||||
syslog.openlog(ident=salt.utils.stringutils.to_str(_options['tag']), logoption=logoption)
|
||||
else:
|
||||
syslog.openlog(logoption=logoption)
|
||||
|
||||
# Send log of given level and facility
|
||||
syslog.syslog(facility | level, salt.utils.json.dumps(ret))
|
||||
|
@ -2701,7 +2701,7 @@ def cloned(name,
|
||||
https_pass=None,
|
||||
output_encoding=None):
|
||||
'''
|
||||
.. versionadded:: 2018.3.2,Fluorine
|
||||
.. versionadded:: 2018.3.3, Fluorine
|
||||
|
||||
Ensure that a repository has been cloned to the specified target directory.
|
||||
If not, clone that repository. No fetches will be performed once cloned.
|
||||
|
@ -1597,6 +1597,40 @@ class FilemodLineTests(TestCase, LoaderModuleMockMixin):
|
||||
expected = self._get_body(file_modified)
|
||||
assert writelines_content[0] == expected, (writelines_content[0], expected)
|
||||
|
||||
@with_tempfile()
|
||||
def test_line_insert_ensure_before_first_line(self, name):
|
||||
'''
|
||||
Test for file.line for insertion ensuring the line is before first line
|
||||
:return:
|
||||
'''
|
||||
cfg_content = '#!/bin/bash'
|
||||
file_content = os.linesep.join([
|
||||
'/etc/init.d/someservice restart',
|
||||
'exit 0'
|
||||
])
|
||||
file_modified = os.linesep.join([
|
||||
cfg_content,
|
||||
'/etc/init.d/someservice restart',
|
||||
'exit 0'
|
||||
])
|
||||
|
||||
isfile_mock = MagicMock(side_effect=lambda x: True if x == name else DEFAULT)
|
||||
with patch('os.path.isfile', isfile_mock), \
|
||||
patch('os.stat', MagicMock(return_value=DummyStat())), \
|
||||
patch('salt.utils.files.fopen',
|
||||
mock_open(read_data=file_content)), \
|
||||
patch('salt.utils.atomicfile.atomic_open',
|
||||
mock_open()) as atomic_open_mock:
|
||||
filemod.line(name, content=cfg_content, before='/etc/init.d/someservice restart', mode='ensure')
|
||||
handles = atomic_open_mock.filehandles[name]
|
||||
# We should only have opened the file once
|
||||
open_count = len(handles)
|
||||
assert open_count == 1, open_count
|
||||
# We should only have invoked .writelines() once...
|
||||
writelines_content = handles[0].writelines_calls
|
||||
writelines_count = len(writelines_content)
|
||||
assert writelines_count == 1, writelines_count
|
||||
|
||||
@with_tempfile()
|
||||
def test_line_insert_ensure_after(self, name):
|
||||
'''
|
||||
|
44
tests/unit/returners/test_syslog_return.py
Normal file
44
tests/unit/returners/test_syslog_return.py
Normal file
@ -0,0 +1,44 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
'''
|
||||
:codeauthor: :email:`Megan Wilhite (mwilhite@saltstack.com)`
|
||||
|
||||
|
||||
tests.unit.returners.test_syslog_return
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
'''
|
||||
|
||||
# Import Python libs
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
# Import Salt Testing libs
|
||||
from tests.support.mixins import LoaderModuleMockMixin
|
||||
from tests.support.unit import TestCase, skipIf
|
||||
from tests.support.mock import NO_MOCK, NO_MOCK_REASON, MagicMock, patch
|
||||
|
||||
# Import salt libs
|
||||
import salt.returners.syslog_return as syslog
|
||||
|
||||
|
||||
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
||||
class SyslogReturnerTestCase(TestCase, LoaderModuleMockMixin):
|
||||
'''
|
||||
Test Syslog returner
|
||||
'''
|
||||
def setup_loader_modules(self):
|
||||
return {syslog: {}}
|
||||
|
||||
def test_syslog_returner_unicode(self):
|
||||
'''
|
||||
test syslog returner with unicode
|
||||
'''
|
||||
ret = {'fun_args': [], 'jid': '20180713160901624786', 'return': True,
|
||||
'retcode': 0, 'success': True, 'fun': 'test.ping', 'id': '02e10e971a30'}
|
||||
opts = {u'level': u'LOG_INFO', u'options': [],
|
||||
u'facility': u'LOG_USER', u'tag': u'salt-minion'}
|
||||
|
||||
with patch('salt.returners.syslog_return._get_options',
|
||||
MagicMock(return_value=opts)):
|
||||
try:
|
||||
syslog.returner(ret)
|
||||
except Exception as e:
|
||||
self.fail('syslog.returner() failed with exception: {0}'.format(e))
|
Loading…
Reference in New Issue
Block a user