]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-daemon: deal with lack of TemporaryDirectory on py2 31264/head
authorSage Weil <sage@redhat.com>
Wed, 30 Oct 2019 18:22:43 +0000 (13:22 -0500)
committerSage Weil <sage@redhat.com>
Wed, 30 Oct 2019 18:29:49 +0000 (13:29 -0500)
Signed-off-by: Sage Weil <sage@redhat.com>
src/ceph-daemon

index 292969a8010318bbb0040889a66ab9dcb34ccf2f..c810406f8dfd1b419302a04cf9cd9ce144d94cb3 100755 (executable)
@@ -38,7 +38,7 @@ except ImportError:
 import fcntl
 try:
     from StringIO import StringIO           # py2
-except:
+except ImportError:
     from io import StringIO                 # py3
 import json
 import logging
@@ -52,6 +52,26 @@ import time
 import uuid
 from distutils.spawn import find_executable
 
+try:
+    from tempfile import TemporaryDirectory # py3
+except ImportError:
+    # define a minimal (but sufficient) equivalent for <= py 3.2
+    import shutil
+    class TemporaryDirectory(object):
+        def __init__(self):
+            self.name = tempfile.mkdtemp()
+
+        def __enter__(self):
+            if not self.name:
+                self.name = tempfile.mkdtemp()
+            return self.name
+
+        def cleanup(self):
+            shutil.rmtree(self.name)
+
+        def __exit__(self, exc_type, exc_value, traceback):
+            self.cleanup()
+
 
 podman_path = None
 
@@ -645,7 +665,7 @@ WantedBy=ceph-{fsid}.target
     return u
 
 def gen_ssh_key(fsid):
-    tmp_dir = tempfile.TemporaryDirectory()
+    tmp_dir = TemporaryDirectory()
     path = tmp_dir.name + '/key'
     call_throws([
         'ssh-keygen',