Consider crimson-osds as well

This patchset modifies the 'get_running_osds' function so that
it also considers crimson-osds as valid OSD's. In addition, it
also modifies the 'get_local_osd_ids' to _not_ include Crimson
OSDs so that unsupported functionality doesn't make some hooks
fail in the ceph-osd charm.

Change-Id: If58bde4d5445ed5de420abc007db6bf8b8e43269
This commit is contained in:
Luciano Lo Giudice 2022-09-05 16:14:32 -03:00
parent 45fe9ad44e
commit 84adacf5c8
2 changed files with 28 additions and 3 deletions

View File

@ -681,15 +681,29 @@ def _get_osd_num_from_dirname(dirname):
return match.group('osd_id')
def get_crimson_osd_ids():
"""Return a set of the OSDs that are running with the Crimson backend."""
rv = set()
try:
out = subprocess.check_output(['pgrep', 'crimson-osd', '-a'])
for line in out.decode('utf8').splitlines():
rv.add(line.split()[-1])
except Exception:
pass
return rv
def get_local_osd_ids():
"""This will list the /var/lib/ceph/osd/* directories and try
to split the ID off of the directory name and return it in
a list.
a list. Excludes crimson OSD's from the returned list.
:returns: list. A list of OSD identifiers
:raises: OSError if something goes wrong with listing the directory.
"""
osd_ids = []
crimson_osds = get_crimson_osd_ids()
osd_path = os.path.join(os.sep, 'var', 'lib', 'ceph', 'osd')
if os.path.exists(osd_path):
try:
@ -698,7 +712,8 @@ def get_local_osd_ids():
osd_id = osd_dir.split('-')[1]
if (_is_int(osd_id) and
filesystem_mounted(os.path.join(
os.sep, osd_path, osd_dir))):
os.sep, osd_path, osd_dir)) and
osd_id not in crimson_osds):
osd_ids.append(osd_id)
except OSError:
raise
@ -2067,7 +2082,7 @@ def filesystem_mounted(fs):
def get_running_osds():
"""Returns a list of the pids of the current running OSD daemons"""
cmd = ['pgrep', 'ceph-osd']
cmd = ['pgrep', 'ceph-osd|crimson-osd']
try:
result = str(subprocess.check_output(cmd).decode('UTF-8'))
return result.split()

View File

@ -1241,6 +1241,16 @@ class CephApplyOSDSettingsTestCase(unittest.TestCase):
self.grace = 'osd_heartbeat_grace'
self.interval = 'osd_heartbeat_interval'
@patch.object(utils.subprocess, 'check_output')
@patch.object(utils.os.path, 'exists')
@patch.object(utils.os, 'listdir')
@patch.object(utils, 'filesystem_mounted')
def test_osd_ids_with_crimson(self, fs_mounted, listdir,
path_exists, check_output):
check_output.return_value = b'38271 /usr/bin/crimson-osd -i 5\n'
listdir.return_value = ['ceph-3', 'ceph-5']
self.assertEqual(['3'], utils.get_local_osd_ids())
@patch.object(utils, 'get_local_osd_ids')
@patch.object(utils.subprocess, 'check_output')
def test_apply_osd_settings(self, _check_output, _get_local_osd_ids):