From 2769232b72601ce7776502b23df0aa387b4fd588 Mon Sep 17 00:00:00 2001 From: Haibo Lin Date: Mar 04 2021 08:08:06 +0000 Subject: runroot: Adjust permissions always Previously commands to adjust permissions do not run when main command failed and then files can't be cleaned up due to Permission Denied problem. JIRA: RHELCMP-4253 Signed-off-by: Haibo Lin --- diff --git a/pungi/runroot.py b/pungi/runroot.py index f119b59..98d7bd3 100644 --- a/pungi/runroot.py +++ b/pungi/runroot.py @@ -174,10 +174,13 @@ class Runroot(kobo.log.LoggingBase): # by the runroot task, so the Pungi user can access them. if chown_paths: paths = " ".join(shlex_quote(pth) for pth in chown_paths) + command += " ; EXIT_CODE=$?" # Make the files world readable - command += " && chmod -R a+r %s" % paths + 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(), paths) + command += " ; chown -R %d %s" % (os.getuid(), paths) + # Exit with code of main command + command += " ; exit $EXIT_CODE" hostname = runroot_ssh_hostnames[arch] user = self.compose.conf.get("runroot_ssh_username", "root") diff --git a/pungi/wrappers/kojiwrapper.py b/pungi/wrappers/kojiwrapper.py index 212a429..d5f65ed 100644 --- a/pungi/wrappers/kojiwrapper.py +++ b/pungi/wrappers/kojiwrapper.py @@ -142,10 +142,13 @@ class KojiWrapper(object): if chown_paths: paths = " ".join(shlex_quote(pth) for pth in chown_paths) + command += " ; EXIT_CODE=$?" # Make the files world readable - command += " && chmod -R a+r %s" % paths + 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(), paths) + command += " ; chown -R %d %s" % (os.getuid(), paths) + # Exit with code of main command + command += " ; exit $EXIT_CODE" cmd.append(command) return cmd diff --git a/tests/test_koji_wrapper.py b/tests/test_koji_wrapper.py index 5f7029e..fc59e07 100644 --- a/tests/test_koji_wrapper.py +++ b/tests/test_koji_wrapper.py @@ -594,7 +594,7 @@ class RunrootKojiWrapperTest(KojiWrapperBaseTestCase): 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' /foo && chown -R 1010 '/output dir' /foo", # noqa: E501 + "rm -f /var/lib/rpm/__db*; rm -rf /var/cache/yum/*; set -x; /bin/echo '&' ; EXIT_CODE=$? ; chmod -R a+r '/output dir' /foo ; chown -R 1010 '/output dir' /foo ; exit $EXIT_CODE", # noqa: E501 ) six.assertCountEqual( self, diff --git a/tests/test_runroot.py b/tests/test_runroot.py index e06cdd3..4b3f048 100644 --- a/tests/test_runroot.py +++ b/tests/test_runroot.py @@ -189,8 +189,10 @@ class TestRunrootOpenSSH(helpers.PungiTestCase): run.assert_has_calls( [ self._ssh_call( - "run df -h && chmod -R a+r /mnt/foo/compose /mnt/foo/x && " - "chown -R %d /mnt/foo/compose /mnt/foo/x" % os.getuid() + "run df -h ; EXIT_CODE=$? ; " + "chmod -R a+r /mnt/foo/compose /mnt/foo/x ; " + "chown -R %d /mnt/foo/compose /mnt/foo/x ; exit $EXIT_CODE" + % os.getuid() ), self._ssh_call( "run rpm -qa --qf='%{name}-%{version}-%{release}.%{arch}\n'",