directly call cmd.run_all

Apparently, you can't always use __salt__ in a util
This commit is contained in:
twangboy 2019-01-15 18:09:36 -07:00
parent e7f53a3df0
commit 2e68d35678
No known key found for this signature in database
GPG Key ID: 93FF3BDEB278C9EB
2 changed files with 4 additions and 3 deletions

View File

@ -66,6 +66,7 @@ import re
import tempfile
# Import Salt libs
import salt.modules.cmdmod
import salt.utils.files
import salt.utils.platform
from salt.exceptions import CommandExecutionError
@ -117,8 +118,8 @@ def _auditpol_cmd(cmd):
Raises:
CommandExecutionError: If the command encounters an error
'''
ret = __salt__['cmd.run_all'](cmd='auditpol {0}'.format(cmd),
python_shell=True)
ret = salt.modules.cmdmod.run_all(cmd='auditpol {0}'.format(cmd),
python_shell=True)
if ret['retcode'] == 0:
return ret['stdout'].splitlines()

View File

@ -55,7 +55,7 @@ class WinLgpoAuditpolTestCase(TestCase, LoaderModuleMockMixin):
def test_set_setting(self):
names = ['Credential Validation', 'IPsec Driver', 'File System', 'SAM']
mock_set = MagicMock(return_value={'retcode': 0, 'stdout': 'Success'})
with patch.dict(win_lgpo_auditpol.__salt__, {'cmd.run_all': mock_set}):
with patch.object(salt.modules.cmdmod, 'run_all', mock_set):
with patch.object(win_lgpo_auditpol, '_get_valid_names',
return_value=[k.lower() for k in names]):
for name in names: