Merge pull request #45113 from twangboy/win_fix_fcgrain

Fix a stack trace in grains.core
This commit is contained in:
Nicole Thomas 2017-12-27 09:36:49 -05:00 committed by GitHub
commit 66e090e75d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 1 deletions

View file

@ -2552,7 +2552,7 @@ def _windows_wwns():
''' '''
Return Fibre Channel port WWNs from a Windows host. Return Fibre Channel port WWNs from a Windows host.
''' '''
ps_cmd = r'Get-WmiObject -class MSFC_FibrePortHBAAttributes -namespace "root\WMI" | Select -Expandproperty Attributes | %{($_.PortWWN | % {"{0:x2}" -f $_}) -join ""}' ps_cmd = r'Get-WmiObject -ErrorAction Stop -class MSFC_FibrePortHBAAttributes -namespace "root\WMI" | Select -Expandproperty Attributes | %{($_.PortWWN | % {"{0:x2}" -f $_}) -join ""}'
ret = [] ret = []

View file

@ -3241,6 +3241,13 @@ def powershell(cmd,
else: else:
encoded_cmd = False encoded_cmd = False
# Put the whole command inside a try / catch block
# Some errors in PowerShell are not "Terminating Errors" and will not be
# caught in a try/catch block. For example, the `Get-WmiObject` command will
# often return a "Non Terminating Error". To fix this, make sure
# `-ErrorAction Stop` is set in the powershell command
cmd = 'try {' + cmd + '} catch { "{}" | ConvertTo-JSON}'
# Retrieve the response, while overriding shell with 'powershell' # Retrieve the response, while overriding shell with 'powershell'
response = run(cmd, response = run(cmd,
cwd=cwd, cwd=cwd,