mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge pull request #47007 from twangboy/fix_46968
Fix some issues with the win_servermanager module
This commit is contained in:
commit
9a9f6524f8
2 changed files with 29 additions and 5 deletions
|
@ -22,6 +22,7 @@ import salt.utils.json
|
|||
import salt.utils.platform
|
||||
import salt.utils.powershell
|
||||
import salt.utils.versions
|
||||
from salt.exceptions import CommandExecutionError
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
@ -57,11 +58,29 @@ def _pshell_json(cmd, cwd=None):
|
|||
if 'convertto-json' not in cmd.lower():
|
||||
cmd = '{0} | ConvertTo-Json'.format(cmd)
|
||||
log.debug('PowerShell: %s', cmd)
|
||||
ret = __salt__['cmd.shell'](cmd, shell='powershell', cwd=cwd)
|
||||
ret = __salt__['cmd.run_all'](cmd, shell='powershell', cwd=cwd)
|
||||
|
||||
if 'pid' in ret:
|
||||
del ret['pid']
|
||||
|
||||
if ret.get('stderr', ''):
|
||||
error = ret['stderr'].splitlines()[0]
|
||||
raise CommandExecutionError(error, info=ret)
|
||||
|
||||
if 'retcode' not in ret or ret['retcode'] != 0:
|
||||
# run_all logs an error to log.error, fail hard back to the user
|
||||
raise CommandExecutionError(
|
||||
'Issue executing PowerShell {0}'.format(cmd), info=ret)
|
||||
|
||||
# Sometimes Powershell returns an empty string, which isn't valid JSON
|
||||
if ret['stdout'] == '':
|
||||
ret['stdout'] = '{}'
|
||||
|
||||
try:
|
||||
ret = salt.utils.json.loads(ret, strict=False)
|
||||
ret = salt.utils.json.loads(ret['stdout'], strict=False)
|
||||
except ValueError:
|
||||
log.debug('Json not returned')
|
||||
raise CommandExecutionError(
|
||||
'No JSON results from PowerShell', info=ret)
|
||||
return ret
|
||||
|
||||
|
||||
|
@ -341,7 +360,12 @@ def remove(feature, remove_payload=False, restart=False):
|
|||
.format(command, _cmd_quote(feature), management_tools,
|
||||
_remove_payload,
|
||||
'-Restart' if restart else '')
|
||||
out = _pshell_json(cmd)
|
||||
try:
|
||||
out = _pshell_json(cmd)
|
||||
except CommandExecutionError as exc:
|
||||
if 'ArgumentNotValid' in exc.message:
|
||||
raise CommandExecutionError('Invalid Feature Name', info=exc.info)
|
||||
raise
|
||||
|
||||
# Results are stored in a list of dictionaries in `FeatureResult`
|
||||
if out['FeatureResult']:
|
||||
|
|
|
@ -111,7 +111,7 @@ def installed(name,
|
|||
- XPS-Viewer
|
||||
- SNMP-Service
|
||||
- exclude:
|
||||
- Web-Service
|
||||
- Web-Server
|
||||
'''
|
||||
if 'force' in kwargs:
|
||||
salt.utils.versions.warn_until(
|
||||
|
|
Loading…
Add table
Reference in a new issue