Skip to content

Commit

Permalink
Backport saltstack#53311 to 2019.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
twangboy committed Jul 26, 2019
1 parent cc1cda1 commit 16c704e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
4 changes: 3 additions & 1 deletion salt/modules/win_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

# Import Salt libs
import salt.utils.platform
import salt.utils.path
from salt.exceptions import CommandExecutionError

# Import 3rd party libs
Expand Down Expand Up @@ -581,7 +582,8 @@ def create_win_salt_restart_task():
salt '*' service.create_win_salt_restart_task()
'''
cmd = 'cmd'
# Updated to use full name for Nessus agent
cmd = salt.utils.path.which('cmd')
args = '/c ping -n 3 127.0.0.1 && net stop salt-minion && net start ' \
'salt-minion'
return __salt__['task.create_task'](name='restart-salt-minion',
Expand Down
20 changes: 17 additions & 3 deletions tests/unit/modules/test_win_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

# Import Salt Libs
import salt.modules.win_service as win_service
import salt.utils.path

# Import 3rd Party Libs
try:
Expand Down Expand Up @@ -209,9 +210,22 @@ def test_createwin_saltrestart_task(self):
Test to create a task in Windows task
scheduler to enable restarting the salt-minion
'''
mock_true = MagicMock(return_value=True)
with patch.dict(win_service.__salt__, {'task.create_task': mock_true}):
self.assertTrue(win_service.create_win_salt_restart_task())
cmd = salt.utils.path.which('cmd')
mock = MagicMock()
with patch.dict(win_service.__salt__, {'task.create_task': mock}):
win_service.create_win_salt_restart_task()
mock.assert_called_once_with(
action_type='Execute',
arguments='/c ping -n 3 127.0.0.1 && net stop salt-minion && '
'net start salt-minion',
cmd=cmd,
force=True,
name='restart-salt-minion',
start_date='1975-01-01',
start_time='01:00',
trigger_type='Once',
user_name='System'
)

def test_execute_salt_restart_task(self):
'''
Expand Down

0 comments on commit 16c704e

Please sign in to comment.