From: Rishabh Dave Date: Wed, 7 Aug 2019 11:25:34 +0000 (+0530) Subject: orchestra/remote: rewrite mktemp to use coreutils mktemp X-Git-Tag: 1.1.0~231^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F1302%2Fhead;p=teuthology.git 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 --- 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): """