Fix a stack trace in grains.core

On Windows machines that do not have fiber channel cards, core.py was
throwing a stack trace everytime it tried to populate the fiber channel
port for grains
This commit is contained in:
twangboy 2017-12-20 14:57:02 -07:00
parent b9503a46af
commit 7de9dd7f2f
No known key found for this signature in database
GPG key ID: 93FF3BDEB278C9EB
2 changed files with 8 additions and 1 deletions

View file

@ -2550,7 +2550,7 @@ def _windows_wwns():
'''
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 = []

View file

@ -3241,6 +3241,13 @@ def powershell(cmd,
else:
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'
response = run(cmd,
cwd=cwd,