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 <hlin@redhat.com>
This commit is contained in:
Haibo Lin 2021-03-01 10:49:49 +08:00
parent b217470464
commit 2769232b72
4 changed files with 15 additions and 7 deletions

View File

@ -174,10 +174,13 @@ class Runroot(kobo.log.LoggingBase):
# by the runroot task, so the Pungi user can access them. # by the runroot task, so the Pungi user can access them.
if chown_paths: if chown_paths:
paths = " ".join(shlex_quote(pth) for pth in chown_paths) paths = " ".join(shlex_quote(pth) for pth in chown_paths)
command += " ; EXIT_CODE=$?"
# Make the files world readable # 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 # 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] hostname = runroot_ssh_hostnames[arch]
user = self.compose.conf.get("runroot_ssh_username", "root") user = self.compose.conf.get("runroot_ssh_username", "root")

View File

@ -142,10 +142,13 @@ class KojiWrapper(object):
if chown_paths: if chown_paths:
paths = " ".join(shlex_quote(pth) for pth in chown_paths) paths = " ".join(shlex_quote(pth) for pth in chown_paths)
command += " ; EXIT_CODE=$?"
# Make the files world readable # 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 # 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) cmd.append(command)
return cmd return cmd

View File

@ -594,7 +594,7 @@ class RunrootKojiWrapperTest(KojiWrapperBaseTestCase):
self.assertEqual(cmd[-2], "s390x") self.assertEqual(cmd[-2], "s390x")
self.assertEqual( self.assertEqual(
cmd[-1], 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( six.assertCountEqual(
self, self,

View File

@ -189,8 +189,10 @@ class TestRunrootOpenSSH(helpers.PungiTestCase):
run.assert_has_calls( run.assert_has_calls(
[ [
self._ssh_call( self._ssh_call(
"run df -h && chmod -R a+r /mnt/foo/compose /mnt/foo/x && " "run df -h ; EXIT_CODE=$? ; "
"chown -R %d /mnt/foo/compose /mnt/foo/x" % os.getuid() "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( self._ssh_call(
"run rpm -qa --qf='%{name}-%{version}-%{release}.%{arch}\n'", "run rpm -qa --qf='%{name}-%{version}-%{release}.%{arch}\n'",