From bd92d11a3a6b9d8036708dc3e617210d9a04a6ed Mon Sep 17 00:00:00 2001 From: Tim Serong Date: Mon, 10 Sep 2018 20:27:11 +1000 Subject: [PATCH] ceph-disk: compatibility fix for python 3 In python 3, dev is a string, but mounts_dev is bytes (because /proc/mounts was opened with mode 'rb') so they can't compare equal, resulting in is_mounted() returning None for mounted OSDs. The safest fix for this we could come up with was to normalize dev to a str using _bytes2str() (just in case), and open /proc/mounts in mode 'r', so its lines are interpreted as strs. Fixes: https://tracker.ceph.com/issues/35906 Signed-off-by: Tim Serong (cherry picked from commit 8e3d948ff4c3b19dc55b9a5ae63f5b63f0c476a3) --- src/ceph-disk/ceph_disk/main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ceph-disk/ceph_disk/main.py b/src/ceph-disk/ceph_disk/main.py index 0058f1ac2d977..73f26ce17d7ab 100644 --- a/src/ceph-disk/ceph_disk/main.py +++ b/src/ceph-disk/ceph_disk/main.py @@ -898,8 +898,8 @@ def is_mounted(dev): """ Check if the given device is mounted. """ - dev = os.path.realpath(dev) - with open(PROCDIR + '/mounts', 'rb') as proc_mounts: + dev = os.path.realpath(_bytes2str(dev)) + with open(PROCDIR + '/mounts', 'r') as proc_mounts: for line in proc_mounts: fields = line.split() if len(fields) < 3: -- 2.39.5