From b2bd65505df108420ee79c93d8da6ffdfa7f7675 Mon Sep 17 00:00:00 2001 From: Alfredo Deza Date: Tue, 30 Jan 2018 09:34:53 -0500 Subject: [PATCH] ceph-volume util.system tmp mounts can now remove a dmcrypt mapper Signed-off-by: Alfredo Deza (cherry picked from commit 60e8699650a491013d51239b9dc58160946d3bf9) --- src/ceph-volume/ceph_volume/util/system.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/ceph-volume/ceph_volume/util/system.py b/src/ceph-volume/ceph_volume/util/system.py index acecc6c8d9b..952fa56fe58 100644 --- a/src/ceph-volume/ceph_volume/util/system.py +++ b/src/ceph-volume/ceph_volume/util/system.py @@ -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): -- 2.47.3