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: I17fab658511275f1dde15683ef296d4c72e7980e Closes-Bug: #1814597 Depends-On: I940b108d914b39b55013a4617c3d17ff7122df60
This commit is contained in:
parent
faefe90ce6
commit
9bc5abab55
|
@ -1442,77 +1442,82 @@ def osdize_dev(dev, osd_format, osd_journal, ignore_errors=False,
|
||||||
|
|
||||||
db = kv()
|
db = kv()
|
||||||
osd_devices = db.get('osd-devices', [])
|
osd_devices = db.get('osd-devices', [])
|
||||||
if dev in osd_devices:
|
|
||||||
log('Device {} already processed by charm,'
|
|
||||||
' skipping'.format(dev))
|
|
||||||
return
|
|
||||||
|
|
||||||
if not os.path.exists(dev):
|
|
||||||
log('Path {} does not exist - bailing'.format(dev))
|
|
||||||
return
|
|
||||||
|
|
||||||
if not is_block_device(dev):
|
|
||||||
log('Path {} is not a block device - bailing'.format(dev))
|
|
||||||
return
|
|
||||||
|
|
||||||
if is_osd_disk(dev):
|
|
||||||
log('Looks like {} is already an'
|
|
||||||
' OSD data or journal, skipping.'.format(dev))
|
|
||||||
return
|
|
||||||
|
|
||||||
if is_device_mounted(dev):
|
|
||||||
log('Looks like {} is in use, skipping.'.format(dev))
|
|
||||||
return
|
|
||||||
|
|
||||||
if is_active_bluestore_device(dev):
|
|
||||||
log('{} is in use as an active bluestore block device,'
|
|
||||||
' skipping.'.format(dev))
|
|
||||||
return
|
|
||||||
|
|
||||||
if is_mapped_luks_device(dev):
|
|
||||||
log('{} is a mapped LUKS device,'
|
|
||||||
' skipping.'.format(dev))
|
|
||||||
return
|
|
||||||
|
|
||||||
if cmp_pkgrevno('ceph', '12.2.4') >= 0:
|
|
||||||
cmd = _ceph_volume(dev,
|
|
||||||
osd_journal,
|
|
||||||
encrypt,
|
|
||||||
bluestore,
|
|
||||||
key_manager)
|
|
||||||
else:
|
|
||||||
cmd = _ceph_disk(dev,
|
|
||||||
osd_format,
|
|
||||||
osd_journal,
|
|
||||||
encrypt,
|
|
||||||
bluestore)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
status_set('maintenance', 'Initializing device {}'.format(dev))
|
if dev in osd_devices:
|
||||||
log("osdize cmd: {}".format(cmd))
|
log('Device {} already processed by charm,'
|
||||||
subprocess.check_call(cmd)
|
' skipping'.format(dev))
|
||||||
except subprocess.CalledProcessError:
|
return
|
||||||
try:
|
|
||||||
lsblk_output = subprocess.check_output(
|
|
||||||
['lsblk', '-P']).decode('UTF-8')
|
|
||||||
except subprocess.CalledProcessError as e:
|
|
||||||
log("Couldn't get lsblk output: {}".format(e), ERROR)
|
|
||||||
if ignore_errors:
|
|
||||||
log('Unable to initialize device: {}'.format(dev), WARNING)
|
|
||||||
if lsblk_output:
|
|
||||||
log('lsblk output: {}'.format(lsblk_output), DEBUG)
|
|
||||||
else:
|
|
||||||
log('Unable to initialize device: {}'.format(dev), ERROR)
|
|
||||||
if lsblk_output:
|
|
||||||
log('lsblk output: {}'.format(lsblk_output), WARNING)
|
|
||||||
raise
|
|
||||||
|
|
||||||
# NOTE: Record processing of device only on success to ensure that
|
if not os.path.exists(dev):
|
||||||
# the charm only tries to initialize a device of OSD usage
|
log('Path {} does not exist - bailing'.format(dev))
|
||||||
# once during its lifetime.
|
return
|
||||||
osd_devices.append(dev)
|
|
||||||
db.set('osd-devices', osd_devices)
|
if not is_block_device(dev):
|
||||||
db.flush()
|
log('Path {} is not a block device - bailing'.format(dev))
|
||||||
|
return
|
||||||
|
|
||||||
|
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):
|
||||||
|
log('Looks like {} is in use, skipping.'.format(dev))
|
||||||
|
return
|
||||||
|
|
||||||
|
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):
|
||||||
|
log('{} is a mapped LUKS device,'
|
||||||
|
' skipping.'.format(dev))
|
||||||
|
return
|
||||||
|
|
||||||
|
if cmp_pkgrevno('ceph', '12.2.4') >= 0:
|
||||||
|
cmd = _ceph_volume(dev,
|
||||||
|
osd_journal,
|
||||||
|
encrypt,
|
||||||
|
bluestore,
|
||||||
|
key_manager)
|
||||||
|
else:
|
||||||
|
cmd = _ceph_disk(dev,
|
||||||
|
osd_format,
|
||||||
|
osd_journal,
|
||||||
|
encrypt,
|
||||||
|
bluestore)
|
||||||
|
|
||||||
|
try:
|
||||||
|
status_set('maintenance', 'Initializing device {}'.format(dev))
|
||||||
|
log("osdize cmd: {}".format(cmd))
|
||||||
|
subprocess.check_call(cmd)
|
||||||
|
except subprocess.CalledProcessError:
|
||||||
|
try:
|
||||||
|
lsblk_output = subprocess.check_output(
|
||||||
|
['lsblk', '-P']).decode('UTF-8')
|
||||||
|
except subprocess.CalledProcessError as e:
|
||||||
|
log("Couldn't get lsblk output: {}".format(e), ERROR)
|
||||||
|
if ignore_errors:
|
||||||
|
log('Unable to initialize device: {}'.format(dev), WARNING)
|
||||||
|
if lsblk_output:
|
||||||
|
log('lsblk output: {}'.format(lsblk_output), DEBUG)
|
||||||
|
else:
|
||||||
|
log('Unable to initialize device: {}'.format(dev), ERROR)
|
||||||
|
if lsblk_output:
|
||||||
|
log('lsblk output: {}'.format(lsblk_output), WARNING)
|
||||||
|
raise
|
||||||
|
|
||||||
|
# NOTE: Record processing of device only on success to ensure that
|
||||||
|
# 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()
|
||||||
|
|
||||||
|
|
||||||
def _ceph_disk(dev, osd_format, osd_journal, encrypt=False, bluestore=False):
|
def _ceph_disk(dev, osd_format, osd_journal, encrypt=False, bluestore=False):
|
||||||
|
|
Loading…
Reference in New Issue