From: Rishabh Dave Date: Fri, 26 Mar 2021 09:20:20 +0000 (+0530) Subject: qa/cephfs: don't use sudo to write files in /tmp X-Git-Tag: v17.1.0~2303^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=e213849581b1a3fbf410ed8ed7298ad8cd338e15;p=ceph.git qa/cephfs: don't use sudo to write files in /tmp Files in /tmp cannot be written by any user( including the root user) other than the file owner even if the permission mode on the file is 777. Fixes: https://tracker.ceph.com/issues/49466 Signed-off-by: Rishabh Dave --- diff --git a/qa/tasks/cephfs/cephfs_test_case.py b/qa/tasks/cephfs/cephfs_test_case.py index 9f4006923100..816ddcc1e7b6 100644 --- a/qa/tasks/cephfs/cephfs_test_case.py +++ b/qa/tasks/cephfs/cephfs_test_case.py @@ -4,12 +4,10 @@ import os import re from shlex import split as shlex_split -from io import StringIO from tasks.ceph_test_case import CephTestCase from teuthology import contextutil -from teuthology.misc import sudo_write_file from teuthology.orchestra import run from teuthology.orchestra.run import CommandFailedError @@ -446,11 +444,4 @@ class CephFSTestCase(CephTestCase): return self.run_cluster_cmd(f'auth get {self.client_name}') def create_keyring_file(self, remote, keyring): - keyring_path = remote.run(args=['mktemp'], stdout=StringIO()).\ - stdout.getvalue().strip() - sudo_write_file(remote, keyring_path, keyring) - - # required when triggered using vstart_runner.py. - remote.run(args=['chmod', '644', keyring_path]) - - return keyring_path + return remote.mktemp(data=keyring) diff --git a/qa/tasks/vstart_runner.py b/qa/tasks/vstart_runner.py index 982dd6ed4ed0..586ecf71d5db 100644 --- a/qa/tasks/vstart_runner.py +++ b/qa/tasks/vstart_runner.py @@ -306,14 +306,23 @@ class LocalRemote(object): # None return mkdtemp(suffix=suffix, prefix='', dir=parentdir) - def mktemp(self, suffix=None, parentdir=None): + def mktemp(self, suffix='', parentdir='', path=None, data=None, + owner=None, mode=None): """ Make a remote temporary file Returns: the path of the temp file created. """ from tempfile import mktemp - return mktemp(suffix=suffix, dir=parentdir) + if not path: + path = mktemp(suffix=suffix, dir=parentdir) + + if data: + # sudo is set to False since root user can't write files in /tmp + # owned by other users. + self.write_file(path=path, data=data, sudo=False) + + return path def write_file(self, path, data, sudo=False, mode=None, owner=None, mkdir=False, append=False):