Add directories to osd-devices as well

Tracking directory backed OSDs in the kv store allows
us to bootstrap further relations based on bootstrapped
OSD counts.

Change-Id: I1a28a28dbd325dd7ffd74940a07be9908d74689c
Closes-Bug: #1802134
This commit is contained in:
Chris MacNaughton 2018-11-07 17:13:34 +01:00
parent f77844b550
commit 646c45dcf4
2 changed files with 23 additions and 1 deletions

View File

@ -1876,6 +1876,14 @@ def osdize_dir(path, encrypt=False, bluestore=False):
:param encrypt: bool. Should the OSD directory be encrypted at rest
:returns: None
"""
db = kv()
osd_devices = db.get('osd-devices', [])
if path in osd_devices:
log('Device {} already processed by charm,'
' skipping'.format(path))
return
if os.path.exists(os.path.join(path, 'upstart')):
log('Path {} is already configured as an OSD - bailing'.format(path))
return
@ -1906,6 +1914,13 @@ def osdize_dir(path, encrypt=False, bluestore=False):
log("osdize dir cmd: {}".format(cmd))
subprocess.check_call(cmd)
# 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(path)
db.set('osd-devices', osd_devices)
db.flush()
def filesystem_mounted(fs):
return subprocess.call(['grep', '-wqs', fs, '/proc/mounts']) == 0

View File

@ -172,6 +172,7 @@ class CephTestCase(unittest.TestCase):
db.get.assert_called_with('osd-devices', [])
db.set.assert_not_called()
@patch.object(utils, 'kv')
@patch.object(utils.subprocess, 'check_call')
@patch.object(utils.os.path, 'exists')
@patch.object(utils, 'is_device_mounted')
@ -180,8 +181,11 @@ class CephTestCase(unittest.TestCase):
@patch.object(utils, 'chownr')
@patch.object(utils, 'ceph_user')
def test_osdize_dir(self, _ceph_user, _chown, _mkdir,
_cmp, _mounted, _exists, _call):
_cmp, _mounted, _exists, _call, _kv):
"""Test that the dev osd is initialized correctly"""
db = MagicMock()
_kv.return_value = db
db.get.return_value = []
_ceph_user.return_value = "ceph"
_mounted.return_value = False
_exists.return_value = False
@ -191,6 +195,9 @@ class CephTestCase(unittest.TestCase):
_call.assert_called_with(['sudo', '-u', 'ceph', 'ceph-disk', 'prepare',
'--data-dir', '/srv/osd', '--filestore'])
db.get.assert_called_with('osd-devices', [])
db.set.assert_called_with('osd-devices', ['/srv/osd'])
@patch.object(utils.subprocess, 'check_output')
def test_get_osd_weight(self, output):
"""It gives an OSD's weight"""