Merge lp:~james-page/charms/precise/ceph-osd/dir-support into lp:~charmers/charms/precise/ceph-osd/trunk

Proposed by James Page
Status: Merged
Approved by: Mark Mims
Approved revision: 21
Merge reported by: Mark Mims
Merged at revision: not available
Proposed branch: lp:~james-page/charms/precise/ceph-osd/dir-support
Merge into: lp:~charmers/charms/precise/ceph-osd/trunk
Diff against target: 207 lines (+88/-22)
4 files modified
config.yaml (+3/-0)
hooks/ceph.py (+73/-17)
hooks/hooks.py (+11/-4)
revision (+1/-1)
To merge this branch: bzr merge lp:~james-page/charms/precise/ceph-osd/dir-support
Reviewer Review Type Date Requested Status
Mark Mims (community) Approve
Review via email: mp+182608@code.launchpad.net

Description of the change

This update add support for using directories to host ceph OSD's; allowing
use with the Juju local provider.

To post a comment you must log in.
Revision history for this message
Mark Mims (mark-mims) wrote :

lgtm

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'config.yaml'
2--- config.yaml 2013-06-10 13:48:23 +0000
3+++ config.yaml 2013-08-28 11:44:29 +0000
4@@ -7,6 +7,9 @@
5 .
6 These devices are the range of devices that will be checked for and
7 used across all service units.
8+ .
9+ For ceph >= 0.56.6 these can also be directories instead of devices - the
10+ charm assumes anything not starting with /dev is a directory instead.
11 osd-journal:
12 type: string
13 description: |
14
15=== modified file 'hooks/ceph.py'
16--- hooks/ceph.py 2013-07-08 08:33:02 +0000
17+++ hooks/ceph.py 2013-08-28 11:44:29 +0000
18@@ -15,14 +15,17 @@
19 from charmhelpers.core.host import (
20 mkdir,
21 service_restart,
22- log
23+)
24+from charmhelpers.core.hookenv import (
25+ log,
26+ ERROR,
27 )
28 from charmhelpers.contrib.storage.linux.utils import (
29 zap_disk,
30- is_block_device
31+ is_block_device,
32 )
33 from utils import (
34- get_unit_hostname
35+ get_unit_hostname,
36 )
37
38 LEADER = 'leader'
39@@ -119,6 +122,16 @@
40 return False
41
42
43+def start_osds(devices):
44+ # Scan for ceph block devices
45+ rescan_osd_devices()
46+ if get_ceph_version() >= "0.56.6":
47+ # Use ceph-disk-activate for directory based OSD's
48+ for dev_or_path in devices:
49+ if os.path.exists(dev_or_path) and os.path.isdir(dev_or_path):
50+ subprocess.check_call(['ceph-disk-activate', dev_or_path])
51+
52+
53 def rescan_osd_devices():
54 cmd = [
55 'udevadm', 'trigger',
56@@ -161,9 +174,38 @@
57 ]
58 }
59
60+_osd_bootstrap_caps_profile = {
61+ 'mon': [
62+ 'allow profile bootstrap-osd'
63+ ]
64+}
65+
66+
67+def parse_key(raw_key):
68+ # get-or-create appears to have different output depending
69+ # on whether its 'get' or 'create'
70+ # 'create' just returns the key, 'get' is more verbose and
71+ # needs parsing
72+ key = None
73+ if len(raw_key.splitlines()) == 1:
74+ key = raw_key
75+ else:
76+ for element in raw_key.splitlines():
77+ if 'key' in element:
78+ key = element.split(' = ')[1].strip() # IGNORE:E1103
79+ return key
80+
81
82 def get_osd_bootstrap_key():
83- return get_named_key('bootstrap-osd', _osd_bootstrap_caps)
84+ try:
85+ # Attempt to get/create a key using the OSD bootstrap profile first
86+ key = get_named_key('bootstrap-osd',
87+ _osd_bootstrap_caps_profile)
88+ except:
89+ # If that fails try with the older style permissions
90+ key = get_named_key('bootstrap-osd',
91+ _osd_bootstrap_caps)
92+ return key
93
94
95 _radosgw_keyring = "/etc/ceph/keyring.rados.gateway"
96@@ -214,19 +256,7 @@
97 subsystem,
98 '; '.join(subcaps),
99 ])
100- output = subprocess.check_output(cmd).strip() # IGNORE:E1103
101- # get-or-create appears to have different output depending
102- # on whether its 'get' or 'create'
103- # 'create' just returns the key, 'get' is more verbose and
104- # needs parsing
105- key = None
106- if len(output.splitlines()) == 1:
107- key = output
108- else:
109- for element in output.splitlines():
110- if 'key' in element:
111- key = element.split(' = ')[1].strip() # IGNORE:E1103
112- return key
113+ return parse_key(subprocess.check_output(cmd).strip()) # IGNORE:E1103
114
115
116 def bootstrap_monitor_cluster(secret):
117@@ -291,6 +321,13 @@
118
119
120 def osdize(dev, osd_format, osd_journal, reformat_osd=False):
121+ if dev.startswith('/dev'):
122+ osdize_dev(dev, osd_format, osd_journal, reformat_osd)
123+ else:
124+ osdize_dir(dev)
125+
126+
127+def osdize_dev(dev, osd_format, osd_journal, reformat_osd=False):
128 if not os.path.exists(dev):
129 log('Path {} does not exist - bailing'.format(dev))
130 return
131@@ -327,6 +364,25 @@
132 subprocess.check_call(cmd)
133
134
135+def osdize_dir(path):
136+ if os.path.exists(os.path.join(path, 'upstart')):
137+ log('Path {} is already configured as an OSD - bailing'.format(path))
138+ return
139+
140+ if get_ceph_version() < "0.56.6":
141+ log('Unable to use directories for OSDs with ceph < 0.56.6',
142+ level=ERROR)
143+ raise
144+
145+ mkdir(path)
146+ cmd = [
147+ 'ceph-disk-prepare',
148+ '--data-dir',
149+ path
150+ ]
151+ subprocess.check_call(cmd)
152+
153+
154 def device_mounted(dev):
155 return subprocess.call(['grep', '-wqs', dev + '1', '/proc/mounts']) == 0
156
157
158=== modified file 'hooks/hooks.py'
159--- hooks/hooks.py 2013-07-03 09:04:42 +0000
160+++ hooks/hooks.py 2013-08-28 11:44:29 +0000
161@@ -96,10 +96,10 @@
162 if ceph.is_bootstrapped():
163 log('ceph bootstrapped, rescanning disks')
164 emit_cephconf()
165- for dev in config('osd-devices').split(' '):
166+ for dev in get_devices():
167 ceph.osdize(dev, config('osd-format'),
168 config('osd-journal'), config('osd-reformat'))
169- ceph.rescan_osd_devices()
170+ ceph.start_osds(get_devices())
171
172 log('End config-changed hook.')
173
174@@ -142,6 +142,13 @@
175 return False
176
177
178+def get_devices():
179+ if config('osd-devices'):
180+ return config('osd-devices').split(' ')
181+ else:
182+ return []
183+
184+
185 @hooks.hook('mon-relation-changed',
186 'mon-relation-departed')
187 def mon_relation():
188@@ -152,10 +159,10 @@
189 log('mon has provided conf- scanning disks')
190 emit_cephconf()
191 ceph.import_osd_bootstrap_key(bootstrap_key)
192- for dev in config('osd-devices').split(' '):
193+ for dev in get_devices():
194 ceph.osdize(dev, config('osd-format'),
195 config('osd-journal'), config('osd-reformat'))
196- ceph.rescan_osd_devices()
197+ ceph.start_osds(get_devices())
198 else:
199 log('mon cluster has not yet provided conf')
200
201
202=== modified file 'revision'
203--- revision 2012-11-12 10:00:51 +0000
204+++ revision 2013-08-28 11:44:29 +0000
205@@ -1,1 +1,1 @@
206-7
207+11

Subscribers

People subscribed via source and target branches