Repository : http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master
commit f142d945cb3f269c00df15c187570cce43abb7d5 Author: Peter Hatina phatina@redhat.com Date: Mon Mar 24 08:28:10 2014 +0100
improve logging when calling synchro methods
cli/lmi/shell/LMIMethod.py | 26 +++++++++++++++++++++++--- 1 files changed, 23 insertions(+), 3 deletions(-)
diff --git a/cli/lmi/shell/LMIMethod.py b/cli/lmi/shell/LMIMethod.py index 7c32be9..8147312 100644 --- a/cli/lmi/shell/LMIMethod.py +++ b/cli/lmi/shell/LMIMethod.py @@ -14,6 +14,7 @@ # along with this program; if not, see http://www.gnu.org/licenses/.
import sys +import logging import pywbem import signal import socket @@ -52,6 +53,8 @@ from LMIExceptions import LMISynchroMethodCallFilterError from LMIExceptions import LMIUnknownParameterError from LMIExceptions import LMIHandlerNamePatternError
+logger = logging.getLogger(__name__) + class LMISignalHelper(object): """ Helper class, which takes care of signal (de)registration and handling. @@ -205,12 +208,21 @@ class LMIMethod(LMIWrapperBaseObject): # Is job in exception state? If so, adjust corresponding error string # from job.GetError() instance if lmi_is_job_exception(job_inst): - (refreshed, _, errorstr) = job_inst.refresh() + try: + (refreshed, _, errorstr) = job_inst.refresh() + except pywbem.cim_operations.CIMError, e: + logger.debug("Sync%s: Job instance can not be refreshed; %s" + % (self._method.name, str(e))) + job_exception.value = e if not refreshed: + logger.debug("Sync%s: Job instance can not be refreshed; %s" + % (self._method.name, errorstr)) raise LMISynchroMethodCallError(errorstr) (exc_rval, exc_rparams, exc_errorstr) = job_inst.GetError() error_inst = exc_rparams.get("error", None) if not error_inst: + logger.debug("Sync%s: Can not retrieve Error instance; %s" + % (self._method.name, exc_errorstr)) raise LMISynchroMethodCallError("Could not get Job error message") errorstr = error_inst.Message return LMIReturnValue(rval=rval, rparams=rparams, errorstr=errorstr) @@ -357,9 +369,13 @@ class LMIMethod(LMIWrapperBaseObject): try: (refreshed, _, errorstr) = job_inst.refresh() except pywbem.cim_operations.CIMError, e: + logger.debug("Sync%s: Job instance can not be refreshed; %s" + % (self._method.name, str(e))) job_exception.value = e break if not refreshed: + logger.debug("Sync%s: Job instance can not be refreshed; %s" + % (self._method.name, errorstr)) job_exception.value = LMISynchroMethodCallError(errorstr) break
@@ -377,7 +393,7 @@ class LMIMethod(LMIWrapperBaseObject): raise job_exception.value if LMISignalHelper().signal_handled() and not job_finished.value: # We got SIGINT or SIGTERM, when waiting for the job, cancelling the job - sys.stderr.write("Cancelling a job '%s'\n" % job_inst.Name) + logger.warn("Cancelling a job '%s'" % job_inst.Name) job_inst.RequestStateChange( RequestedState=job_inst.RequestStateChange.RequestedStateValues.Terminate ) @@ -418,9 +434,13 @@ class LMIMethod(LMIWrapperBaseObject): sleep_time *= 2 (refreshed, _, errorstr) = job_inst.refresh() if not refreshed: + logger.debug("Sync%s: Job instance can not be refreshed; %s" + % (self._method.name, errorstr)) job_exception = LMISynchroMethodCallError(errorstr) break except pywbem.cim_operations.CIMError, e: + logger.debug("Sync%s: Job instance can not be refreshed; %s" + % (self._method.name, str(e))) job_exception = LMISynchroMethodCallError(e.message) finally: cond.release() @@ -431,7 +451,7 @@ class LMIMethod(LMIWrapperBaseObject):
if LMISignalHelper().signal_handled() and not lmi_is_job_finished(job_inst): # We got SIGINT or SIGTERM, when waiting for the job, cancelling the job - sys.stderr.write("Cancelling a job '%s'\n" % job_inst.Name) + logger.warn("Cancelling a job '%s'" % job_inst.Name) job_inst.RequestStateChange( RequestedState=job_inst.RequestStateChange.RequestedStateValues.Terminate )
cura-tools-devel@lists.fedorahosted.org