Skip to content

Commit

Permalink
Allow chroot_scan to create archive instead of directory
Browse files Browse the repository at this point in the history
  • Loading branch information
tkopecek authored and praiskup committed Feb 14, 2024
1 parent 74d13f0 commit 49ce04c
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 2 deletions.
3 changes: 3 additions & 0 deletions docs/Plugin-ChrootScan.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions mock/docs/site-defaults.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion mock/py/mockbuild/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
16 changes: 15 additions & 1 deletion mock/py/mockbuild/plugins/chroot_scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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)
3 changes: 3 additions & 0 deletions releng/release-notes-next/chroot_scan_tarball.feature
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit 49ce04c

Please sign in to comment.