From 1b58e5ea01bc1eecdff02d95bca84e672d77c210 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Tue, 25 Jun 2019 16:07:15 -0400 Subject: [PATCH] Carry Redfish error logic to oem OEM will now relay the generic redfish errors when possible. Change-Id: I31ac6cd9f2949e853e05b55f12d77341cee0d698 --- pyghmi/redfish/oem/generic.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pyghmi/redfish/oem/generic.py b/pyghmi/redfish/oem/generic.py index 3083b43a..6a0f1247 100644 --- a/pyghmi/redfish/oem/generic.py +++ b/pyghmi/redfish/oem/generic.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import json import os import pyghmi.exceptions as exc @@ -69,7 +70,15 @@ class OEMHandler(object): wc = self.webclient.dupe() res = wc.grab_json_response_with_status(url, payload, method=method) if res[1] < 200 or res[1] >= 300: - raise exc.PyghmiException(res[0]) + try: + info = json.loads(res[0]) + errmsg = [ + x.get('Message', x['MessageId']) for x in info.get( + 'error', {}).get('@Message.ExtendedInfo', {})] + errmsg = ','.join(errmsg) + raise exc.RedfishError(errmsg) + except (ValueError, KeyError): + raise exc.PyghmiException(str(url) + ":" + res[0]) if payload is None and method is None: self._urlcache[url] = { 'contents': res[0],