]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-volume util.system tmp mounts can now remove a dmcrypt mapper
authorAlfredo Deza <adeza@redhat.com>
Tue, 30 Jan 2018 14:34:53 +0000 (09:34 -0500)
committerAlfredo Deza <adeza@redhat.com>
Tue, 30 Jan 2018 21:33:55 +0000 (16:33 -0500)
Signed-off-by: Alfredo Deza <adeza@redhat.com>
src/ceph-volume/ceph_volume/util/system.py

index acecc6c8d9b157da8f02225e400c29d70f769c56..952fa56fe58628274ff7b4ed537495654be6882e 100644 (file)
@@ -85,11 +85,17 @@ class tmp_mount(object):
     """
     Temporarily mount a device on a temporary directory,
     and unmount it upon exit
+
+    When ``encrypted`` is set to ``True``, the exit method will call out to
+    close the device so that it doesn't remain open after mounting. It is
+    assumed that it will be open because otherwise it wouldn't be possible to
+    mount in the first place
     """
 
-    def __init__(self, device):
+    def __init__(self, device, encrypted=False):
         self.device = device
         self.path = None
+        self.encrypted = encrypted
 
     def __enter__(self):
         self.path = tempfile.mkdtemp()
@@ -107,6 +113,10 @@ class tmp_mount(object):
             '-v',
             self.path
         ])
+        if self.encrypted:
+            # avoid a circular import from the encryption module
+            from ceph_volume.util import encryption
+            encryption.dmcrypt_close(self.device)
 
 
 def path_is_mounted(path, destination=None):