From 18caf08d0e0500212859f2e5228b66c5e7745c85 Mon Sep 17 00:00:00 2001 From: Rishabh Dave Date: Fri, 26 Mar 2021 14:56:11 +0530 Subject: [PATCH] orchestra/remote: add a method to write files in /tmp 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 --- teuthology/orchestra/remote.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/teuthology/orchestra/remote.py b/teuthology/orchestra/remote.py index a9c4c0fd1d..feb9b7c1c2 100644 --- a/teuthology/orchestra/remote.py +++ b/teuthology/orchestra/remote.py @@ -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'): -- 2.39.5