Ensure we populate osd-devices with existing devices

If an older version of ceph-osd is deployed and then
upgraded to a version that keeps track of bootstrapped
OSDs, then the list of osd-devices never gets updated
with the pre-existing devices.

This change allows us to add existing, mounted Ceph
OSDs to the osd-devices entry in the local KV storage.

Change-Id: I940b108d914b39b55013a4617c3d17ff7122df60
Closes-Bug: #1814597
This commit is contained in:
Chris MacNaughton 2019-02-05 12:20:25 +01:00 committed by Chris MacNaughton (icey)
parent 33b4082685
commit 886ef0b224
2 changed files with 96 additions and 71 deletions

View File

@ -1446,6 +1446,7 @@ def osdize_dev(dev, osd_format, osd_journal, ignore_errors=False,
db = kv()
osd_devices = db.get('osd-devices', [])
try:
if dev in osd_devices:
log('Device {} already processed by charm,'
' skipping'.format(dev))
@ -1462,6 +1463,8 @@ def osdize_dev(dev, osd_format, osd_journal, ignore_errors=False,
if is_osd_disk(dev):
log('Looks like {} is already an'
' OSD data or journal, skipping.'.format(dev))
if is_device_mounted(dev):
osd_devices.append(dev)
return
if is_device_mounted(dev):
@ -1471,6 +1474,7 @@ def osdize_dev(dev, osd_format, osd_journal, ignore_errors=False,
if is_active_bluestore_device(dev):
log('{} is in use as an active bluestore block device,'
' skipping.'.format(dev))
osd_devices.append(dev)
return
if is_mapped_luks_device(dev):
@ -1515,6 +1519,7 @@ def osdize_dev(dev, osd_format, osd_journal, ignore_errors=False,
# the charm only tries to initialize a device of OSD usage
# once during its lifetime.
osd_devices.append(dev)
finally:
db.set('osd-devices', osd_devices)
db.flush()

View File

@ -140,7 +140,27 @@ class CephTestCase(unittest.TestCase):
utils.osdize('/dev/sdb', osd_format='xfs', osd_journal=None,
bluestore=False)
db.get.assert_called_with('osd-devices', [])
db.set.assert_not_called()
db.set.assert_called_with('osd-devices', ['/dev/sdb'])
@patch.object(utils, 'kv')
@patch.object(utils.os.path, 'exists')
@patch.object(utils, 'is_device_mounted')
@patch.object(utils, 'is_block_device')
@patch.object(utils, 'is_osd_disk')
def test_osdize_dev_already_processed_without_kv(self, _is_osd, _is_blk,
_mounted, _exists, _kv):
"""Ensure that previously processed disks are skipped"""
db = MagicMock()
_kv.return_value = db
db.get.return_value = []
_exists.return_value = True
_is_osd.return_value = True
_mounted.return_value = True
_is_blk.return_value = True
utils.osdize('/dev/sdb', osd_format='xfs', osd_journal=None,
bluestore=False)
db.get.assert_called_with('osd-devices', [])
db.set.assert_called_with('osd-devices', ['/dev/sdb'])
@patch.object(utils, 'kv')
@patch.object(utils.subprocess, 'check_call')
@ -170,7 +190,7 @@ class CephTestCase(unittest.TestCase):
utils.osdize('/dev/sdb', encrypt=True, osd_format=None,
osd_journal=None, bluestore=True, key_manager='vault')
db.get.assert_called_with('osd-devices', [])
db.set.assert_not_called()
db.set.assert_called_with('osd-devices', [])
@patch.object(utils, 'kv')
@patch.object(utils.subprocess, 'check_call')