From cdf09477abe9a56bf12046498e5caa8e9878a813 Mon Sep 17 00:00:00 2001 From: James Page Date: Mon, 15 Oct 2012 11:13:36 +0100 Subject: [PATCH] Update bootstrap handling to ensure key and fsid are present before trying to init and start OSD devices. Refactor osd device rescanning into ceph package. --- hooks/ceph.py | 13 +++++++++++++ hooks/hooks.py | 27 ++++++++++++++------------- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/hooks/ceph.py b/hooks/ceph.py index 567ec3fa..3e466c50 100644 --- a/hooks/ceph.py +++ b/hooks/ceph.py @@ -72,9 +72,22 @@ def is_osd_disk(dev): pass return False + +def rescan_osd_devices(): + cmd = [ + 'udevadm', 'trigger', + '--subsystem-match=block', '--action=add' + ] + + subprocess.call(cmd) + _bootstrap_keyring = "/var/lib/ceph/bootstrap-osd/ceph.keyring" +def is_bootstrapped(): + return os.path.exists(_bootstrap_keyring) + + def import_osd_bootstrap_key(key): if not os.path.exists(_bootstrap_keyring): cmd = [ diff --git a/hooks/hooks.py b/hooks/hooks.py index 74183b2d..5a43ce00 100755 --- a/hooks/hooks.py +++ b/hooks/hooks.py @@ -31,8 +31,11 @@ def install(): def emit_cephconf(): + mon_hosts = get_mon_hosts() + utils.juju_log('INFO', 'Monitor hosts are ' + repr(mon_hosts)) + cephcontext = { - 'mon_hosts': ' '.join(get_mon_hosts()), + 'mon_hosts': ' '.join(mon_hosts), 'fsid': get_fsid() } @@ -43,15 +46,12 @@ def emit_cephconf(): def config_changed(): utils.juju_log('INFO', 'Begin config-changed hook.') - utils.juju_log('INFO', 'Monitor hosts are ' + repr(get_mon_hosts())) - - if get_fsid(): - utils.juju_log('INFO', 'cluster fsid detected, rescanning disks') + if ceph.is_bootstrapped(): + utils.juju_log('INFO', 'ceph bootstrapped, rescanning disks') emit_cephconf() for dev in utils.config_get('osd-devices').split(' '): osdize(dev) - subprocess.call(['udevadm', 'trigger', - '--subsystem-match=block', '--action=add']) + ceph.rescan_osd_devices() utils.juju_log('INFO', 'End config-changed hook.') @@ -103,17 +103,18 @@ def osdize(dev): def mon_relation(): utils.juju_log('INFO', 'Begin mon-relation hook.') - if get_fsid(): - utils.juju_log('INFO', 'mon has provided fsid - scanning disks') + bootstrap_key = utils.relation_get('osd_bootstrap_key') + if (get_fsid() and + bootstrap_key != ""): + utils.juju_log('INFO', 'mon has provided fsid & key- scanning disks') emit_cephconf() - ceph.import_osd_bootstrap_key(utils.relation_get('osd_bootstrap_key')) + ceph.import_osd_bootstrap_key(bootstrap_key) for dev in utils.config_get('osd-devices').split(' '): osdize(dev) - subprocess.call(['udevadm', 'trigger', - '--subsystem-match=block', '--action=add']) + ceph.rescan_osd_devices() else: utils.juju_log('INFO', - 'mon cluster has not yet provided fsid') + 'mon cluster has not yet provided fsid & key') utils.juju_log('INFO', 'End mon-relation hook.')