Skip to content

Commit

Permalink
De-duplicate two opinionated doChroot() calls
Browse files Browse the repository at this point in the history
See #1456.
  • Loading branch information
praiskup authored and xsuchy committed Sep 24, 2024
1 parent e8b3fa2 commit 7b92dc4
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 35 deletions.
18 changes: 18 additions & 0 deletions mock/py/mockbuild/buildroot.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,24 @@ def doChroot(self, command, nosync=False, *args, **kargs):
self.uid_manager.restorePrivs()
return result

def doChrootPlugin(self, command, cwd=None):
"""
Execute command (specified as array, not a shell command string) in this
buildroot in `cwd`, as a non-privileged user. Used by plugins.
"""
private_network = not self.config.get('rpmbuild_networking', False)
self.doChroot(
command,
shell=False,
cwd=cwd,
logger=self.build_log,
uid=self.chrootuid,
gid=self.chrootgid,
user=self.chrootuser,
unshare_net=private_network,
printOutput=self.config.get('print_main_output', True)
)

def all_chroot_packages(self):
"""package set, result of rpm -qa in the buildroot"""
self.nuke_rpm_db()
Expand Down
16 changes: 1 addition & 15 deletions mock/py/mockbuild/plugins/rpkg_preprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,4 @@ def _preprocess(self, host_chroot_spec, host_chroot_sources):
command_str = self.opts.get('cmd') % {'source_spec': chroot_sources_spec,
'target_spec': chroot_spec}
command = shlex.split(command_str)

# determine whether to use private network or not based on rpmbuild_networking
private_network = (not self.config.get('rpmbuild_networking', False))

self.buildroot.doChroot(
command,
shell=False,
cwd=chroot_sources,
logger=self.buildroot.build_log,
uid=self.buildroot.chrootuid,
gid=self.buildroot.chrootgid,
user=self.buildroot.chrootuser,
unshare_net=private_network,
printOutput=self.config.get('print_main_output', True)
)
self.buildroot.doChrootPlugin(command, cwd=chroot_sources)
12 changes: 1 addition & 11 deletions mock/py/mockbuild/plugins/rpmautospec.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,4 @@ def attempt_process_distgit(
# bonus, spec files will be processed in the environment they will be
# built for, reducing the impact of the host system on the outcome,
# leading to more deterministic results and better repeatable builds.
self.buildroot.doChroot(
command,
shell=False,
cwd=chroot_sources,
logger=self.buildroot.build_log,
uid=self.buildroot.chrootuid,
gid=self.buildroot.chrootgid,
user=self.buildroot.chrootuser,
unshare_net=not self.config.get("rpmbuild_networking", False),
printOutput=self.config.get("print_main_output", True),
)
self.buildroot.doChrootPlugin(command, cwd=chroot_sources)
11 changes: 2 additions & 9 deletions mock/tests/plugins/test_rpmautospec.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,19 +158,12 @@ def test_attempt_process_distgit(

expected_command = plugin.opts["cmd_base"] + [chroot_sources_spec, chroot_spec]

plugin.buildroot.doChroot.assert_called_once_with(
plugin.buildroot.doChrootPlugin.assert_called_once_with(
expected_command,
shell=False,
cwd=chroot_sources,
logger=plugin.buildroot.build_log,
uid=plugin.buildroot.chrootuid,
gid=plugin.buildroot.chrootgid,
user=plugin.buildroot.chrootuser,
unshare_net=not plugin.config.get("rpmbuild_networking", False),
printOutput=plugin.config.get("print_main_output", True),
)
else:
plugin.buildroot.doChroot.assert_not_called()
plugin.buildroot.doChrootPlugin.assert_not_called()
if "broken-requires" not in testcase:
if "spec-files-different" in testcase:
log_method = log.warning
Expand Down

0 comments on commit 7b92dc4

Please sign in to comment.