Add ceph-mgr bootstrap function

As of the Luminous release, Ceph requires ceph-mgr daemons be run
to have a fully functional cluster. [0]

[0] http://docs.ceph.com/docs/master/mgr/administrator/

Change-Id: I31197dcd3ad05c0db3811096c6d88308e7c10658
This commit is contained in:
Corey Bryant 2017-08-09 12:35:48 +00:00
parent f2b0fcf9e8
commit 55a89963d6
2 changed files with 72 additions and 0 deletions

View File

@ -1314,6 +1314,27 @@ def bootstrap_monitor_cluster(secret):
os.unlink(keyring)
def bootstrap_manager():
hostname = socket.gethostname()
path = '/var/lib/ceph/mgr/ceph-{}'.format(hostname)
keyring = os.path.join(path, 'keyring')
if os.path.exists(keyring):
log('bootstrap_manager: mgr already initialized.')
else:
mkdir(path, owner=ceph_user(), group=ceph_user())
subprocess.check_call(['ceph', 'auth', 'get-or-create',
'mgr.{}'.format(hostname), 'mon',
'allow profile mgr', 'osd', 'allow *',
'mds', 'allow *', '--out-file',
keyring])
chownr(path, ceph_user(), ceph_user())
unit = 'ceph-mgr@{}'.format(hostname)
subprocess.check_call(['systemctl', 'enable', unit])
service_restart(unit)
def update_monfs():
hostname = socket.gethostname()
monfs = '/var/lib/ceph/mon/ceph-{}'.format(hostname)

View File

@ -408,6 +408,57 @@ class CephTestCase(unittest.TestCase):
def test_bootstrap_monitor_cluster_luminous(self):
self._test_bootstrap_monitor_cluster(luminos=True)
@mock.patch.object(ceph, 'chownr')
@mock.patch.object(ceph, 'cmp_pkgrevno')
@mock.patch.object(ceph, 'ceph_user')
@mock.patch.object(ceph, 'os')
@mock.patch.object(ceph, 'log')
@mock.patch.object(ceph, 'mkdir')
@mock.patch.object(ceph, 'subprocess')
@mock.patch.object(ceph, 'service_restart')
def test_bootstrap_manager(self,
mock_service_restart,
mock_subprocess,
mock_mkdir,
mock_log,
mock_os,
mock_ceph_user,
mock_cmp_pkgrevno,
mock_chownr):
test_hostname = ceph.socket.gethostname()
test_path = '/var/lib/ceph/mgr/ceph-{}'.format(test_hostname)
test_keyring = '/var/lib/ceph/mgr/ceph-{}/keyring'.format(
test_hostname)
test_unit = 'ceph-mgr@{}'.format(test_hostname)
mock_os.path.exists.return_value = False
mock_os.path.join.return_value = test_keyring
mock_ceph_user.return_value = 'ceph'
test_calls = [
mock.call(
['ceph', 'auth', 'get-or-create',
'mgr.{}'.format(test_hostname), 'mon',
'allow profile mgr', 'osd', 'allow *',
'mds', 'allow *', '--out-file',
test_keyring]
),
mock.call(['systemctl', 'enable', test_unit]),
]
mock_open = mock.mock_open()
with mock.patch('ceph.open', mock_open, create=True):
ceph.bootstrap_manager()
self.assertEqual(
mock_subprocess.check_call.mock_calls,
test_calls
)
mock_service_restart.assert_called_with(test_unit)
mock_mkdir.assert_has_calls([
mock.call(test_path, owner='ceph', group='ceph'),
])
class CephVersionTestCase(unittest.TestCase):
@mock.patch.object(ceph, 'get_os_codename_install_source')