]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-volume: fix simple scan
authorGuillaume Abrioux <gabrioux@redhat.com>
Fri, 29 Jul 2022 13:58:05 +0000 (15:58 +0200)
committerGuillaume Abrioux <gabrioux@redhat.com>
Fri, 5 Aug 2022 06:58:17 +0000 (08:58 +0200)
When the class `Device` is instantiated with a path instead of a
block device, it fails like following.

```
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  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 <gabrioux@redhat.com>
(cherry picked from commit 5a10e3e9e865aafd9d3f90beb186777060d17f08)

src/ceph-volume/ceph_volume/tests/util/test_disk.py
src/ceph-volume/ceph_volume/util/disk.py

index ab652c22e6ddf5618d60ceaa580e692552cf91a1..d14c79874ce9448b3b9b05ca648224d9f16bcc79 100644 (file)
@@ -541,3 +541,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
index a653fad4e0c622bd795f5d1d177b85340a9e7a2c..84c4cc7e182435445224f6bc4433875df06bdef1 100644 (file)
@@ -884,10 +884,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