Add support for Storage hooks

This adds support for Juju's storage hooks by merging the config
provided osd-devices with Juju storage provided osd-devices, in the
same way that the existing Ceph charm handles them.

In addition to providing support for ceph-osds via Juju storage,
we provide support for multiple journal devices through Juju storage
as well.

We have to add a shim hook to ensure that Ceph is installed prior
to storage hook invocation because storage attached at deploy time
will execute hooks before the install hook

Change-Id: Idad46e8f4cc32e09fbd64d29cd93745662e9f542
This commit is contained in:
Chris MacNaughton 2016-04-07 08:43:19 -04:00
parent 72b8ecade3
commit 7e2ef1d0ea
7 changed files with 43 additions and 9 deletions

View File

@ -10,7 +10,8 @@ options:
The devices to format and set up as osd volumes.
These devices are the range of devices that will be checked for and
used across all service units.
used across all service units, in addition to any volumes attached
via the --storage flag during deployment.
For ceph >= 0.56.6 these can also be directories instead of devices - the
charm assumes anything not starting with /dev is a directory instead.

7
hooks/add-storage Executable file
View File

@ -0,0 +1,7 @@
#!/bin/bash
# Wrapper to deal with newer Ubuntu versions that don't have py2 installed
# by default.
dpkg -l|grep 'python-apt ' || exit 0
exec ./hooks/storage.real

View File

@ -31,6 +31,8 @@ from charmhelpers.core.hookenv import (
UnregisteredHookError,
service_name,
status_set,
storage_get,
storage_list,
)
from charmhelpers.core.host import (
umount,
@ -379,6 +381,7 @@ def config_changed():
prepare_disks_and_activate()
@hooks.hook('storage.real')
def prepare_disks_and_activate():
osd_journal = get_journal_devices()
check_overlap(osd_journal, set(get_devices()))
@ -447,20 +450,31 @@ def reformat_osd():
def get_devices():
if config('osd-devices'):
return [
devices = [
os.path.realpath(path)
for path in config('osd-devices').split(' ')]
else:
return []
devices = []
# List storage instances for the 'osd-devices'
# store declared for this charm too, and add
# their block device paths to the list.
storage_ids = storage_list('osd-devices')
devices.extend((storage_get('location', s) for s in storage_ids))
return devices
def get_journal_devices():
osd_journal = config('osd-journal')
if not osd_journal:
return set()
osd_journal = [l.strip() for l in config('osd-journal').split(' ')]
osd_journal = set(filter(os.path.exists, osd_journal))
return osd_journal
if config('osd-journal'):
devices = config('osd-journal')
devices = [l.strip() for l in config('osd-journal').split(' ')]
else:
devices = []
storage_ids = storage_list('osd-journals')
devices.extend((storage_get('location', s) for s in storage_ids))
devices = filter(os.path.exists, devices)
return set(devices)
@hooks.hook('mon-relation-changed',

View File

@ -0,0 +1 @@
add-storage

View File

@ -0,0 +1 @@
add-storage

1
hooks/storage.real Symbolic link
View File

@ -0,0 +1 @@
ceph_hooks.py

View File

@ -19,3 +19,12 @@ description: |
requires:
mon:
interface: ceph-osd
storage:
osd-devices:
type: block
multiple:
range: 0-
osd-journals:
type: block
multiple:
range: 0-