From 2e68d35678ba979272108bd9fe8d22b5417c81f7 Mon Sep 17 00:00:00 2001 From: twangboy Date: Tue, 15 Jan 2019 18:09:36 -0700 Subject: [PATCH] directly call cmd.run_all Apparently, you can't always use __salt__ in a util --- salt/utils/win_lgpo_auditpol.py | 5 +++-- tests/unit/utils/test_win_lgpo_auditpol.py | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/salt/utils/win_lgpo_auditpol.py b/salt/utils/win_lgpo_auditpol.py index 7a84bf82a4..b729728b8d 100644 --- a/salt/utils/win_lgpo_auditpol.py +++ b/salt/utils/win_lgpo_auditpol.py @@ -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() diff --git a/tests/unit/utils/test_win_lgpo_auditpol.py b/tests/unit/utils/test_win_lgpo_auditpol.py index 6703869d1c..b7b288a64c 100644 --- a/tests/unit/utils/test_win_lgpo_auditpol.py +++ b/tests/unit/utils/test_win_lgpo_auditpol.py @@ -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: