Basic functionality for save_failed_tree plugin

This commit is contained in:
Tomas Kopecek 2016-10-26 10:55:39 +02:00 committed by Mike McLean
parent d2e666f8d0
commit dd5425f23e
2 changed files with 69 additions and 0 deletions

View file

@ -0,0 +1,40 @@
import fnmatch
import os
import tarfile
import koji.tasks as tasks
from __main__ import BuildRoot
__all__ = ('SaveFailedTreeTask',)
def omit_ccache(tarinfo):
if fnmatch.fnmatch(tarinfo.name, '*/tmp/krb5cc') or \
fnmatch.fnmatch(tarinfo.name, '*/etc/*.keytab'):
return None
else:
return tarinfo
class SaveFailedTreeTask(tasks.BaseTaskHandler):
Methods = ['saveFailedTree']
_taskWeight = 3.0
def handler(self, taskID, full=False):
self.logger.debug("Starting saving buildroots for task %d [full=%s]" % (taskID, full))
tar_path = os.path.join(self.workdir, 'broots-task-%s.tar.gz' % taskID)
f = tarfile.open(tar_path, "w:gz")
for broot in self.session.listBuildroots(taskID=taskID):
broot = BuildRoot(self.session, self.options, broot['id'])
path = broot.rootdir()
if full:
self.logger.debug("Adding buildroot (full): %s" % path)
else:
path = os.path.join(path, 'builddir')
self.logger.debug("Adding buildroot: %s" % path)
f.add(path, filter=omit_ccache)
f.close()
self.logger.debug("Uploading %s to hub." % tar_path)
self.uploadFile(tar_path)
os.unlink(tar_path)
self.logger.debug("Finished saving buildroots for task %d" % taskID)

View file

@ -0,0 +1,29 @@
import koji
from koji.plugin import export
import sys
sys.path.insert(0, '/usr/share/koji-hub/')
import kojihub
__all__ = ('saveFailedTree',)
@export
def saveFailedTree(taskID, full=False, **opts):
# let it raise errors
taskID = int(taskID)
full = bool(full)
task_info = kojihub.Task(taskID).getInfo()
if task_info['state'] != koji.TASK_STATES['FAILED']:
return 'Task %s has not failed.' % taskID
elif task_info['method'] != 'buildArch':
# TODO: allowed tasks could be defined in plugin hub config
return 'Only buildArch tasks can upload buildroot (Task %(id)s is %(method)s).' % task_info
# owner?
# permissions?
args = koji.encode_args(taskID, full, **opts)
taskopts = {
'assign': task_info['host_id'],
}
return kojihub.make_task('saveFailedTree', args, **taskopts)