Trigger udev rescan if pv_dev disappears
Workaround for kernel by in Ubuntu 20.04 LTS. When using by-dname device paths with MAAS and bcache, the pvcreate operation results in the by-dname entry for the block device being deleted. The subsequent vgcreate then fails as the path cannot be found. Trigger a rescan of block devices if the pv_dev path does not exists after the pvcreate operation. Change-Id: Ifb16c47ae5ff316cbcfc3798de3446a3774fa012 Related-Bug: 1878752
This commit is contained in:
parent
d783db8f88
commit
2d61a56544
|
@ -1957,6 +1957,9 @@ def _allocate_logical_volume(dev, lv_type, osd_fsid,
|
|||
vg_name = None
|
||||
if not lvm.is_lvm_physical_volume(pv_dev):
|
||||
lvm.create_lvm_physical_volume(pv_dev)
|
||||
if not os.path.exists(pv_dev):
|
||||
# NOTE: trigger rescan to work around bug 1878752
|
||||
rescan_osd_devices()
|
||||
if shared:
|
||||
vg_name = 'ceph-{}-{}'.format(lv_type,
|
||||
str(uuid.uuid4()))
|
||||
|
|
|
@ -38,3 +38,80 @@ class GeneralUtilsTestCase(unittest.TestCase):
|
|||
'--subsystem-match=block',
|
||||
'--action=add'])
|
||||
_udevadm_settle.assert_called_once_with()
|
||||
|
||||
|
||||
class AllocateLVTestCase(unittest.TestCase):
|
||||
|
||||
@patch.object(charms_ceph.utils, 'rescan_osd_devices')
|
||||
@patch.object(charms_ceph.utils, '_initialize_disk')
|
||||
@patch.object(charms_ceph.utils.os.path, 'exists')
|
||||
@patch.object(charms_ceph.utils, 'lvm')
|
||||
def test_allocate_lv_ok(self,
|
||||
_lvm,
|
||||
_exists,
|
||||
_initialize_disk,
|
||||
_rescan_osd_devices):
|
||||
_exists.return_value = True
|
||||
_lvm.list_logical_volumes.return_value = []
|
||||
_lvm.is_lvm_physical_volume.return_value = False
|
||||
_initialize_disk.side_effect = (
|
||||
lambda dev, dev_uuid, encrypt, key_manager: dev
|
||||
)
|
||||
self.assertEqual(
|
||||
charms_ceph.utils._allocate_logical_volume(
|
||||
dev="/dev/disk/by-dname/foobar",
|
||||
lv_type="block",
|
||||
osd_fsid="abcdef"
|
||||
),
|
||||
"ceph-abcdef/osd-block-abcdef"
|
||||
)
|
||||
_lvm.create_lvm_physical_volume.assert_called_once_with(
|
||||
"/dev/disk/by-dname/foobar"
|
||||
)
|
||||
_lvm.create_lvm_volume_group.assert_called_once_with(
|
||||
"ceph-abcdef",
|
||||
"/dev/disk/by-dname/foobar"
|
||||
)
|
||||
_lvm.create_logical_volume.assert_called_once_with(
|
||||
"osd-block-abcdef",
|
||||
"ceph-abcdef",
|
||||
None,
|
||||
)
|
||||
_rescan_osd_devices.assert_not_called()
|
||||
|
||||
@patch.object(charms_ceph.utils, 'rescan_osd_devices')
|
||||
@patch.object(charms_ceph.utils, '_initialize_disk')
|
||||
@patch.object(charms_ceph.utils.os.path, 'exists')
|
||||
@patch.object(charms_ceph.utils, 'lvm')
|
||||
def test_allocate_lv_bug1878752(self,
|
||||
_lvm,
|
||||
_exists,
|
||||
_initialize_disk,
|
||||
_rescan_osd_devices):
|
||||
_exists.return_value = False
|
||||
_lvm.list_logical_volumes.return_value = []
|
||||
_lvm.is_lvm_physical_volume.return_value = False
|
||||
_initialize_disk.side_effect = (
|
||||
lambda dev, dev_uuid, encrypt, key_manager: dev
|
||||
)
|
||||
self.assertEqual(
|
||||
charms_ceph.utils._allocate_logical_volume(
|
||||
dev="/dev/disk/by-dname/foobar",
|
||||
lv_type="block",
|
||||
osd_fsid="abcdef"
|
||||
),
|
||||
"ceph-abcdef/osd-block-abcdef"
|
||||
)
|
||||
_lvm.create_lvm_physical_volume.assert_called_once_with(
|
||||
"/dev/disk/by-dname/foobar"
|
||||
)
|
||||
_lvm.create_lvm_volume_group.assert_called_once_with(
|
||||
"ceph-abcdef",
|
||||
"/dev/disk/by-dname/foobar"
|
||||
)
|
||||
_lvm.create_logical_volume.assert_called_once_with(
|
||||
"osd-block-abcdef",
|
||||
"ceph-abcdef",
|
||||
None,
|
||||
)
|
||||
_rescan_osd_devices.assert_called_once_with()
|
||||
|
|
Loading…
Reference in New Issue