don't error when waiting on 'canfail' tasks

This commit is contained in:
Mike McLean 2016-06-17 15:22:46 -04:00
parent 316ed1f952
commit aed4682411
2 changed files with 26 additions and 20 deletions

View file

@ -400,7 +400,7 @@ class Task(object):
params, method = xmlrpclib.loads(xml_request)
return params
def getResult(self):
def getResult(self, raise_fault=True):
query = """SELECT state,result FROM task WHERE id = %(id)i"""
r = _fetchSingle(query, vars(self))
if not r:
@ -410,17 +410,20 @@ class Task(object):
raise koji.GenericError, "Task %i is canceled" % self.id
elif koji.TASK_STATES[state] not in ['CLOSED', 'FAILED']:
raise koji.GenericError, "Task %i is not finished" % self.id
# If the result is a Fault, then loads will raise it
# This is probably what we want to happen.
# Note that you can't really 'return' a fault over xmlrpc, you
# can only 'raise' them.
# If you try to return a fault as a value, it gets reduced to
# a mere struct.
# f = Fault(1,"hello"); print dumps((f,))
if xml_result.find('<?xml', 0, 10) == -1:
#handle older base64 encoded data
xml_result = base64.decodestring(xml_result)
result, method = xmlrpclib.loads(xml_result)
try:
# If the result is a Fault, then loads will raise it
# This is normally what we want to happen
result, method = xmlrpclib.loads(xml_result)
except Fault, fault:
if raise_fault:
raise
# Note that you can't really return a fault over xmlrpc, except by
# raising it. We return a dictionary in the same format that
# multiCall does.
return {'faultCode': fault.faultCode, 'faultString': fault.faultString}
return result[0]
def getInfo(self, strict=True, request=False):
@ -10066,9 +10069,9 @@ class RootExports(object):
task = Task(taskId)
return task.getRequest()
def getTaskResult(self, taskId):
def getTaskResult(self, taskId, raise_fault=True):
task = Task(taskId)
return task.getResult()
return task.getResult(raise_fault=raise_fault)
def getTaskInfo(self, task_id, request=False):
"""Get information about a task"""
@ -11094,7 +11097,8 @@ class Host(object):
c.execute(q, locals())
return [finished, unfinished]
def taskWaitResults(self, parent, tasks):
def taskWaitResults(self, parent, tasks, canfail=None):
results = {}
# If we're getting results, we're done waiting
self.taskUnwait(parent)
c = context.cnx.cursor()
@ -11108,16 +11112,17 @@ class Host(object):
# Query all subtasks
tasks = []
c.execute(q, locals())
for id, state in c.fetchall():
for task_id, state in c.fetchall():
if state == canceled:
raise koji.GenericError, "Subtask canceled"
elif state in (closed, failed):
tasks.append(id)
tasks.append(task_id)
# Would use a dict, but xmlrpc requires the keys to be strings
results = []
for id in tasks:
task = Task(id)
results.append([id, task.getResult()])
for task_id in tasks:
task = Task(task_id)
raise_fault = (result in canfail)
results.append([task_id, task.getResult(raise_fault=raise_fault)])
return results
def getHostTasks(self):