From 49ce04c8ab6733a6f43397bbbd29fb971d89a090 Mon Sep 17 00:00:00 2001 From: Tomas Kopecek Date: Wed, 14 Feb 2024 15:27:07 +0100 Subject: [PATCH] Allow chroot_scan to create archive instead of directory Motviated by https://pagure.io/koji/issue/3439 --- docs/Plugin-ChrootScan.md | 3 +++ mock/docs/site-defaults.cfg | 3 +++ mock/py/mockbuild/config.py | 4 +++- mock/py/mockbuild/plugins/chroot_scan.py | 16 +++++++++++++++- .../chroot_scan_tarball.feature | 3 +++ 5 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 releng/release-notes-next/chroot_scan_tarball.feature diff --git a/docs/Plugin-ChrootScan.md b/docs/Plugin-ChrootScan.md index cc01291ca..006a03c3f 100644 --- a/docs/Plugin-ChrootScan.md +++ b/docs/Plugin-ChrootScan.md @@ -13,10 +13,13 @@ The chroot_scan plugin is disabled by default. To enable it and to add files to config_opts['plugin_conf']['chroot_scan_opts'] = { 'regexes': [ "core(\.\d+)?", "\.log$",], 'only_failed': True, + 'write_tar': False, } The above logic turns on the chroot_scan plugin and adds corefiles and log files to the scan plugin. When the 'postbuild' hook is run by mock, the chroot_scan will look through the chroot for files that match the regular expressions in it's list and any matching file will be copied to the mock result directory for the config file. Again if you want this to be enabled across all configs, edit the `/etc/mock/site-defaults.cfg` file. When `only_failed` is set to False, then those files are always copied. When it is set to True (default when plugin enabled), then those files are only copied when build failed. +when `write_tar` is set to True, then instead of `chroot_scan` directory, `chroot_scan.tar.gz` is created with the directory archive. + `only_failed` option is available since mock-1.2.8 diff --git a/mock/docs/site-defaults.cfg b/mock/docs/site-defaults.cfg index 1900047c3..372d2ba46 100644 --- a/mock/docs/site-defaults.cfg +++ b/mock/docs/site-defaults.cfg @@ -278,12 +278,15 @@ # config_opts['plugin_conf']['tmpfs_opts']['mode'] = '0755' # config_opts['plugin_conf']['tmpfs_opts']['keep_mounted'] = False # +# https://rpm-software-management.github.io/mock/Plugin-ChrootScan # config_opts['plugin_conf']['chroot_scan_enable'] = False # config_opts['plugin_conf']['chroot_scan_opts'] = { ## Regexp of files which should be copied from buildroot to resultdir. # 'regexes': [ "^[^k]?core(\.\d+)?", "\.log$",], ## If set to True files are copied only if build failed. # 'only_failed': True, +## If set to True, tarball is created instead of directory. +# 'write_tar': False, #} # # lvm_root plugin is not enabled by default and is distributed in separate diff --git a/mock/py/mockbuild/config.py b/mock/py/mockbuild/config.py index 5577cbe63..67027ca6e 100644 --- a/mock/py/mockbuild/config.py +++ b/mock/py/mockbuild/config.py @@ -179,7 +179,9 @@ def setup_default_config_opts(): 'regexes': [ "^[^k]?core(\\.\\d+)?$", "\\.log$", ], - 'only_failed': True}, + 'only_failed': True, + 'write_tar': False, + }, 'sign_enable': False, 'sign_opts': { 'cmd': 'rpmsign', diff --git a/mock/py/mockbuild/plugins/chroot_scan.py b/mock/py/mockbuild/plugins/chroot_scan.py index 012e22d18..95ea2e3cd 100644 --- a/mock/py/mockbuild/plugins/chroot_scan.py +++ b/mock/py/mockbuild/plugins/chroot_scan.py @@ -8,11 +8,12 @@ import os import os.path import re +import shutil import subprocess # our imports from mockbuild.trace_decorator import getLog, traceLog -from mockbuild import file_util +from mockbuild import file_util, util requires_api_version = "1.1" @@ -41,6 +42,10 @@ def _only_failed(self): """ Returns boolean value if option 'only_failed' is set. """ return str(self.scan_opts['only_failed']) == 'True' + def _tarball(self): + """ Returns boolean value if option 'write_tar' is set. """ + return str(self.scan_opts['write_tar']) == 'True' + @traceLog() def _scanChroot(self): is_failed = self.state.result != "success" @@ -72,3 +77,12 @@ def __scanChroot(self): # some packages installs 555 perms on dirs, # so user can't delete/move chroot_scan's results subprocess.call(['chmod', '-R', 'u+w', self.resultdir]) + if self._tarball(): + tarfile = self.resultdir + ".tar.gz" + logger.info("chroot_scan: creating tarball %s", tarfile) + __tar_cmd = self.config["tar_binary"] + util.do( + [__tar_cmd, "-czf", tarfile, self.resultdir], + shell=False, printOutput=True + ) + shutil.rmtree(self.resultdir) diff --git a/releng/release-notes-next/chroot_scan_tarball.feature b/releng/release-notes-next/chroot_scan_tarball.feature new file mode 100644 index 000000000..ac2cac25f --- /dev/null +++ b/releng/release-notes-next/chroot_scan_tarball.feature @@ -0,0 +1,3 @@ +New `write_tar` option for `chroot_scan` plugin. Without it, directory +structure is created in `resultdir`. If `write_tar` is set to `True`, +write_tar will be created instead.