mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge branch '2017.7' into more_tests
This commit is contained in:
commit
d50324b4b5
4 changed files with 77 additions and 57 deletions
|
@ -126,7 +126,7 @@ The corresponding Pillar top file would look like this:
|
|||
|
||||
.. code-block:: yaml
|
||||
|
||||
{{saltenv}}:
|
||||
"{{saltenv}}":
|
||||
'*':
|
||||
- bar
|
||||
|
||||
|
|
|
@ -30,7 +30,8 @@ from tests.support.helpers import (
|
|||
with_system_user_and_group,
|
||||
with_tempfile,
|
||||
Webserver,
|
||||
destructiveTest
|
||||
destructiveTest,
|
||||
dedent,
|
||||
)
|
||||
from tests.support.mixins import SaltReturnAssertsMixin
|
||||
|
||||
|
@ -2647,57 +2648,57 @@ class FileTest(ModuleCase, SaltReturnAssertsMixin):
|
|||
class BlockreplaceTest(ModuleCase, SaltReturnAssertsMixin):
|
||||
marker_start = '# start'
|
||||
marker_end = '# end'
|
||||
content = six.text_type(os.linesep.join([
|
||||
'Line 1 of block',
|
||||
'Line 2 of block',
|
||||
'']))
|
||||
without_block = six.text_type(os.linesep.join([
|
||||
'Hello world!',
|
||||
'',
|
||||
'# comment here',
|
||||
'']))
|
||||
with_non_matching_block = six.text_type(os.linesep.join([
|
||||
'Hello world!',
|
||||
'',
|
||||
'# start',
|
||||
'No match here',
|
||||
'# end',
|
||||
'# comment here',
|
||||
'']))
|
||||
with_non_matching_block_and_marker_end_not_after_newline = six.text_type(os.linesep.join([
|
||||
'Hello world!',
|
||||
'',
|
||||
'# start',
|
||||
'No match here# end',
|
||||
'# comment here',
|
||||
'']))
|
||||
with_matching_block = six.text_type(os.linesep.join([
|
||||
'Hello world!',
|
||||
'',
|
||||
'# start',
|
||||
'Line 1 of block',
|
||||
'Line 2 of block',
|
||||
'# end',
|
||||
'# comment here',
|
||||
'']))
|
||||
with_matching_block_and_extra_newline = six.text_type(os.linesep.join([
|
||||
'Hello world!',
|
||||
'',
|
||||
'# start',
|
||||
'Line 1 of block',
|
||||
'Line 2 of block',
|
||||
'',
|
||||
'# end',
|
||||
'# comment here',
|
||||
'']))
|
||||
with_matching_block_and_marker_end_not_after_newline = six.text_type(os.linesep.join([
|
||||
'Hello world!',
|
||||
'',
|
||||
'# start',
|
||||
'Line 1 of block',
|
||||
'Line 2 of block# end',
|
||||
'# comment here',
|
||||
'']))
|
||||
content = dedent(six.text_type('''\
|
||||
Line 1 of block
|
||||
Line 2 of block
|
||||
'''))
|
||||
without_block = dedent(six.text_type('''\
|
||||
Hello world!
|
||||
|
||||
# comment here
|
||||
'''))
|
||||
with_non_matching_block = dedent(six.text_type('''\
|
||||
Hello world!
|
||||
|
||||
# start
|
||||
No match here
|
||||
# end
|
||||
# comment here
|
||||
'''))
|
||||
with_non_matching_block_and_marker_end_not_after_newline = dedent(six.text_type('''\
|
||||
Hello world!
|
||||
|
||||
# start
|
||||
No match here# end
|
||||
# comment here
|
||||
'''))
|
||||
with_matching_block = dedent(six.text_type('''\
|
||||
Hello world!
|
||||
|
||||
# start
|
||||
Line 1 of block
|
||||
Line 2 of block
|
||||
# end
|
||||
# comment here
|
||||
'''))
|
||||
with_matching_block_and_extra_newline = dedent(six.text_type('''\
|
||||
Hello world!
|
||||
|
||||
# start
|
||||
Line 1 of block
|
||||
Line 2 of block
|
||||
|
||||
# end
|
||||
# comment here
|
||||
'''))
|
||||
with_matching_block_and_marker_end_not_after_newline = dedent(six.text_type('''\
|
||||
Hello world!
|
||||
|
||||
# start
|
||||
Line 1 of block
|
||||
Line 2 of block# end
|
||||
# comment here
|
||||
'''))
|
||||
content_explicit_posix_newlines = ('Line 1 of block\n'
|
||||
'Line 2 of block\n')
|
||||
content_explicit_windows_newlines = ('Line 1 of block\r\n'
|
||||
|
|
|
@ -25,6 +25,7 @@ import socket
|
|||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import textwrap
|
||||
import threading
|
||||
import time
|
||||
import tornado.ioloop
|
||||
|
@ -1565,3 +1566,17 @@ def this_user():
|
|||
if salt.utils.is_windows():
|
||||
return salt.utils.win_functions.get_current_user(with_domain=False)
|
||||
return pwd.getpwuid(os.getuid())[0]
|
||||
|
||||
|
||||
def dedent(text, linesep=os.linesep):
|
||||
'''
|
||||
A wrapper around textwrap.dedent that also sets line endings.
|
||||
'''
|
||||
linesep = salt.utils.to_unicode(linesep)
|
||||
unicode_text = textwrap.dedent(salt.utils.to_unicode(text))
|
||||
clean_text = linesep.join(unicode_text.splitlines())
|
||||
if unicode_text.endswith(u'\n'):
|
||||
clean_text += linesep
|
||||
if not isinstance(text, six.text_type):
|
||||
return salt.utils.to_bytes(clean_text)
|
||||
return clean_text
|
||||
|
|
|
@ -139,13 +139,17 @@ class WinServiceTestCase(TestCase, LoaderModuleMockMixin):
|
|||
'''
|
||||
mock_true = MagicMock(return_value=True)
|
||||
mock_false = MagicMock(return_value=False)
|
||||
mock_info = MagicMock(side_effect=[{'Status': 'Running'},
|
||||
{'Status': 'Stop Pending'},
|
||||
{'Status': 'Stopped'}])
|
||||
mock_info = MagicMock(side_effect=[{'Status': 'Stopped'}])
|
||||
|
||||
with patch.dict(win_service.__salt__, {'cmd.run': MagicMock(return_value="service was stopped")}):
|
||||
with patch.dict(win_service.__salt__, {'cmd.run': MagicMock(return_value="service was stopped")}), \
|
||||
patch.object(win32serviceutil, 'StopService', mock_true), \
|
||||
patch.object(win_service, '_status_wait', mock_info):
|
||||
self.assertTrue(win_service.stop('spongebob'))
|
||||
|
||||
mock_info = MagicMock(side_effect=[{'Status': 'Running', 'Status_WaitHint': 0},
|
||||
{'Status': 'Stop Pending', 'Status_WaitHint': 0},
|
||||
{'Status': 'Stopped'}])
|
||||
|
||||
with patch.dict(win_service.__salt__, {'cmd.run': MagicMock(return_value="service was stopped")}), \
|
||||
patch.object(win32serviceutil, 'StopService', mock_true), \
|
||||
patch.object(win_service, 'info', mock_info), \
|
||||
|
|
Loading…
Add table
Reference in a new issue