summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCorey Bryant <corey.bryant@canonical.com>2017-08-09 12:35:48 +0000
committerCorey Bryant <corey.bryant@canonical.com>2017-08-10 20:32:09 +0000
commit55a89963d663427c49cee615d4e6afad1ca16ac1 (patch)
tree3cda222e994941c657cf9ac0fc6a42b383db9b0a
parentf2b0fcf9e84d76ac1ff8282d389ceabcfdbc0ac4 (diff)
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
Notes
Notes (review): Code-Review+1: Pete Vander Giessen <pete.vandergiessen@canonical.com> Code-Review+2: Billy Olsen <billy.olsen@gmail.com> Workflow+1: Billy Olsen <billy.olsen@gmail.com> Verified+2: Jenkins Submitted-by: Jenkins Submitted-at: Fri, 11 Aug 2017 01:23:57 +0000 Reviewed-on: https://review.openstack.org/492122 Project: openstack/charms.ceph Branch: refs/heads/master
-rw-r--r--ceph/__init__.py21
-rw-r--r--unit_tests/test_ceph.py51
2 files changed, 72 insertions, 0 deletions
diff --git a/ceph/__init__.py b/ceph/__init__.py
index 7f8d3a4..6aaf4fa 100644
--- a/ceph/__init__.py
+++ b/ceph/__init__.py
@@ -1314,6 +1314,27 @@ def bootstrap_monitor_cluster(secret):
1314 os.unlink(keyring) 1314 os.unlink(keyring)
1315 1315
1316 1316
1317def bootstrap_manager():
1318 hostname = socket.gethostname()
1319 path = '/var/lib/ceph/mgr/ceph-{}'.format(hostname)
1320 keyring = os.path.join(path, 'keyring')
1321
1322 if os.path.exists(keyring):
1323 log('bootstrap_manager: mgr already initialized.')
1324 else:
1325 mkdir(path, owner=ceph_user(), group=ceph_user())
1326 subprocess.check_call(['ceph', 'auth', 'get-or-create',
1327 'mgr.{}'.format(hostname), 'mon',
1328 'allow profile mgr', 'osd', 'allow *',
1329 'mds', 'allow *', '--out-file',
1330 keyring])
1331 chownr(path, ceph_user(), ceph_user())
1332
1333 unit = 'ceph-mgr@{}'.format(hostname)
1334 subprocess.check_call(['systemctl', 'enable', unit])
1335 service_restart(unit)
1336
1337
1317def update_monfs(): 1338def update_monfs():
1318 hostname = socket.gethostname() 1339 hostname = socket.gethostname()
1319 monfs = '/var/lib/ceph/mon/ceph-{}'.format(hostname) 1340 monfs = '/var/lib/ceph/mon/ceph-{}'.format(hostname)
diff --git a/unit_tests/test_ceph.py b/unit_tests/test_ceph.py
index faa3728..015f58f 100644
--- a/unit_tests/test_ceph.py
+++ b/unit_tests/test_ceph.py
@@ -408,6 +408,57 @@ class CephTestCase(unittest.TestCase):
408 def test_bootstrap_monitor_cluster_luminous(self): 408 def test_bootstrap_monitor_cluster_luminous(self):
409 self._test_bootstrap_monitor_cluster(luminos=True) 409 self._test_bootstrap_monitor_cluster(luminos=True)
410 410
411 @mock.patch.object(ceph, 'chownr')
412 @mock.patch.object(ceph, 'cmp_pkgrevno')
413 @mock.patch.object(ceph, 'ceph_user')
414 @mock.patch.object(ceph, 'os')
415 @mock.patch.object(ceph, 'log')
416 @mock.patch.object(ceph, 'mkdir')
417 @mock.patch.object(ceph, 'subprocess')
418 @mock.patch.object(ceph, 'service_restart')
419 def test_bootstrap_manager(self,
420 mock_service_restart,
421 mock_subprocess,
422 mock_mkdir,
423 mock_log,
424 mock_os,
425 mock_ceph_user,
426 mock_cmp_pkgrevno,
427 mock_chownr):
428 test_hostname = ceph.socket.gethostname()
429 test_path = '/var/lib/ceph/mgr/ceph-{}'.format(test_hostname)
430 test_keyring = '/var/lib/ceph/mgr/ceph-{}/keyring'.format(
431 test_hostname)
432 test_unit = 'ceph-mgr@{}'.format(test_hostname)
433
434 mock_os.path.exists.return_value = False
435 mock_os.path.join.return_value = test_keyring
436 mock_ceph_user.return_value = 'ceph'
437
438 test_calls = [
439 mock.call(
440 ['ceph', 'auth', 'get-or-create',
441 'mgr.{}'.format(test_hostname), 'mon',
442 'allow profile mgr', 'osd', 'allow *',
443 'mds', 'allow *', '--out-file',
444 test_keyring]
445 ),
446 mock.call(['systemctl', 'enable', test_unit]),
447 ]
448
449 mock_open = mock.mock_open()
450 with mock.patch('ceph.open', mock_open, create=True):
451 ceph.bootstrap_manager()
452
453 self.assertEqual(
454 mock_subprocess.check_call.mock_calls,
455 test_calls
456 )
457 mock_service_restart.assert_called_with(test_unit)
458 mock_mkdir.assert_has_calls([
459 mock.call(test_path, owner='ceph', group='ceph'),
460 ])
461
411 462
412class CephVersionTestCase(unittest.TestCase): 463class CephVersionTestCase(unittest.TestCase):
413 @mock.patch.object(ceph, 'get_os_codename_install_source') 464 @mock.patch.object(ceph, 'get_os_codename_install_source')