kojiwrapper: Allow changing mode of multiple files

The directory with logs should have updated owner and permission as
well as the actual output. This patch lays foundation for that by
allowing multiple paths to be specified.

JIRA: COMPOSE-3545
Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
This commit is contained in:
Lubomír Sedlář 2019-05-16 10:36:09 +02:00
parent 8acd2c9689
commit f2bbf35429
5 changed files with 16 additions and 13 deletions

View File

@ -68,7 +68,7 @@ class Runroot(kobo.log.LoggingBase):
runroot_tag = self.compose.conf["runroot_tag"]
if output_dir:
kwargs["destdir"] = output_dir
kwargs.setdefault("chown_paths", []).append(output_dir)
koji_wrapper = kojiwrapper.KojiWrapper(self.compose.conf["koji_profile"])
koji_cmd = koji_wrapper.get_runroot_cmd(

View File

@ -69,7 +69,7 @@ class KojiWrapper(object):
def get_runroot_cmd(self, target, arch, command, quiet=False, use_shell=True,
channel=None, packages=None, mounts=None, weight=None,
task_id=True, new_chroot=False, destdir=None):
task_id=True, new_chroot=False, chown_paths=None):
cmd = self._get_cmd("runroot")
if quiet:
@ -113,11 +113,12 @@ class KojiWrapper(object):
# HACK: remove rpmdb and yum cache
command = "rm -f /var/lib/rpm/__db*; rm -rf /var/cache/yum/*; set -x; " + command
if destdir:
if chown_paths:
paths = " ".join(shlex_quote(pth) for pth in chown_paths)
# Make the files world readable
command += " && chmod -R a+r %s" % shlex_quote(destdir)
command += " && chmod -R a+r %s" % paths
# and owned by the same user that is running the process
command += " && chown -R %d %s" % (os.getuid(), shlex_quote(destdir))
command += " && chown -R %d %s" % (os.getuid(), paths)
cmd.append(command)
return cmd

View File

@ -604,7 +604,7 @@ class BuildinstallThreadTestCase(PungiTestCase):
'rrt', 'x86_64', self.cmd, channel=None,
use_shell=True, task_id=True,
packages=['lorax'], mounts=[self.topdir], weight=123,
destdir=destdir,
chown_paths=[destdir],
)])
self.assertItemsEqual(
run_runroot_cmd.mock_calls,
@ -673,7 +673,7 @@ class BuildinstallThreadTestCase(PungiTestCase):
"rrt", "amd64", self.cmd, channel=None,
use_shell=True, task_id=True,
packages=['anaconda'], mounts=[self.topdir], weight=None,
destdir=destdir,
chown_paths=[destdir],
)])
self.assertItemsEqual(
run_runroot_cmd.mock_calls,
@ -845,7 +845,9 @@ class BuildinstallThreadTestCase(PungiTestCase):
'rrt', 'x86_64', self.cmd, channel=None,
use_shell=True, task_id=True,
packages=['lorax'], mounts=[self.topdir], weight=123,
destdir="/buildinstall_topdir/buildinstall-%s/x86_64/Server" % os.path.basename(self.topdir),
chown_paths=[
"/buildinstall_topdir/buildinstall-%s/x86_64/Server" % os.path.basename(self.topdir),
],
)])
self.assertItemsEqual(
run_runroot_cmd.mock_calls,

View File

@ -431,18 +431,18 @@ class RunrootKojiWrapperTest(KojiWrapperBaseTestCase):
'--package=lorax', '--mount=/tmp'])
@mock.patch("os.getuid", new=lambda: 1010)
def test_with_destdir(self):
def test_with_chown_paths(self):
cmd = self.koji.get_runroot_cmd('tgt', 's390x', ['/bin/echo', '&'],
quiet=True, channel='chan',
packages=['lorax', 'some_other_package'],
mounts=['/tmp'], weight=1000, destdir="/output dir")
mounts=['/tmp'], weight=1000, chown_paths=["/output dir", "/foo"])
self.assertEqual(len(cmd), 14)
self.assertEqual(cmd[:3], ['koji', '--profile=custom-koji', 'runroot'])
self.assertEqual(cmd[-3], 'tgt')
self.assertEqual(cmd[-2], 's390x')
self.assertEqual(
cmd[-1],
"rm -f /var/lib/rpm/__db*; rm -rf /var/cache/yum/*; set -x; /bin/echo '&' && chmod -R a+r '/output dir' && chown -R 1010 '/output dir'"
"rm -f /var/lib/rpm/__db*; rm -rf /var/cache/yum/*; set -x; /bin/echo '&' && chmod -R a+r '/output dir' /foo && chown -R 1010 '/output dir' /foo"
)
self.assertItemsEqual(cmd[3:-3],
['--channel-override=chan', '--quiet', '--use-shell',

View File

@ -152,10 +152,10 @@ class OstreeThreadTest(helpers.PungiTestCase):
channel=None, mounts=[self.topdir],
packages=['pungi', 'lorax', 'ostree'],
task_id=True, use_shell=True, weight=weight,
destdir=outdir)])
chown_paths=[outdir])])
self.assertEqual(koji.run_runroot_cmd.call_args_list,
[mock.call(koji.get_runroot_cmd.return_value,
log_file='%s/%s/runroot.log' % (self.topdir, LOG_PATH))])
log_file=os.path.join(self.topdir, LOG_PATH, "runroot.log"))])
def assertIsoLinked(self, link, get_file_size, get_mtime, final_iso_path):
self.assertEqual(link.call_args_list,