executing real job, but error handling still won't work
This commit is contained in:
parent
0f8fa7ea6c
commit
a1e95212d5
2 changed files with 25 additions and 8 deletions
|
|
@ -1,12 +1,14 @@
|
||||||
import subprocess as sp
|
import subprocess as sp
|
||||||
|
from subprocess import Popen
|
||||||
from subprocess import CalledProcessError
|
from subprocess import CalledProcessError
|
||||||
from datetime import datetime as dt
|
from datetime import datetime as dt
|
||||||
|
|
||||||
class Command:
|
class Command:
|
||||||
def __init__(self, command):
|
def __init__(self, command, log):
|
||||||
self.command = command
|
self.command = command
|
||||||
self.output = ""
|
self.log = log
|
||||||
self.error = ""
|
self.output = None
|
||||||
|
self.error = None
|
||||||
self.retcode = 0
|
self.retcode = 0
|
||||||
self.commandStart=0
|
self.commandStart=0
|
||||||
|
|
||||||
|
|
@ -22,18 +24,26 @@ class Command:
|
||||||
self.retcode = process.poll()
|
self.retcode = process.poll()
|
||||||
'''
|
'''
|
||||||
try:
|
try:
|
||||||
print self.command
|
self.commandStart = dt.now()
|
||||||
self.output=sp.check_output(self.command.split(),stderr=sp.STDOUT)
|
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:
|
except CalledProcessError:
|
||||||
self.error=CalledProcessError.output
|
self.error=CalledProcessError.output
|
||||||
self.retcode = CalledProcessError.returncode
|
self.retcode = CalledProcessError.returncode
|
||||||
|
except Error:
|
||||||
|
self.log.d("error: " + str(Error))
|
||||||
|
|
||||||
def getOutput(self):
|
def getOutput(self):
|
||||||
return self.output
|
return self.output
|
||||||
|
|
||||||
def getError(self):
|
def getError(self):
|
||||||
return self.error
|
return self.error
|
||||||
|
|
||||||
|
def getOutputAll(self):
|
||||||
|
return str(self.output) + str(self.error) + str(self.retcode)
|
||||||
|
|
||||||
def getReturnCode(self):
|
def getReturnCode(self):
|
||||||
return self.retcode
|
return self.retcode
|
||||||
|
|
|
||||||
|
|
@ -42,8 +42,15 @@ class JobInfo:
|
||||||
def handleCall(self):
|
def handleCall(self):
|
||||||
self.log.d("handle call")
|
self.log.d("handle call")
|
||||||
self.log.d(self.hostServices)
|
self.log.d(self.hostServices)
|
||||||
for hs in self.hostServices:
|
try:
|
||||||
log.d(str(hs))
|
|
||||||
|
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...
|
#must find real service command stored in hosts...
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue