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 <ridave@redhat.com>
This commit is contained in:
Rishabh Dave 2021-03-26 14:50:20 +05:30
parent e05959de8d
commit e213849581
2 changed files with 12 additions and 12 deletions

View File

@ -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)

View File

@ -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):