From 551f52922f10cf03f96097370f3c03df72685b96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubom=C3=ADr=20Sedl=C3=A1=C5=99?= Date: Wed, 22 May 2019 12:54:26 +0200 Subject: [PATCH] runroot: Remove useless argument output_path MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The same logic is handled by `chown_paths`, which does the same thing but supports multiple paths. Signed-off-by: Lubomír Sedlář --- pungi/phases/buildinstall.py | 4 ++-- pungi/phases/ostree_installer.py | 2 +- pungi/runroot.py | 30 +++++++++++++----------------- tests/test_buildinstall.py | 4 ++-- tests/test_runroot.py | 7 ++++--- 5 files changed, 22 insertions(+), 25 deletions(-) diff --git a/pungi/phases/buildinstall.py b/pungi/phases/buildinstall.py index 38c64baa..181acfdc 100644 --- a/pungi/phases/buildinstall.py +++ b/pungi/phases/buildinstall.py @@ -422,7 +422,7 @@ class BuildinstallThread(WorkerThread): # Get list of packages which are neded in runroot. packages = [] - chown_paths = [] + chown_paths = [output_dir] if buildinstall_method == "lorax": packages += ["lorax"] chown_paths.append(_get_log_dir(compose, variant, arch)) @@ -438,7 +438,7 @@ class BuildinstallThread(WorkerThread): runroot = Runroot(compose) runroot.run( cmd, log_file=log_file, arch=arch, packages=packages, - mounts=[compose.topdir], output_dir=output_dir, + mounts=[compose.topdir], weight=compose.conf['runroot_weights'].get('buildinstall'), chown_paths=chown_paths, ) diff --git a/pungi/phases/ostree_installer.py b/pungi/phases/ostree_installer.py index 0ece3e86..e0efda9e 100644 --- a/pungi/phases/ostree_installer.py +++ b/pungi/phases/ostree_installer.py @@ -187,5 +187,5 @@ class OstreeInstallerThread(WorkerThread): runroot = Runroot(compose) runroot.run( cmd, log_file=log_file, arch=arch, packages=packages, - mounts=[compose.topdir], output_dir=output_dir, + mounts=[compose.topdir], chown_paths=[output_dir], weight=compose.conf['runroot_weights'].get('ostree_installer')) diff --git a/pungi/runroot.py b/pungi/runroot.py index 8a003878..43687b75 100644 --- a/pungi/runroot.py +++ b/pungi/runroot.py @@ -59,17 +59,13 @@ class Runroot(kobo.log.LoggingBase): run(command, show_cmd=True, logfile=log_file) self._result = True - def _run_koji(self, command, log_file=None, packages=None, - arch=None, output_dir=None, **kwargs): + def _run_koji(self, command, log_file=None, packages=None, arch=None, **kwargs): """ Runs the runroot command in Koji. """ runroot_channel = self.compose.conf.get("runroot_channel") runroot_tag = self.compose.conf["runroot_tag"] - if 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( runroot_tag, arch, command, @@ -102,7 +98,7 @@ class Runroot(kobo.log.LoggingBase): return run(ssh_cmd, show_cmd=True, logfile=log_file)[1] def _run_openssh(self, command, log_file=None, arch=None, packages=None, - output_dir=None, **kwargs): + chown_paths=None, **kwargs): """ Runs the runroot command on remote machine using ssh. """ @@ -112,11 +108,12 @@ class Runroot(kobo.log.LoggingBase): # If the output dir is defined, change the permissions of files generated # by the runroot task, so the Pungi user can access them. - if output_dir: + 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(output_dir) + 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(output_dir)) + command += " && chown -R %d %s" % (os.getuid(), paths) hostname = runroot_ssh_hostnames[arch] user = self.compose.conf.get("runroot_ssh_username", "root") @@ -172,8 +169,7 @@ class Runroot(kobo.log.LoggingBase): continue self._result.append(i) - def run(self, command, log_file=None, packages=None, arch=None, - output_dir=None, **kwargs): + def run(self, command, log_file=None, packages=None, arch=None, **kwargs): """ Runs the runroot task using the `Runroot.runroot_method`. Blocks until the runroot task is successfully finished. Raises an exception on error. @@ -196,16 +192,16 @@ class Runroot(kobo.log.LoggingBase): """ if self.runroot_method == "local": self._run_local( - command, log_file=log_file, packages=packages, arch=arch, - output_dir=output_dir, **kwargs) + command, log_file=log_file, packages=packages, arch=arch, **kwargs + ) elif self.runroot_method == "koji": self._run_koji( - command, log_file=log_file, packages=packages, arch=arch, - output_dir=output_dir, **kwargs) + command, log_file=log_file, packages=packages, arch=arch, **kwargs + ) elif self.runroot_method == "openssh": self._run_openssh( - command, log_file=log_file, packages=packages, arch=arch, - output_dir=output_dir, **kwargs) + command, log_file=log_file, packages=packages, arch=arch, **kwargs + ) else: raise ValueError("Unknown runroot_method %r." % self.runroot_method) diff --git a/tests/test_buildinstall.py b/tests/test_buildinstall.py index f492cdab..de1e7b11 100644 --- a/tests/test_buildinstall.py +++ b/tests/test_buildinstall.py @@ -605,8 +605,8 @@ class BuildinstallThreadTestCase(PungiTestCase): use_shell=True, task_id=True, packages=['lorax'], mounts=[self.topdir], weight=123, chown_paths=[ - os.path.join(self.topdir, "logs/x86_64/buildinstall-Server-logs"), destdir, + os.path.join(self.topdir, "logs/x86_64/buildinstall-Server-logs"), ], )]) self.assertItemsEqual( @@ -849,8 +849,8 @@ class BuildinstallThreadTestCase(PungiTestCase): use_shell=True, task_id=True, packages=['lorax'], mounts=[self.topdir], weight=123, chown_paths=[ - "/buildinstall_topdir/buildinstall-%s/x86_64/Server/logs" % os.path.basename(self.topdir), "/buildinstall_topdir/buildinstall-%s/x86_64/Server" % os.path.basename(self.topdir), + "/buildinstall_topdir/buildinstall-%s/x86_64/Server/logs" % os.path.basename(self.topdir), ], )]) self.assertItemsEqual( diff --git a/tests/test_runroot.py b/tests/test_runroot.py index 6615419a..63d2cd69 100644 --- a/tests/test_runroot.py +++ b/tests/test_runroot.py @@ -121,10 +121,11 @@ class TestRunrootOpenSSH(helpers.PungiTestCase): run.return_value = (0, "key\n") self.runroot.run("df -h", log_file="/foo/runroot.log", arch="x86_64", - packages=["lorax", "automake"], output_dir="/mnt/foo/compose") + packages=["lorax", "automake"], + chown_paths=["/mnt/foo/compose", "/mnt/foo/x"]) run.assert_has_calls([ self._ssh_call( - 'run df -h && chmod -R a+r /mnt/foo/compose && ' - 'chown -R %d /mnt/foo/compose' % os.getuid()), + "run df -h && chmod -R a+r /mnt/foo/compose /mnt/foo/x && " + "chown -R %d /mnt/foo/compose /mnt/foo/x" % os.getuid()), self._ssh_call("run rpm -qa --qf='%{name}-%{version}-%{release}.%{arch}\n'"), ])