Merge lp:~heut2008/charms/trusty/ceph-radosgw/auth_protocol into lp:~openstack-charmers-archive/charms/trusty/ceph-radosgw/trunk

Proposed by Yaguang Tang
Status: Superseded
Proposed branch: lp:~heut2008/charms/trusty/ceph-radosgw/auth_protocol
Merge into: lp:~openstack-charmers-archive/charms/trusty/ceph-radosgw/trunk
Diff against target: 392 lines (+169/-46) (has conflicts)
8 files modified
hooks/ceph.py (+0/-15)
hooks/charmhelpers/contrib/storage/linux/utils.py (+1/-0)
hooks/charmhelpers/core/fstab.py (+116/-0)
hooks/charmhelpers/core/hookenv.py (+5/-4)
hooks/charmhelpers/core/host.py (+8/-6)
hooks/charmhelpers/fetch/__init__.py (+33/-16)
hooks/hooks.py (+5/-4)
templates/ceph.conf (+1/-1)
Conflict adding file hooks/charmhelpers/core/fstab.py.  Moved existing file to hooks/charmhelpers/core/fstab.py.moved.
To merge this branch: bzr merge lp:~heut2008/charms/trusty/ceph-radosgw/auth_protocol
Reviewer Review Type Date Requested Status
OpenStack Charmers Pending
Review via email: mp+232538@code.launchpad.net

This proposal has been superseded by a proposal from 2014-08-28.

