From f93b90f2a57084d2aaf2b548aad7e5a36940f717 Mon Sep 17 00:00:00 2001 From: Jarrod Johnon Date: Thu, 15 Jan 2015 14:03:12 -0500 Subject: [PATCH] Enhance IpmiException to carry IPMI codenumber In some cases, an exception warrants a different handling depending on the code of the error. Have the exception carry the code up for calling code to make a decision. Change-Id: Ie7e134d3a7d99eaa1ec3a82c6f39e82dc4422ca7 --- pyghmi/exceptions.py | 5 ++++- pyghmi/ipmi/command.py | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/pyghmi/exceptions.py b/pyghmi/exceptions.py index b0935fff..3fefd27d 100644 --- a/pyghmi/exceptions.py +++ b/pyghmi/exceptions.py @@ -2,6 +2,7 @@ # vim: tabstop=4 shiftwidth=4 softtabstop=4 # Copyright 2013 IBM Corporation +# Copyright 2015 Lenovo # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -23,7 +24,9 @@ class PyghmiException(Exception): class IpmiException(PyghmiException): - pass + def __init__(self, text='', code=0): + super(IpmiException, self).__init__(text) + self.ipmicode = code class InvalidParameterValue(PyghmiException): diff --git a/pyghmi/ipmi/command.py b/pyghmi/ipmi/command.py index e90d7463..12e3b3d4 100644 --- a/pyghmi/ipmi/command.py +++ b/pyghmi/ipmi/command.py @@ -1,6 +1,7 @@ # vim: tabstop=4 shiftwidth=4 softtabstop=4 # Copyright 2013 IBM Corporation +# Copyright 2015 Lenovo # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -363,7 +364,7 @@ class Command(object): if self._sdr.sensors[sensor].name == sensorname: rsp = self.raw_command(command=0x2d, netfn=4, data=(sensor,)) if 'error' in rsp: - raise Exception(rsp['error']) + raise exc.IpmiException(rsp['error'], rsp['code']) return self._sdr.sensors[sensor].decode_sensor_reading( rsp['data']) raise Exception('Sensor not found: ' + sensorname)