]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-volume: fix inventory with device arg 48037/head
authorGuillaume Abrioux <gabrioux@redhat.com>
Fri, 9 Sep 2022 13:00:20 +0000 (15:00 +0200)
committerGuillaume Abrioux <gabrioux@redhat.com>
Fri, 9 Sep 2022 14:52:12 +0000 (16:52 +0200)
there's no need to go through all devices present when
a device is passed to the `ceph-volume inventory` command.

Fixes: https://tracker.ceph.com/issues/57085
Signed-off-by: Guillaume Abrioux <gabrioux@redhat.com>
src/ceph-volume/ceph_volume/tests/conftest.py
src/ceph-volume/ceph_volume/util/device.py
src/ceph-volume/ceph_volume/util/disk.py

index f060f78d44c57b5b645d020de4037337defcccfa..89f8d6d11790e85a44351cfd47288e3fc5cf191d 100644 (file)
@@ -215,7 +215,7 @@ def disable_kernel_queries(monkeypatch):
     '''
     This speeds up calls to Device and Disk
     '''
-    monkeypatch.setattr("ceph_volume.util.device.disk.get_devices", lambda: {})
+    monkeypatch.setattr("ceph_volume.util.device.disk.get_devices", lambda device='': {})
     monkeypatch.setattr("ceph_volume.util.disk.udevadm_property", lambda *a, **kw: {})
 
 
@@ -297,7 +297,7 @@ def device_info(monkeypatch, patch_bluestore_label):
         udevadm = udevadm if udevadm else {}
         lv = Factory(**lv) if lv else None
         monkeypatch.setattr("ceph_volume.sys_info.devices", {})
-        monkeypatch.setattr("ceph_volume.util.device.disk.get_devices", lambda: devices)
+        monkeypatch.setattr("ceph_volume.util.device.disk.get_devices", lambda device='': devices)
         if not devices:
             monkeypatch.setattr("ceph_volume.util.device.lvm.get_single_lv", lambda filters: lv)
         else:
index 015cfe6ff607c497176d9e73f910a9cb19f56a7a..d0a942d073be1a0defd16525f0a1e30b51bbbc1c 100644 (file)
@@ -111,7 +111,10 @@ class Device(object):
             if "dm-" not in real_path:
                 self.path = real_path
         if not sys_info.devices:
-            sys_info.devices = disk.get_devices()
+            if self.path:
+                sys_info.devices = disk.get_devices(device=self.path)
+            else:
+                sys_info.devices = disk.get_devices()
         if sys_info.devices.get(self.path, {}):
             self.device_nodes = sys_info.devices[self.path]['device_nodes']
         self.sys_api = sys_info.devices.get(self.path, {})
index 4f388742d8dee5f05fac66e5b6d9bb488dc46b60..4a310e30f3d5cf6a5defb08cacad87f417587b5a 100644 (file)
@@ -777,7 +777,7 @@ class AllowLoopDevices(object):
 allow_loop_devices = AllowLoopDevices()
 
 
-def get_block_devs_sysfs(_sys_block_path='/sys/block', _sys_dev_block_path='/sys/dev/block'):
+def get_block_devs_sysfs(_sys_block_path='/sys/block', _sys_dev_block_path='/sys/dev/block', device=''):
     def holder_inner_loop():
         for holder in holders:
             # /sys/block/sdy/holders/dm-8/dm/uuid
@@ -787,7 +787,10 @@ def get_block_devs_sysfs(_sys_block_path='/sys/block', _sys_dev_block_path='/sys
 
     # First, get devices that are _not_ partitions
     result = list()
-    dev_names = os.listdir(_sys_block_path)
+    if not device:
+        dev_names = os.listdir(_sys_block_path)
+    else:
+        dev_names = [device]
     for dev in dev_names:
         name = kname = os.path.join("/dev", dev)
         if not os.path.exists(name):