From 1966a88844fe62414d02657f97c3668101afc37c Mon Sep 17 00:00:00 2001 From: Rishabh Dave Date: Fri, 26 Mar 2021 14:56:11 +0530 Subject: [PATCH] orchestra/remote: extend mktemp() to accept data Extend remote.Remote.mktemp() to accept data as a parameter and write the data to the temporary file after it is created. Signed-off-by: Rishabh Dave --- teuthology/orchestra/remote.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/teuthology/orchestra/remote.py b/teuthology/orchestra/remote.py index a9c4c0fd..bedfcc6f 100644 --- a/teuthology/orchestra/remote.py +++ b/teuthology/orchestra/remote.py @@ -229,20 +229,28 @@ class Remote(object): return self.sh(args).strip() - def mktemp(self, suffix=None, parentdir=None): + def mktemp(self, suffix=None, parentdir=None, data=None): """ - Make a remote temporary file + Make a remote temporary file. + + :param suffix: suffix for the temporary file + :param parentdir: parent dir where temp file should be created + :param data: write data to the file if provided Returns: the path of the temp file created. """ args = ['mktemp'] - if suffix: args.append('--suffix=%s' % suffix) if parentdir: args.append('--tmpdir=%s' % parentdir) - return self.sh(args).strip() + path = self.sh(args).strip() + + if data: + self.write_file(path=path, data=data) + + return path def sh(self, script, **kwargs): """ -- 2.47.3