From: Guillaume Abrioux Date: Fri, 9 Sep 2022 13:00:20 +0000 (+0200) Subject: ceph-volume: fix inventory with device arg X-Git-Tag: v18.0.0~27^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F48037%2Fhead;p=ceph.git ceph-volume: fix inventory with device arg 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 --- diff --git a/src/ceph-volume/ceph_volume/tests/conftest.py b/src/ceph-volume/ceph_volume/tests/conftest.py index f060f78d44c5..89f8d6d11790 100644 --- a/src/ceph-volume/ceph_volume/tests/conftest.py +++ b/src/ceph-volume/ceph_volume/tests/conftest.py @@ -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: diff --git a/src/ceph-volume/ceph_volume/util/device.py b/src/ceph-volume/ceph_volume/util/device.py index 015cfe6ff607..d0a942d073be 100644 --- a/src/ceph-volume/ceph_volume/util/device.py +++ b/src/ceph-volume/ceph_volume/util/device.py @@ -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, {}) diff --git a/src/ceph-volume/ceph_volume/util/disk.py b/src/ceph-volume/ceph_volume/util/disk.py index 4f388742d8de..4a310e30f3d5 100644 --- a/src/ceph-volume/ceph_volume/util/disk.py +++ b/src/ceph-volume/ceph_volume/util/disk.py @@ -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):