From 7e2ef1d0eaacb7604a8c70173035f02508897604 Mon Sep 17 00:00:00 2001 From: Chris MacNaughton Date: Thu, 7 Apr 2016 08:43:19 -0400 Subject: [PATCH] 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 --- config.yaml | 3 ++- hooks/add-storage | 7 +++++++ hooks/ceph_hooks.py | 30 +++++++++++++++++++++-------- hooks/osd-devices-storage-attached | 1 + hooks/osd-devices-storage-detaching | 1 + hooks/storage.real | 1 + metadata.yaml | 9 +++++++++ 7 files changed, 43 insertions(+), 9 deletions(-) create mode 100755 hooks/add-storage create mode 120000 hooks/osd-devices-storage-attached create mode 120000 hooks/osd-devices-storage-detaching create mode 120000 hooks/storage.real diff --git a/config.yaml b/config.yaml index b15628ac..2506d9c7 100644 --- a/config.yaml +++ b/config.yaml @@ -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. diff --git a/hooks/add-storage b/hooks/add-storage new file mode 100755 index 00000000..5b02c170 --- /dev/null +++ b/hooks/add-storage @@ -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 \ No newline at end of file diff --git a/hooks/ceph_hooks.py b/hooks/ceph_hooks.py index e508e0e6..6b846109 100755 --- a/hooks/ceph_hooks.py +++ b/hooks/ceph_hooks.py @@ -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', diff --git a/hooks/osd-devices-storage-attached b/hooks/osd-devices-storage-attached new file mode 120000 index 00000000..68134a91 --- /dev/null +++ b/hooks/osd-devices-storage-attached @@ -0,0 +1 @@ +add-storage \ No newline at end of file diff --git a/hooks/osd-devices-storage-detaching b/hooks/osd-devices-storage-detaching new file mode 120000 index 00000000..68134a91 --- /dev/null +++ b/hooks/osd-devices-storage-detaching @@ -0,0 +1 @@ +add-storage \ No newline at end of file diff --git a/hooks/storage.real b/hooks/storage.real new file mode 120000 index 00000000..52d96630 --- /dev/null +++ b/hooks/storage.real @@ -0,0 +1 @@ +ceph_hooks.py \ No newline at end of file diff --git a/metadata.yaml b/metadata.yaml index dad778db..01a2aa64 100644 --- a/metadata.yaml +++ b/metadata.yaml @@ -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- \ No newline at end of file