From ddeb34e8d75ac19640cac05175cdee1e8472a891 Mon Sep 17 00:00:00 2001 From: "Rafael.Timmerberg" Date: Wed, 29 May 2013 23:39:16 +0200 Subject: [PATCH] executing real job, but error handling still won't work --- lib/core/command.py | 22 ++++++++++++++++------ lib/core/job.py | 11 +++++++++-- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/lib/core/command.py b/lib/core/command.py index 74c1b09..ea91457 100644 --- a/lib/core/command.py +++ b/lib/core/command.py @@ -1,12 +1,14 @@ import subprocess as sp +from subprocess import Popen from subprocess import CalledProcessError from datetime import datetime as dt class Command: - def __init__(self, command): + def __init__(self, command, log): self.command = command - self.output = "" - self.error = "" + self.log = log + self.output = None + self.error = None self.retcode = 0 self.commandStart=0 @@ -22,18 +24,26 @@ class Command: self.retcode = process.poll() ''' try: - print self.command - self.output=sp.check_output(self.command.split(),stderr=sp.STDOUT) - + self.commandStart = dt.now() + self.log.d("calling command " + str(self.command) + " at " + str(self.commandStart)) + self.output=sp.check_output(self.command.split()) + #process = Popen(stdout=PIPE, *popenargs, **kwargs) + #self.output, self.error = process.communicate() + #self.retcode = process.poll() except CalledProcessError: self.error=CalledProcessError.output self.retcode = CalledProcessError.returncode + except Error: + self.log.d("error: " + str(Error)) def getOutput(self): return self.output def getError(self): return self.error + + def getOutputAll(self): + return str(self.output) + str(self.error) + str(self.retcode) def getReturnCode(self): return self.retcode diff --git a/lib/core/job.py b/lib/core/job.py index 8cf684a..3c9d7e6 100644 --- a/lib/core/job.py +++ b/lib/core/job.py @@ -42,8 +42,15 @@ class JobInfo: def handleCall(self): self.log.d("handle call") self.log.d(self.hostServices) - for hs in self.hostServices: - log.d(str(hs)) + try: + + for hs in self.hostServices: + self.log.d(str(hs)) + cmd=Command(hs.service.command, self.log) + cmd.call() + log.d(cmd.getOutputOrError()) + except Error: + self.log.d(Error) #must find real service command stored in hosts...