Skip to content

Commit

Permalink
ceph-volume: allow symlinks as devices
Browse files Browse the repository at this point in the history
This MR creates ability to use symlinks as devices for ceph-volume.
One example of use will include usage of custom udev rules to map disk slots in enclosures to block device labels like:

/dev/data1 -> /dev/sda
/dev/data2 -> /dev/sdb

Fixes: https://tracker.ceph.com/issues/49103

Signed-off-by: Jan Sobczak <jsobczak@cloudferro.com>
Co-authored-by: Guillaume Abrioux <gabrioux@redhat.com>
  • Loading branch information
Jan Sobczak and guits committed Jun 29, 2022
1 parent 12aade9 commit 58f7d4d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
34 changes: 33 additions & 1 deletion src/ceph-volume/ceph_volume/tests/util/test_device.py
Expand Up @@ -230,7 +230,39 @@ def test_reject_not_acceptable_device(self, fake_call, device_info):
disk = device.Device("/dev/dm-0")
assert not disk.available

def test_reject_readonly_device(self, fake_call, device_info):
@patch('ceph_volume.util.device.os.readlink')
@patch('ceph_volume.util.device.os.path.islink')
def test_accept_symlink_to_device(self,
m_os_path_islink,
m_os_readlink,
device_info,
fake_call):
m_os_path_islink.return_value = True
m_os_readlink.return_value = '/dev/sdb'
data = {"/dev/sdb": {"ro": 0, "size": 5368709120}}
lsblk = {"TYPE": "disk"}
device_info(devices=data,lsblk=lsblk)
disk = device.Device("/dev/test_symlink")
print(disk)
print(disk.sys_api)
assert disk.available

@patch('ceph_volume.util.device.os.readlink')
@patch('ceph_volume.util.device.os.path.islink')
def test_reject_symlink_to_device_mapper(self,
m_os_path_islink,
m_os_readlink,
device_info,
fake_call):
m_os_path_islink.return_value = True
m_os_readlink.return_value = '/dev/dm-0'
data = {"/dev/mapper/mpatha": {"ro": 0, "size": 5368709120}}
lsblk = {"TYPE": "disk"}
device_info(devices=data,lsblk=lsblk)
disk = device.Device("/dev/mapper/mpatha")
assert disk.available

def test_reject_readonly_device(self, device_info, fake_call):
data = {"/dev/cdrom": {"ro": 1}}
lsblk = {"TYPE": "disk"}
device_info(devices=data,lsblk=lsblk)
Expand Down
8 changes: 7 additions & 1 deletion src/ceph-volume/ceph_volume/util/device.py
Expand Up @@ -151,6 +151,13 @@ def __hash__(self):
def _parse(self):
if not sys_info.devices:
sys_info.devices = disk.get_devices()
# check if we are a symlink
if os.path.islink(self.abspath):
temp_path = os.path.join(os.path.dirname(self.abspath),
os.readlink(self.abspath))
# check if we are not a device mapper
if "dm-" not in temp_path:
self.abspath = temp_path
self.sys_api = sys_info.devices.get(self.abspath, {})
if not self.sys_api:
# if no device was found check if we are a partition
Expand All @@ -160,7 +167,6 @@ def _parse(self):
if part:
self.sys_api = part
break

# if the path is not absolute, we have 'vg/lv', let's use LV name
# to get the LV.
if self.path[0] == '/':
Expand Down

0 comments on commit 58f7d4d

Please sign in to comment.