]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
qa/cephfs: don't use sudo to write files in /tmp
authorRishabh Dave <ridave@redhat.com>
Fri, 26 Mar 2021 09:20:20 +0000 (14:50 +0530)
committerRishabh Dave <ridave@redhat.com>
Thu, 8 Apr 2021 06:26:00 +0000 (11:56 +0530)
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>
qa/tasks/cephfs/cephfs_test_case.py
qa/tasks/vstart_runner.py

index 9f400692310053cfe5858d4559fe127a680ccd95..816ddcc1e7b623d0ef6d4b16c4eb2fbc9763ee33 100644 (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)
index 982dd6ed4ed01dc23cf265e49efce42f233aeb68..586ecf71d5db12271f60a31d9b9ded942a43b3d1 100644 (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):