]> git.apps.os.sepia.ceph.com Git - teuthology.git/commitdiff
orchestra/remote: add a method to write files in /tmp no-sudo-for-tmp-files
authorRishabh Dave <ridave@redhat.com>
Fri, 26 Mar 2021 09:26:11 +0000 (14:56 +0530)
committerRishabh Dave <ridave@redhat.com>
Fri, 26 Mar 2021 10:48:35 +0000 (16:18 +0530)
Test code can call sudo_write_file() to write files in /tmp which won't
work since in newer kernel version files in /tmp can only be written by
the owner. Add a method that creates a file in /tmp and then writes it
without using sudo.

Signed-off-by: Rishabh Dave <ridave@redhat.com>
teuthology/orchestra/remote.py

index a9c4c0fd1d780924b35646a9969c7a2291cbdb61..feb9b7c1c248fff37cdcc7f5f16ffe4d700e0bef 100644 (file)
@@ -561,7 +561,6 @@ class Remote(object):
 
         return proc.stdout.getvalue()
 
-
     def write_file(self, path, data, sudo=False, mode=None, owner=None,
                                      mkdir=False, append=False):
         """
@@ -599,6 +598,22 @@ class Remote(object):
         """
         self.write_file(path, data, sudo=True, **kwargs)
 
+    def write_temp_file(self, **kwargs):
+        """
+        This is a convenience method that call write_file() but without sudo.
+        Reason for excluding sudo is that files in /tmp can not be written by
+        any user (including the root user) besides the file owner.
+
+        Takes arguments of write_file() and of mktemp().
+        """
+        kwargs['sudo'] = False
+
+        if not kwargs.get('path'):
+            kwargs['path'] = self.mktemp(kwargs.pop('suffix',  None),
+                                         kwargs.pop('parentdir', None))
+        self.write_file(**kwargs)
+        return kwargs['path']
+
     @property
     def os(self):
         if not hasattr(self, '_os'):