From 258bbb88c0ef17c7d8737c1786e0db66ad7a06ac Mon Sep 17 00:00:00 2001 From: Rishabh Dave Date: Wed, 7 Aug 2019 16:55:34 +0530 Subject: [PATCH] orchestra/remote: rewrite mktemp to use coreutils mktemp Use mktemp instead of Python's tempfile.mktemp since coreutils is more easily available. Signed-off-by: Rishabh Dave --- teuthology/orchestra/remote.py | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/teuthology/orchestra/remote.py b/teuthology/orchestra/remote.py index 9ca1c9e1b..96e9a45d6 100644 --- a/teuthology/orchestra/remote.py +++ b/teuthology/orchestra/remote.py @@ -219,29 +219,20 @@ class Remote(object): return self.sh(args).strip() - def mktemp(self): + def mktemp(self, suffix=None, parentdir=None): """ Make a remote temporary file - Returns: the name of the temp file created using - tempfile.mkstemp + Returns: the path of the temp file created. """ - py_cmd = "import os; import tempfile; import sys;" + \ - "(fd,fname) = tempfile.mkstemp();" + \ - "os.close(fd);" + \ - "sys.stdout.write(fname.rstrip());" + \ - "sys.stdout.flush()" - args = [ - 'python', - '-c', - py_cmd, - ] - proc = self.run( - args=args, - stdout=StringIO(), - ) - data = proc.stdout.getvalue() - return data + args = ['mktemp'] + + if suffix: + args.append('--suffix=%s' % suffix) + if parentdir: + args.append('--tmpdir=%s' % parentdir) + + return self.sh(args).strip() def sh(self, script, **kwargs): """ -- 2.47.3