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)