This commit is contained in:
Mike McLean 2017-03-29 21:31:24 -04:00
parent 3b82594a32
commit d1ab4ed287
3 changed files with 69 additions and 44 deletions

View file

@ -12,12 +12,14 @@ __all__ = ('SaveFailedTreeTask',)
CONFIG_FILE = '/etc/kojid/plugins/save_failed_tree.conf'
config = None
def omit_paths(tarinfo):
if any([fnmatch.fnmatch(tarinfo.name, f) for f in config['path_filters']]):
return None
else:
return tarinfo
def read_config():
global config
cp = ConfigParser.SafeConfigParser()
@ -31,29 +33,37 @@ def read_config():
if cp.has_option('general', 'volume'):
config['volume'] = cp.get('general', 'volume').strip()
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))
def handler(self, buildrootID, full=False):
self.logger.debug("Saving buildroot %d [full=%s]", buildrootID, full)
read_config()
tar_path = os.path.join(self.workdir, 'broots-task-%s.tar.gz' % taskID)
f = tarfile.open(tar_path, "w:gz")
brinfo = self.session.getBuildroot(buildrootID)
host_id = self.session.host.getHost()['id']
for broot in self.session.listBuildroots(taskID=taskID):
if broot['host_id'] != host_id:
raise koji.GenericError("Task is run on wrong builder.")
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_paths)
if brinfo['host_id'] != host_id:
raise koji.GenericError("Task is run on wrong builder")
broot = BuildRoot(self.session, self.options, brinfo['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)
if not os.path.exists(path):
raise koji.GenericError("Buildroot directory is missing: %s" % path)
tar_path = os.path.join(self.workdir, 'broot-%s.tar.gz' % buildrootID)
self.logger.debug("Creating buildroot archive %s", tar_path)
f = tarfile.open(tar_path, "w:gz")
f.add(path, filter=omit_paths)
f.close()
self.logger.debug("Uploading %s to hub." % tar_path)
self.logger.debug("Uploading %s to hub", tar_path)
self.uploadFile(tar_path, volume=config['volume'])
os.unlink(tar_path)
self.logger.debug("Finished saving buildroots for task %d" % taskID)
self.logger.debug("Finished saving buildroot %s", buildrootID)

View file

@ -15,7 +15,7 @@ allowed_methods = None
@export
def saveFailedTree(taskID, full=False, **opts):
def saveFailedTree(buildrootID, full=False, **opts):
"""Create saveFailedTree task
If arguments are invalid, error message is returned. Otherwise task id of
@ -23,7 +23,7 @@ def saveFailedTree(taskID, full=False, **opts):
global config, allowed_methods
# let it raise errors
taskID = int(taskID)
buildrootID = int(buildrootID)
full = bool(full)
# read configuration only once
@ -34,6 +34,8 @@ def saveFailedTree(taskID, full=False, **opts):
if len(allowed_methods) == 1 and allowed_methods[0] == '*':
allowed_methods = '*'
brinfo = kojihub.get_buildroot(buildrootID, strict=True)
taskID = brinfo['task_id']
task_info = kojihub.Task(taskID).getInfo()
if task_info['state'] != koji.TASK_STATES['FAILED']:
raise koji.PreBuildError("Task %s has not failed. Only failed tasks can upload their buildroots." % taskID)
@ -45,8 +47,8 @@ def saveFailedTree(taskID, full=False, **opts):
elif not kojihub.get_host(task_info['host_id'])['enabled']:
raise koji.PreBuildError("Host is disabled.")
args = koji.encode_args(taskID, full, **opts)
args = koji.encode_args(buildrootID, full, **opts)
taskopts = {
'assign': task_info['host_id'],
'assign': brinfo['host_id'],
}
return kojihub.make_task('saveFailedTree', args, **taskopts)