From 6a242b1e4a9c555a2c12904e56b21fc8c40771a0 Mon Sep 17 00:00:00 2001 From: Guillaume Abrioux Date: Fri, 29 Jul 2022 15:58:05 +0200 Subject: [PATCH] ceph-volume: fix simple scan When the class `Device` is instantiated with a path instead of a block device, it fails like following. ``` Traceback (most recent call last): File "", line 1, in File "/usr/lib/python3.6/site-packages/ceph_volume/util/device.py", line 130, in __init__ self._parse() File "/usr/lib/python3.6/site-packages/ceph_volume/util/device.py", line 233, in _parse self.ceph_device = disk.has_bluestore_label(self.path) File "/usr/lib/python3.6/site-packages/ceph_volume/util/disk.py", line 906, in has_bluestore_label with open(device_path, "rb") as fd: IsADirectoryError: [Errno 21] Is a directory: '/var/lib/ceph/osd/ceph-0/' ``` passing a path instead of a block device is valid, `simple scan` needs it. Fixes: https://tracker.ceph.com/issues/56969 Signed-off-by: Guillaume Abrioux (cherry picked from commit 5a10e3e9e865aafd9d3f90beb186777060d17f08) --- src/ceph-volume/ceph_volume/tests/util/test_disk.py | 7 +++++++ src/ceph-volume/ceph_volume/util/disk.py | 13 ++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/ceph-volume/ceph_volume/tests/util/test_disk.py b/src/ceph-volume/ceph_volume/tests/util/test_disk.py index 299463504c6a6..fcd644a861b53 100644 --- a/src/ceph-volume/ceph_volume/tests/util/test_disk.py +++ b/src/ceph-volume/ceph_volume/tests/util/test_disk.py @@ -515,3 +515,10 @@ class TestAllowLoopDevsWarning(object): log = caplog.records[0] assert log.levelname == "WARNING" assert "will never be supported in production" in log.message + + +class TestHasBlueStoreLabel(object): + def test_device_path_is_a_path(self, fake_filesystem): + device_path = '/var/lib/ceph/osd/ceph-0' + fake_filesystem.create_dir(device_path) + assert not disk.has_bluestore_label(device_path) \ No newline at end of file diff --git a/src/ceph-volume/ceph_volume/util/disk.py b/src/ceph-volume/ceph_volume/util/disk.py index ec0ea7d3d57bf..cc59e5dfc6529 100644 --- a/src/ceph-volume/ceph_volume/util/disk.py +++ b/src/ceph-volume/ceph_volume/util/disk.py @@ -901,10 +901,13 @@ def has_bluestore_label(device_path): # throws OSError on failure logger.info("opening device {} to check for BlueStore label".format(device_path)) - with open(device_path, "rb") as fd: - # read first 22 bytes looking for bluestore disk signature - signature = fd.read(22) - if signature.decode('ascii', 'replace') == bluestoreDiskSignature: - isBluestore = True + try: + with open(device_path, "rb") as fd: + # read first 22 bytes looking for bluestore disk signature + signature = fd.read(22) + if signature.decode('ascii', 'replace') == bluestoreDiskSignature: + isBluestore = True + except IsADirectoryError: + logger.info(f'{device_path} is a directory, skipping.') return isBluestore -- 2.39.5