From f2bbf35429437b6f0381d7cfbe3bc1258e3f086b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubom=C3=ADr=20Sedl=C3=A1=C5=99?= Date: Thu, 16 May 2019 10:36:09 +0200 Subject: [PATCH] kojiwrapper: Allow changing mode of multiple files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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ář --- pungi/runroot.py | 2 +- pungi/wrappers/kojiwrapper.py | 9 +++++---- tests/test_buildinstall.py | 8 +++++--- tests/test_koji_wrapper.py | 6 +++--- tests/test_ostree_installer_phase.py | 4 ++-- 5 files changed, 16 insertions(+), 13 deletions(-) diff --git a/pungi/runroot.py b/pungi/runroot.py index 25c804b7..8a003878 100644 --- a/pungi/runroot.py +++ b/pungi/runroot.py @@ -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( diff --git a/pungi/wrappers/kojiwrapper.py b/pungi/wrappers/kojiwrapper.py index 3cd9ac97..359acbce 100644 --- a/pungi/wrappers/kojiwrapper.py +++ b/pungi/wrappers/kojiwrapper.py @@ -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 diff --git a/tests/test_buildinstall.py b/tests/test_buildinstall.py index 2a956c69..7ec231bc 100644 --- a/tests/test_buildinstall.py +++ b/tests/test_buildinstall.py @@ -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, diff --git a/tests/test_koji_wrapper.py b/tests/test_koji_wrapper.py index 34d8b3a3..399bb907 100644 --- a/tests/test_koji_wrapper.py +++ b/tests/test_koji_wrapper.py @@ -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', diff --git a/tests/test_ostree_installer_phase.py b/tests/test_ostree_installer_phase.py index dec47a86..93857518 100644 --- a/tests/test_ostree_installer_phase.py +++ b/tests/test_ostree_installer_phase.py @@ -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,