To post a comment you must log in.

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'hooks/ceph.py'
2--- hooks/ceph.py 2014-01-24 16:04:49 +0000
3+++ hooks/ceph.py 2014-08-28 10:55:53 +0000
4@@ -11,7 +11,6 @@
5 import subprocess
6 import time
7 import os
8-import apt_pkg as apt
9
10 from socket import gethostname as get_unit_hostname
11
12@@ -220,17 +219,3 @@
13 if 'key' in element:
14 key = element.split(' = ')[1].strip() # IGNORE:E1103
15 return key
16-
17-
18-def get_ceph_version(package=None):
19- apt.init()
20- cache = apt.Cache()
21- pkg = cache[package or 'ceph']
22- if pkg.current_ver:
23- return apt.upstream_version(pkg.current_ver.ver_str)
24- else:
25- return None
26-
27-
28-def version_compare(a, b):
29- return apt.version_compare(a, b)
30
31=== modified file 'hooks/charmhelpers/contrib/storage/linux/utils.py'
32--- hooks/charmhelpers/contrib/storage/linux/utils.py 2014-05-19 11:37:27 +0000
33+++ hooks/charmhelpers/contrib/storage/linux/utils.py 2014-08-28 10:55:53 +0000
34@@ -37,6 +37,7 @@
35 check_call(['dd', 'if=/dev/zero', 'of=%s' % (block_device),
36 'bs=512', 'count=100', 'seek=%s' % (gpt_end)])
37
38+
39 def is_device_mounted(device):
40 '''Given a device path, return True if that device is mounted, and False
41 if it isn't.
42
43=== added file 'hooks/charmhelpers/core/fstab.py'
44--- hooks/charmhelpers/core/fstab.py 1970-01-01 00:00:00 +0000
45+++ hooks/charmhelpers/core/fstab.py 2014-08-28 10:55:53 +0000
46@@ -0,0 +1,116 @@
47+#!/usr/bin/env python
48+# -*- coding: utf-8 -*-
49+
50+__author__ = 'Jorge Niedbalski R. <jorge.niedbalski@canonical.com>'
51+
52+import os
53+
54+
55+class Fstab(file):
56+ """This class extends file in order to implement a file reader/writer
57+ for file `/etc/fstab`
58+ """
59+
60+ class Entry(object):
61+ """Entry class represents a non-comment line on the `/etc/fstab` file
62+ """
63+ def __init__(self, device, mountpoint, filesystem,
64+ options, d=0, p=0):
65+ self.device = device
66+ self.mountpoint = mountpoint
67+ self.filesystem = filesystem
68+
69+ if not options:
70+ options = "defaults"
71+
72+ self.options = options
73+ self.d = d
74+ self.p = p
75+
76+ def __eq__(self, o):
77+ return str(self) == str(o)
78+
79+ def __str__(self):
80+ return "{} {} {} {} {} {}".format(self.device,
81+ self.mountpoint,
82+ self.filesystem,
83+ self.options,
84+ self.d,
85+ self.p)
86+
87+ DEFAULT_PATH = os.path.join(os.path.sep, 'etc', 'fstab')
88+
89+ def __init__(self, path=None):
90+ if path:
91+ self._path = path
92+ else:
93+ self._path = self.DEFAULT_PATH
94+ file.__init__(self, self._path, 'r+')
95+
96+ def _hydrate_entry(self, line):
97+ # NOTE: use split with no arguments to split on any
98+ # whitespace including tabs
99+ return Fstab.Entry(*filter(
100+ lambda x: x not in ('', None),
101+ line.strip("\n").split()))
102+
103+ @property
104+ def entries(self):
105+ self.seek(0)
106+ for line in self.readlines():
107+ try:
108+ if not line.startswith("#"):
109+ yield self._hydrate_entry(line)
110+ except ValueError:
111+ pass
112+
113+ def get_entry_by_attr(self, attr, value):
114+ for entry in self.entries:
115+ e_attr = getattr(entry, attr)
116+ if e_attr == value:
117+ return entry
118+ return None
119+
120+ def add_entry(self, entry):
121+ if self.get_entry_by_attr('device', entry.device):
122+ return False
123+
124+ self.write(str(entry) + '\n')
125+ self.truncate()
126+ return entry
127+
128+ def remove_entry(self, entry):
129+ self.seek(0)
130+
131+ lines = self.readlines()
132+
133+ found = False
134+ for index, line in enumerate(lines):
135+ if not line.startswith("#"):
136+ if self._hydrate_entry(line) == entry:
137+ found = True
138+ break
139+
140+ if not found:
141+ return False
142+
143+ lines.remove(line)
144+
145+ self.seek(0)
146+ self.write(''.join(lines))
147+ self.truncate()
148+ return True
149+
150+ @classmethod
151+ def remove_by_mountpoint(cls, mountpoint, path=None):
152+ fstab = cls(path=path)
153+ entry = fstab.get_entry_by_attr('mountpoint', mountpoint)
154+ if entry:
155+ return fstab.remove_entry(entry)
156+ return False
157+
158+ @classmethod
159+ def add(cls, device, mountpoint, filesystem, options=None, path=None):
160+ return cls(path=path).add_entry(Fstab.Entry(device,
161+ mountpoint, filesystem,
162+ options=options))
163
164=== renamed file 'hooks/charmhelpers/core/fstab.py' => 'hooks/charmhelpers/core/fstab.py.moved'
165=== modified file 'hooks/charmhelpers/core/hookenv.py'
166--- hooks/charmhelpers/core/hookenv.py 2014-05-19 11:37:27 +0000
167+++ hooks/charmhelpers/core/hookenv.py 2014-08-28 10:55:53 +0000
168@@ -25,7 +25,7 @@
169 def cached(func):
170 """Cache return values for multiple executions of func + args
171
172- For example:
173+ For example::
174
175 @cached
176 def unit_get(attribute):
177@@ -445,18 +445,19 @@
178 class Hooks(object):
179 """A convenient handler for hook functions.
180
181- Example:
182+ Example::
183+
184 hooks = Hooks()
185
186 # register a hook, taking its name from the function name
187 @hooks.hook()
188 def install():
189- ...
190+ pass # your code here
191
192 # register a hook, providing a custom hook name
193 @hooks.hook("config-changed")
194 def config_changed():
195- ...
196+ pass # your code here
197
198 if __name__ == "__main__":
199 # execute a hook based on the name the program is called by
200
201=== modified file 'hooks/charmhelpers/core/host.py'
202--- hooks/charmhelpers/core/host.py 2014-07-24 10:00:43 +0000
203+++ hooks/charmhelpers/core/host.py 2014-08-28 10:55:53 +0000
204@@ -12,7 +12,6 @@
205 import string
206 import subprocess
207 import hashlib
208-import apt_pkg
209
210 from collections import OrderedDict
211
212@@ -212,13 +211,13 @@
213 def restart_on_change(restart_map, stopstart=False):
214 """Restart services based on configuration files changing
215
216- This function is used a decorator, for example
217+ This function is used a decorator, for example::
218
219 @restart_on_change({
220 '/etc/ceph/ceph.conf': [ 'cinder-api', 'cinder-volume' ]
221 })
222 def ceph_client_changed():
223- ...
224+ pass # your code here
225
226 In this example, the cinder-api and cinder-volume services
227 would be restarted if /etc/ceph/ceph.conf is changed by the
228@@ -314,10 +313,13 @@
229
230 def cmp_pkgrevno(package, revno, pkgcache=None):
231 '''Compare supplied revno with the revno of the installed package
232- 1 => Installed revno is greater than supplied arg
233- 0 => Installed revno is the same as supplied arg
234- -1 => Installed revno is less than supplied arg
235+
236+ * 1 => Installed revno is greater than supplied arg
237+ * 0 => Installed revno is the same as supplied arg
238+ * -1 => Installed revno is less than supplied arg
239+
240 '''
241+ import apt_pkg
242 if not pkgcache:
243 apt_pkg.init()
244 # Force Apt to build its cache in memory. That way we avoid race
245
246=== modified file 'hooks/charmhelpers/fetch/__init__.py'
247--- hooks/charmhelpers/fetch/__init__.py 2014-05-19 11:37:27 +0000
248+++ hooks/charmhelpers/fetch/__init__.py 2014-08-28 10:55:53 +0000
249@@ -13,7 +13,6 @@
250 config,
251 log,
252 )
253-import apt_pkg
254 import os
255
256
257@@ -56,6 +55,15 @@
258 'icehouse/proposed': 'precise-proposed/icehouse',
259 'precise-icehouse/proposed': 'precise-proposed/icehouse',
260 'precise-proposed/icehouse': 'precise-proposed/icehouse',
261+ # Juno
262+ 'juno': 'trusty-updates/juno',
263+ 'trusty-juno': 'trusty-updates/juno',
264+ 'trusty-juno/updates': 'trusty-updates/juno',
265+ 'trusty-updates/juno': 'trusty-updates/juno',
266+ 'juno/proposed': 'trusty-proposed/juno',
267+ 'juno/proposed': 'trusty-proposed/juno',
268+ 'trusty-juno/proposed': 'trusty-proposed/juno',
269+ 'trusty-proposed/juno': 'trusty-proposed/juno',
270 }
271
272 # The order of this list is very important. Handlers should be listed in from
273@@ -108,6 +116,7 @@
274
275 def filter_installed_packages(packages):
276 """Returns a list of packages that require installation"""
277+ import apt_pkg
278 apt_pkg.init()
279
280 # Tell apt to build an in-memory cache to prevent race conditions (if
281@@ -226,31 +235,39 @@
282 sources_var='install_sources',
283 keys_var='install_keys'):
284 """
285- Configure multiple sources from charm configuration
286+ Configure multiple sources from charm configuration.
287+
288+ The lists are encoded as yaml fragments in the configuration.
289+ The frament needs to be included as a string.
290
291 Example config:
292- install_sources:
293+ install_sources: |
294 - "ppa:foo"
295 - "http://example.com/repo precise main"
296- install_keys:
297+ install_keys: |
298 - null
299 - "a1b2c3d4"
300
301 Note that 'null' (a.k.a. None) should not be quoted.
302 """
303- sources = safe_load(config(sources_var))
304- keys = config(keys_var)
305- if keys is not None:
306- keys = safe_load(keys)
307- if isinstance(sources, basestring) and (
308- keys is None or isinstance(keys, basestring)):
309- add_source(sources, keys)
310+ sources = safe_load((config(sources_var) or '').strip()) or []
311+ keys = safe_load((config(keys_var) or '').strip()) or None
312+
313+ if isinstance(sources, basestring):
314+ sources = [sources]
315+
316+ if keys is None:
317+ for source in sources:
318+ add_source(source, None)
319 else:
320- if not len(sources) == len(keys):
321- msg = 'Install sources and keys lists are different lengths'
322- raise SourceConfigError(msg)
323- for src_num in range(len(sources)):
324- add_source(sources[src_num], keys[src_num])
325+ if isinstance(keys, basestring):
326+ keys = [keys]
327+
328+ if len(sources) != len(keys):
329+ raise SourceConfigError(
330+ 'Install sources and keys lists are different lengths')
331+ for source, key in zip(sources, keys):
332+ add_source(source, key)
333 if update:
334 apt_update(fatal=True)
335
336
337=== modified file 'hooks/hooks.py'
338--- hooks/hooks.py 2014-03-25 18:44:22 +0000
339+++ hooks/hooks.py 2014-08-28 10:55:53 +0000
340@@ -38,6 +38,7 @@
341 )
342
343 from charmhelpers.payload.execd import execd_preinstall
344+from charmhelpers.core.host import cmp_pkgrevno
345 from socket import gethostname as get_unit_hostname
346
347 hooks = Hooks()
348@@ -73,13 +74,13 @@
349 'auth_supported': get_auth() or 'none',
350 'mon_hosts': ' '.join(get_mon_hosts()),
351 'hostname': get_unit_hostname(),
352- 'version': ceph.get_ceph_version('radosgw'),
353+ 'old_auth': cmp_pkgrevno('radosgw', "0.51") < 0,
354 'use_syslog': str(config('use-syslog')).lower()
355 }
356
357 # Check to ensure that correct version of ceph is
358 # in use
359- if ceph.get_ceph_version('radosgw') >= "0.55":
360+ if cmp_pkgrevno('radosgw', '0.55') >= 0:
361 # Add keystone configuration if found
362 ks_conf = get_keystone_conf()
363 if ks_conf:
364@@ -161,7 +162,7 @@
365 for unit in related_units(relid):
366 ks_auth = {
367 'auth_type': 'keystone',
368- 'auth_protocol': 'http',
369+ 'auth_protocol': relation_get('auth_protocol', unit, relid),
370 'auth_host': relation_get('auth_host', unit, relid),
371 'auth_port': relation_get('auth_port', unit, relid),
372 'admin_token': relation_get('admin_token', unit, relid),
373@@ -208,7 +209,7 @@
374
375 @hooks.hook('identity-service-relation-joined')
376 def identity_joined(relid=None):
377- if ceph.get_ceph_version('radosgw') < "0.55":
378+ if cmp_pkgrevno('radosgw', '0.55') < 0:
379 log('Integration with keystone requires ceph >= 0.55')
380 sys.exit(1)
381
382
383=== modified file 'templates/ceph.conf'
384--- templates/ceph.conf 2014-03-25 18:44:22 +0000
385+++ templates/ceph.conf 2014-08-28 10:55:53 +0000
386@@ -1,5 +1,5 @@
387 [global]
388-{% if version < "0.51" %}
389+{% if old_auth %}
390 auth supported = {{ auth_supported }}
391 {% else %}
392 auth cluster required = {{ auth_supported }}

Subscribers

People subscribed via source and target branches