From: Erwan Velu Date: Tue, 9 Oct 2018 20:02:31 +0000 (+0200) Subject: ceph_volume: Rejecting Read-only devices X-Git-Tag: v14.1.0~1075^2~4 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=f1a94350064263f27f67d2c715c5ca5922481a01;p=ceph.git ceph_volume: Rejecting Read-only devices If a devices is said to be read-only, there is no chance we can actually use it. So let's report it as unusable. Signed-off-by: Erwan Velu --- diff --git a/src/ceph-volume/ceph_volume/tests/util/test_device.py b/src/ceph-volume/ceph_volume/tests/util/test_device.py index 1e6766b45a3..a44be7697dc 100644 --- a/src/ceph-volume/ceph_volume/tests/util/test_device.py +++ b/src/ceph-volume/ceph_volume/tests/util/test_device.py @@ -162,6 +162,18 @@ class TestCephDiskDevice(object): disk = device.Device("/dev/sdb") assert disk.is_valid + def test_reject_readonly_device(self, device_info): + data = {"/dev/cdrom": {"ro": 1}} + device_info(devices=data) + disk = device.Device("/dev/cdrom") + assert not disk.is_valid + + def test_accept_non_readonly_device(self, device_info): + data = {"/dev/sda": {"ro": 0}} + device_info(devices=data) + disk = device.Device("/dev/sda") + assert disk.is_valid + @pytest.mark.parametrize("label", ceph_partlabels) def test_is_member_lsblk(self, device_info, label): lsblk = {"PARTLABEL": label} diff --git a/src/ceph-volume/ceph_volume/util/device.py b/src/ceph-volume/ceph_volume/util/device.py index a705678157f..7831c14ca81 100644 --- a/src/ceph-volume/ceph_volume/util/device.py +++ b/src/ceph-volume/ceph_volume/util/device.py @@ -141,6 +141,7 @@ class Device(object): except KeyError: pass reject_device('removable', 1, 'removable') + reject_device('ro', 1, 'read-only') self._valid = len(self._rejected_reasons) == 0 return self._valid diff --git a/src/ceph-volume/ceph_volume/util/disk.py b/src/ceph-volume/ceph_volume/util/disk.py index dd7c6242610..618bf435257 100644 --- a/src/ceph-volume/ceph_volume/util/disk.py +++ b/src/ceph-volume/ceph_volume/util/disk.py @@ -695,6 +695,9 @@ def get_devices(_sys_block_path='/sys/block', _dev_path='/dev', _mapper_path='/d continue metadata['removable'] = get_file_contents(os.path.join(sysdir, 'removable')) + # Is the device read-only ? + metadata['ro'] = get_file_contents(os.path.join(sysdir, 'ro')) + for key in ['vendor', 'model', 'sas_address', 'sas_device_handle']: metadata[key] = get_file_contents(sysdir + "/device/" + key)