Add option to ignore device errors

This commit is contained in:
james.page@ubuntu.com 2014-08-15 10:06:49 +01:00
parent eb1d0968d3
commit e9034b466c
3 changed files with 28 additions and 7 deletions

View File

@ -48,6 +48,16 @@ options:
.
Specifying this option (any value) forces a reformat of any OSD devices
found which are not already mounted.
ignore-device-errors:
type: boolean
default: False
description: |
By default, the charm will raise errors if a whitelisted device is found,
but for some reason the charm is unable to initialize the device for use
by Ceph.
.
Setting this option to 'True' will result in the charm classifying such
problems as warnings only and will not result in a hook error.
ephemeral-unmount:
type: string
description: |

View File

@ -18,7 +18,7 @@ from charmhelpers.core.host import (
)
from charmhelpers.core.hookenv import (
log,
ERROR,
ERROR, WARNING
)
from charmhelpers.contrib.storage.linux.utils import (
zap_disk,
@ -307,14 +307,16 @@ def update_monfs():
pass
def osdize(dev, osd_format, osd_journal, reformat_osd=False):
def osdize(dev, osd_format, osd_journal, reformat_osd=False,
ignore_errors=False):
if dev.startswith('/dev'):
osdize_dev(dev, osd_format, osd_journal, reformat_osd)
osdize_dev(dev, osd_format, osd_journal, reformat_osd, ignore_errors)
else:
osdize_dir(dev)
def osdize_dev(dev, osd_format, osd_journal, reformat_osd=False):
def osdize_dev(dev, osd_format, osd_journal, reformat_osd=False,
ignore_errors=False):
if not os.path.exists(dev):
log('Path {} does not exist - bailing'.format(dev))
return
@ -349,7 +351,14 @@ def osdize_dev(dev, osd_format, osd_journal, reformat_osd=False):
if reformat_osd:
zap_disk(dev)
subprocess.check_call(cmd)
try:
subprocess.check_call(cmd)
except subprocess.CalledProcessError as e:
if ignore_errors:
log('Enable to initialize device: {}'.format(dev), WARNING)
else:
log('Enable to initialize device: {}'.format(dev), ERROR)
raise e
def osdize_dir(path):

View File

@ -111,7 +111,8 @@ def config_changed():
emit_cephconf()
for dev in get_devices():
ceph.osdize(dev, config('osd-format'),
config('osd-journal'), config('osd-reformat'))
config('osd-journal'), config('osd-reformat'),
config('ignore-device-errors'))
ceph.start_osds(get_devices())
@ -172,7 +173,8 @@ def mon_relation():
ceph.import_osd_bootstrap_key(bootstrap_key)
for dev in get_devices():
ceph.osdize(dev, config('osd-format'),
config('osd-journal'), config('osd-reformat'))
config('osd-journal'), config('osd-reformat'),
config('ignore-device-errors'))
ceph.start_osds(get_devices())
else:
log('mon cluster has not yet provided conf')