]> git-server-git.apps.pok.os.sepia.ceph.com Git - teuthology.git/commitdiff
orchestra/remote: rewrite mktemp to use coreutils mktemp 1302/head
authorRishabh Dave <ridave@redhat.com>
Wed, 7 Aug 2019 11:25:34 +0000 (16:55 +0530)
committerRishabh Dave <ridave@redhat.com>
Mon, 19 Aug 2019 08:37:48 +0000 (14:07 +0530)
Use mktemp instead of Python's tempfile.mktemp since coreutils is more
easily available.

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

index 9ca1c9e1bffedfdedf8d8850c7e4e0ddb3c7ff91..96e9a45d62276e50669bf453ef01b65a45ce81ad 100644 (file)
@@ -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):
         """