From 7d168ad7bdbb6d6d5231a4ae540ab03040b49a38 Mon Sep 17 00:00:00 2001 From: Jan Fajerski Date: Fri, 11 Sep 2020 16:35:00 +0200 Subject: [PATCH] ceph-volume inventory: add option to filter unwanted devices Some device we never want to pass to the batch subcommand. For now this includes devices that have a partition or are mounted on the machine. One goal is to filter the root device, so it is not included on a batch command and thus would contribute to its implicit sizing calculation. Signed-off-by: Jan Fajerski --- src/ceph-volume/ceph_volume/inventory/main.py | 11 +++++++++-- .../ceph_volume/tests/devices/lvm/test_common.py | 1 - src/ceph-volume/ceph_volume/util/device.py | 16 +++++++++++++--- src/pybind/mgr/cephadm/module.py | 2 +- 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/ceph-volume/ceph_volume/inventory/main.py b/src/ceph-volume/ceph_volume/inventory/main.py index 470be274f52eb..f4b392e4173dd 100644 --- a/src/ceph-volume/ceph_volume/inventory/main.py +++ b/src/ceph-volume/ceph_volume/inventory/main.py @@ -31,17 +31,24 @@ class Inventory(object): default='plain', help='Output format', ) + parser.add_argument( + '--filter-for-batch', + action='store_true', + help=('Filter devices unsuitable to pass to an OSD service spec, ' + 'no effect when is passed'), + default=False, + ) self.args = parser.parse_args(self.argv) if self.args.path: self.format_report(Device(self.args.path)) else: - self.format_report(Devices()) + self.format_report(Devices(self.args.filter_for_batch)) def get_report(self): if self.args.path: return Device(self.args.path).json_report() else: - return Devices().json_report() + return Devices(self.args.filter_for_batch).json_report() def format_report(self, inventory): if self.args.format == 'json': diff --git a/src/ceph-volume/ceph_volume/tests/devices/lvm/test_common.py b/src/ceph-volume/ceph_volume/tests/devices/lvm/test_common.py index c6b8a3d945508..fe792d5ab99a2 100644 --- a/src/ceph-volume/ceph_volume/tests/devices/lvm/test_common.py +++ b/src/ceph-volume/ceph_volume/tests/devices/lvm/test_common.py @@ -1,4 +1,3 @@ -import pytest from ceph_volume.devices.lvm import common diff --git a/src/ceph-volume/ceph_volume/util/device.py b/src/ceph-volume/ceph_volume/util/device.py index 531b46e171126..f046f282233e3 100644 --- a/src/ceph-volume/ceph_volume/util/device.py +++ b/src/ceph-volume/ceph_volume/util/device.py @@ -4,7 +4,7 @@ import os from functools import total_ordering from ceph_volume import sys_info, process from ceph_volume.api import lvm -from ceph_volume.util import disk +from ceph_volume.util import disk, system from ceph_volume.util.lsmdisk import LSMDisk from ceph_volume.util.constants import ceph_disk_guids @@ -27,13 +27,15 @@ class Devices(object): A container for Device instances with reporting """ - def __init__(self, devices=None): + def __init__(self, devices=None, filter_for_batch=False): if not sys_info.devices: sys_info.devices = disk.get_devices() self.devices = [Device(k) for k in sys_info.devices.keys()] + if filter_for_batch: + self.devices = [d for d in self.devices if d.available_lvm_batch] - def pretty_report(self, all=True): + def pretty_report(self): output = [ report_template.format( dev='Device Path', @@ -498,6 +500,14 @@ class Device(object): return len(rejected) == 0, rejected + @property + def available_lvm_batch(self): + if self.sys_api.get("partitions"): + return False + if system.device_is_mounted(self.path): + return False + return self.is_device or self.is_lv + class CephDiskDevice(object): """ diff --git a/src/pybind/mgr/cephadm/module.py b/src/pybind/mgr/cephadm/module.py index a36a220650061..0018887f48cd9 100644 --- a/src/pybind/mgr/cephadm/module.py +++ b/src/pybind/mgr/cephadm/module.py @@ -1541,7 +1541,7 @@ To check that the host is reachable: out, err, code = self._run_cephadm( host, 'osd', 'ceph-volume', - ['--', 'inventory', '--format=json']) + ['--', 'inventory', '--format=json', '--filter-for-batch']) if code: return 'host %s ceph-volume inventory returned %d: %s' % ( host, code, err) -- 2.39.5