Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_check_tasks_ours(self):
tasks = [
{'id': 101, 'state': koji.TASK_STATES['FREE']},
{'id': 102, 'state': koji.TASK_STATES['OPEN']},
{'id': 103, 'state': koji.TASK_STATES['CLOSED']},
{'id': 104, 'state': koji.TASK_STATES['CANCELED']},
{'id': 105, 'state': koji.TASK_STATES['FAILED']},
]
task_idx = dict([(t['id'], t) for t in tasks])
order = []
def getTaskInfo(task_id):
# record the order of calls in multicall
order.append(task_id)
def multiCall(strict):
return [[task_idx[tid]] for tid in order]
self.session.getTaskInfo.side_effect = getTaskInfo
self.session.multiCall.side_effect = multiCall
self.mgr.tasks = dict([
(t['id'], {'taskinfo': t, 'tag_id': 'TAG'})
for t in tasks])
def getTaskInfo(self, task_id, request=False):
assert task_id == self.TAG_TASK_ID
# For extra code coverage, imagine Koji denies the task ever
# existed.
if self.tag_task_state is None:
return None
return {'state': koji.TASK_STATES[self.tag_task_state]}
def wait(self):
logger.debug("waiting for koji task %r to finish", self.task_id)
while not self.session.taskFinished(self.task_id):
time.sleep(self.poll_interval)
logger.debug("koji task is finished, getting info")
task_info = self.session.getTaskInfo(self.task_id, request=True)
self.state = koji.TASK_STATES[task_info['state']]
return self.state
if 'src' in rpmsByArch:
srpm = rpmsByArch['src'][0]
headers = server.getRPMHeaders(srpm['id'], headers=['summary', 'description'])
values['summary'] = koji.fixEncoding(headers.get('summary'))
values['description'] = koji.fixEncoding(headers.get('description'))
values['changelog'] = server.getChangelogEntries(build['id'])
if build['task_id']:
task = server.getTaskInfo(build['task_id'], request=True)
# get the summary, description, and changelogs from the built srpm
# if the build is not yet complete
if build['state'] != koji.BUILD_STATES['COMPLETE']:
srpm_tasks = server.listTasks(opts={'parent': task['id'], 'method': 'buildSRPMFromSCM'})
if srpm_tasks:
srpm_task = srpm_tasks[0]
if srpm_task['state'] == koji.TASK_STATES['CLOSED']:
srpm_path = None
for output in server.listTaskOutput(srpm_task['id']):
if output.endswith('.src.rpm'):
srpm_path = output
break
if srpm_path:
srpm_headers = server.getRPMHeaders(taskID=srpm_task['id'], filepath=srpm_path,
headers=['summary', 'description'])
if srpm_headers:
values['summary'] = koji.fixEncoding(srpm_headers['summary'])
values['description'] = koji.fixEncoding(srpm_headers['description'])
changelog = server.getChangelogEntries(taskID=srpm_task['id'], filepath=srpm_path)
if changelog:
values['changelog'] = changelog
else:
task = None
def _verify_tasks(cls, session, task_dict):
"""Checks if any of the tasks failed and tries to extract mock exit code from it.
Args:
session (koji.ClientSession): Active Koji session instance.
task_dict (dict): Dict mapping Koji task ID to its state.
Returns:
int: Mock exit code or -1 if any task failed, otherwise None.
"""
for task_id, state in task_dict.items():
if state == koji.TASK_STATES['FAILED']:
try:
session.getTaskResult(task_id)
except koji.BuildError as e:
# typical error message:
# BuildError: error building package (arch noarch),
# mock exited with status 1; see build.log for more information
match = re.search(r'mock exited with status (\d+)', str(e))
if match:
return int(match.group(1))
else:
return -1
return None
found = True
break
if not found:
print "skipping", build, task["request"]
return
if not task:
print('Invalid task ID: %i' % task_id)
elif task['state'] in (koji.TASK_STATES['FREE'], koji.TASK_STATES['OPEN']):
print('Task %i has not completed' % task['id'])
elif task['state'] != koji.TASK_STATES['CLOSED']:
print('Task %i did not complete successfully' % task['id'])
if task['method'] == 'build':
print 'Getting rpms from children of task %i: %s' % (task['id'], koji.taskLabel(task))
tasks = session.listTasks(opts={'parent': task_id, 'method': 'buildArch', 'state': [koji.TASK_STATES['CLOSED']],
'decode': True})
elif task['method'] == 'buildArch':
tasks = [task]
else:
print('Task %i is not a build or buildArch task' % task['id'])
for task in tasks:
print ">>>>", task, task['id']
arch = task.get('arch', 'unkwown')
output = session.listTaskOutput(task['id'])
print ">>>>", arch, output
# logs = [filename for filename in output if filename.endswith('.log')]
for item in output:
base_path = koji.pathinfo.taskrelpath(task['id'])
file_url = "%s/%s/%s" % (work_url, base_path, item)
urls.append((arch, file_url))
br = missed_br.get(id)
if not br:
self.logger.warn("%(name)s: not in db" % data)
continue
desc = "%(id)i/%(tag_name)s/%(arch)s" % br
if not br['retire_ts']:
self.logger.warn("%s: no retire timestamp" % desc)
continue
age = time.time() - br['retire_ts']
self.logger.debug("Expired/stray buildroot: %s" % desc)
if br and br['task_id']:
task = tasks.get(br['task_id'])
if not task:
self.logger.warn("%s: invalid task %s" % (desc, br['task_id']))
continue
if (task['state'] == koji.TASK_STATES['FAILED'] and age < self.options.failed_buildroot_lifetime):
#XXX - this could be smarter
# keep buildroots for failed tasks around for a little while
self.logger.debug("Keeping failed buildroot: %s" % desc)
continue
topdir = data['dir']
rootdir = None
if topdir:
rootdir = "%s/root" % topdir
try:
st = os.lstat(rootdir)
except OSError as e:
if e.errno == errno.ENOENT:
rootdir = None
else:
self.logger.warn("%s: %s" % (desc, e))
continue
latest_repo.get('id', 0) > collection.latest_repo_id):
if not collection.secondary_mode:
return latest_repo['id']
else:
# in secondary mode, we want to only resolve the repo if it was
# already regenerated on primary
backend.refresh_repo_mappings(self.session)
mapping = self.db.query(RepoMapping)\
.filter_by(secondary_id=latest_repo['id'])\
.first()
if (
mapping and
mapping.primary_id and (
self.session.koji('primary')
.getTaskInfo(mapping.task_id)['state']
) == koji.TASK_STATES['CLOSED']
):
return latest_repo['id']
"""
rpms: List[str] = []
logs: List[str] = []
for task_id in tasklist:
logger.info('Downloading packages and logs for task %s', task_id)
task = session.getTaskInfo(task_id, request=True)
if task['state'] in [koji.TASK_STATES['FREE'], koji.TASK_STATES['OPEN']]:
logger.info('Task %s is still running!', task_id)
continue
elif task['state'] != koji.TASK_STATES['CLOSED']:
logger.info('Task %s did not complete successfully!', task_id)
if task['method'] == 'buildArch':
tasks = [task]
elif task['method'] == 'build':
opts = dict(parent=task_id, method='buildArch', decode=True,
state=[koji.TASK_STATES['CLOSED'], koji.TASK_STATES['FAILED']])
tasks = session.listTasks(opts=opts)
else:
logger.info('Task %s is not a build or buildArch task!', task_id)
continue
for task in tasks:
base_path = koji.pathinfo.taskrelpath(task['id'])
output = session.listTaskOutput(task['id'])
for filename in output:
local_path = os.path.join(destination, filename)
download = False
fn, ext = os.path.splitext(filename)
if ext == '.rpm':
if task['state'] != koji.TASK_STATES['CLOSED']:
continue
if local_path not in rpms:
nevra = RpmHelper.split_nevra(fn)
sleep: How long to sleep between polls on Koji when waiting for tasks to complete.
Returns:
A list of failed tasks. An empty list indicates that all tasks completed successfully.
"""
log.debug("Waiting for %d tasks to complete: %s" % (len(tasks), tasks))
failed_tasks = []
if not session:
session = get_session()
for task in tasks:
if not task:
log.debug("Skipping task: %s" % task)
continue
while not session.taskFinished(task):
time.sleep(sleep)
task_info = session.getTaskInfo(task)
if task_info['state'] != koji.TASK_STATES['CLOSED']:
log.error("Koji task %d failed" % task)
failed_tasks.append(task)
log.debug("%d tasks completed successfully, %d tasks failed." % (
len(tasks) - len(failed_tasks), len(failed_tasks)))
return failed_tasks