From 0372a8e6a4751af1da8707c5937dbdb17ea298f7 Mon Sep 17 00:00:00 2001 From: Tomas Kopecek Date: Jan 03 2023 13:25:05 +0000 Subject: kiwi: upload log for failed tasks Related: https://pagure.io/koji/issue/3597 --- diff --git a/builder/kojid b/builder/kojid index 4d0ad8b..e91545c 100755 --- a/builder/kojid +++ b/builder/kojid @@ -436,8 +436,10 @@ class BuildRoot(object): with koji._open_text_file(self.rootdir() + destfile, 'wt') as fo: fo.write(settings) - def mock(self, args): + def mock(self, args, additional_logs=None): """Run mock""" + if additional_logs is None: + additional_logs = {} mockpath = getattr(self.options, "mockpath", "/usr/bin/mock") cmd = [mockpath, "-r", self.mockcfg] # if self.options.debug_mock: @@ -457,6 +459,8 @@ class BuildRoot(object): resultdir = self.resultdir() uploadpath = self.getUploadPath() logs = {} + for logname, path in additional_logs.items(): + logs[logname] = (None, None, 0, path) ts_offsets = {} finished = False diff --git a/plugins/builder/kiwi.py b/plugins/builder/kiwi.py index eb3b086..30a0c4e 100644 --- a/plugins/builder/kiwi.py +++ b/plugins/builder/kiwi.py @@ -371,19 +371,22 @@ class KiwiCreateImageTask(BaseBuildTask): desc, types = self.prepareDescription(path, name, version, repos, arch) self.uploadFile(desc) + target_dir = '/builddir/result/image' + root_log_path = os.path.join(broot.rootdir(), target_dir[1:], "build/image-root.log") + root_log_remote_name = f"image-root.{arch}.log" cmd = ['kiwi-ng'] if self.opts.get('profile'): cmd.extend(['--profile', self.opts['profile']]) if self.opts.get('type'): cmd.extend(['--type', self.opts['type']]) - target_dir = '/builddir/result/image' cmd.extend([ '--kiwi-file', os.path.basename(desc), # global option for image/system commands 'system', 'build', '--description', os.path.join(os.path.basename(scmsrcdir), base_path), '--target-dir', target_dir, ]) - rv = broot.mock(['--cwd', broot.tmpdir(within=True), '--chroot', '--'] + cmd) + rv = broot.mock(['--cwd', broot.tmpdir(within=True), '--chroot', '--'] + cmd, + additional_logs={root_log_remote_name: root_log_path}) if rv: raise koji.GenericError("Kiwi failed") @@ -410,12 +413,6 @@ class KiwiCreateImageTask(BaseBuildTask): 'files': [], } - # TODO: upload detailed log? - # build/image-root.log - root_log_path = os.path.join(broot.tmpdir(), target_dir[1:], "build/image-root.log") - if os.path.exists(root_log_path): - self.uploadFile(root_log_path, remoteName=f"image-root.{arch}.log") - bundle_path = os.path.join(broot.rootdir(), bundle_dir[1:]) for fname in os.listdir(bundle_path): self.uploadFile(os.path.join(bundle_path, fname), remoteName=fname)