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
=== modified file 'hooks/ceph.py'
--- hooks/ceph.py 2014-01-24 16:04:49 +0000
+++ hooks/ceph.py 2014-08-28 10:55:53 +0000
@@ -11,7 +11,6 @@
11import subprocess11import subprocess
12import time12import time
13import os13import os
14import apt_pkg as apt
1514
16from socket import gethostname as get_unit_hostname15from socket import gethostname as get_unit_hostname
1716
@@ -220,17 +219,3 @@
220 if 'key' in element:219 if 'key' in element:
221 key = element.split(' = ')[1].strip() # IGNORE:E1103220 key = element.split(' = ')[1].strip() # IGNORE:E1103
222 return key221 return key
223
224
225def get_ceph_version(package=None):
226 apt.init()
227 cache = apt.Cache()
228 pkg = cache[package or 'ceph']
229 if pkg.current_ver:
230 return apt.upstream_version(pkg.current_ver.ver_str)
231 else:
232 return None
233
234
235def version_compare(a, b):
236 return apt.version_compare(a, b)
237222
=== modified file 'hooks/charmhelpers/contrib/storage/linux/utils.py'
--- hooks/charmhelpers/contrib/storage/linux/utils.py 2014-05-19 11:37:27 +0000
+++ hooks/charmhelpers/contrib/storage/linux/utils.py 2014-08-28 10:55:53 +0000
@@ -37,6 +37,7 @@
37 check_call(['dd', 'if=/dev/zero', 'of=%s' % (block_device),37 check_call(['dd', 'if=/dev/zero', 'of=%s' % (block_device),
38 'bs=512', 'count=100', 'seek=%s' % (gpt_end)])38 'bs=512', 'count=100', 'seek=%s' % (gpt_end)])
3939
40
40def is_device_mounted(device):41def is_device_mounted(device):
41 '''Given a device path, return True if that device is mounted, and False42 '''Given a device path, return True if that device is mounted, and False
42 if it isn't.43 if it isn't.
4344
=== added file 'hooks/charmhelpers/core/fstab.py'
--- hooks/charmhelpers/core/fstab.py 1970-01-01 00:00:00 +0000
+++ hooks/charmhelpers/core/fstab.py 2014-08-28 10:55:53 +0000
@@ -0,0 +1,116 @@
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3
4__author__ = 'Jorge Niedbalski R. <jorge.niedbalski@canonical.com>'
5
6import os
7
8
9class Fstab(file):
10 """This class extends file in order to implement a file reader/writer
11 for file `/etc/fstab`
12 """
13
14 class Entry(object):
15 """Entry class represents a non-comment line on the `/etc/fstab` file
16 """
17 def __init__(self, device, mountpoint, filesystem,
18 options, d=0, p=0):
19 self.device = device
20 self.mountpoint = mountpoint
21 self.filesystem = filesystem
22
23 if not options:
24 options = "defaults"
25
26 self.options = options
27 self.d = d
28 self.p = p
29
30 def __eq__(self, o):
31 return str(self) == str(o)
32
33 def __str__(self):
34 return "{} {} {} {} {} {}".format(self.device,
35 self.mountpoint,
36 self.filesystem,
37 self.options,
38 self.d,
39 self.p)
40
41 DEFAULT_PATH = os.path.join(os.path.sep, 'etc', 'fstab')
42
43 def __init__(self, path=None):
44 if path:
45 self._path = path
46 else:
47 self._path = self.DEFAULT_PATH
48 file.__init__(self, self._path, 'r+')
49
50 def _hydrate_entry(self, line):
51 # NOTE: use split with no arguments to split on any
52 # whitespace including tabs
53 return Fstab.Entry(*filter(
54 lambda x: x not in ('', None),
55 line.strip("\n").split()))
56
57 @property
58 def entries(self):
59 self.seek(0)
60 for line in self.readlines():
61 try:
62 if not line.startswith("#"):
63 yield self._hydrate_entry(line)
64 except ValueError:
65 pass
66
67 def get_entry_by_attr(self, attr, value):
68 for entry in self.entries:
69 e_attr = getattr(entry, attr)
70 if e_attr == value:
71 return entry
72 return None
73
74 def add_entry(self, entry):
75 if self.get_entry_by_attr('device', entry.device):
76 return False
77
78 self.write(str(entry) + '\n')
79 self.truncate()
80 return entry
81
82 def remove_entry(self, entry):
83 self.seek(0)
84
85 lines = self.readlines()
86
87 found = False
88 for index, line in enumerate(lines):
89 if not line.startswith("#"):
90 if self._hydrate_entry(line) == entry:
91 found = True
92 break
93
94 if not found:
95 return False
96
97 lines.remove(line)
98
99 self.seek(0)
100 self.write(''.join(lines))
101 self.truncate()
102 return True
103
104 @classmethod
105 def remove_by_mountpoint(cls, mountpoint, path=None):
106 fstab = cls(path=path)
107 entry = fstab.get_entry_by_attr('mountpoint', mountpoint)
108 if entry:
109 return fstab.remove_entry(entry)
110 return False
111
112 @classmethod
113 def add(cls, device, mountpoint, filesystem, options=None, path=None):
114 return cls(path=path).add_entry(Fstab.Entry(device,
115 mountpoint, filesystem,
116 options=options))
0117
=== renamed file 'hooks/charmhelpers/core/fstab.py' => 'hooks/charmhelpers/core/fstab.py.moved'
=== modified file 'hooks/charmhelpers/core/hookenv.py'
--- hooks/charmhelpers/core/hookenv.py 2014-05-19 11:37:27 +0000
+++ hooks/charmhelpers/core/hookenv.py 2014-08-28 10:55:53 +0000
@@ -25,7 +25,7 @@
25def cached(func):25def cached(func):
26 """Cache return values for multiple executions of func + args26 """Cache return values for multiple executions of func + args
2727
28 For example:28 For example::
2929
30 @cached30 @cached
31 def unit_get(attribute):31 def unit_get(attribute):
@@ -445,18 +445,19 @@
445class Hooks(object):445class Hooks(object):
446 """A convenient handler for hook functions.446 """A convenient handler for hook functions.
447447
448 Example:448 Example::
449
449 hooks = Hooks()450 hooks = Hooks()
450451
451 # register a hook, taking its name from the function name452 # register a hook, taking its name from the function name
452 @hooks.hook()453 @hooks.hook()
453 def install():454 def install():
454 ...455 pass # your code here
455456
456 # register a hook, providing a custom hook name457 # register a hook, providing a custom hook name
457 @hooks.hook("config-changed")458 @hooks.hook("config-changed")
458 def config_changed():459 def config_changed():
459 ...460 pass # your code here
460461
461 if __name__ == "__main__":462 if __name__ == "__main__":
462 # execute a hook based on the name the program is called by463 # execute a hook based on the name the program is called by
463464
=== modified file 'hooks/charmhelpers/core/host.py'
--- hooks/charmhelpers/core/host.py 2014-07-24 10:00:43 +0000
+++ hooks/charmhelpers/core/host.py 2014-08-28 10:55:53 +0000
@@ -12,7 +12,6 @@
12import string12import string
13import subprocess13import subprocess
14import hashlib14import hashlib
15import apt_pkg
1615
17from collections import OrderedDict16from collections import OrderedDict
1817
@@ -212,13 +211,13 @@
212def restart_on_change(restart_map, stopstart=False):211def restart_on_change(restart_map, stopstart=False):
213 """Restart services based on configuration files changing212 """Restart services based on configuration files changing
214213
215 This function is used a decorator, for example214 This function is used a decorator, for example::
216215
217 @restart_on_change({216 @restart_on_change({
218 '/etc/ceph/ceph.conf': [ 'cinder-api', 'cinder-volume' ]217 '/etc/ceph/ceph.conf': [ 'cinder-api', 'cinder-volume' ]
219 })218 })
220 def ceph_client_changed():219 def ceph_client_changed():
221 ...220 pass # your code here
222221
223 In this example, the cinder-api and cinder-volume services222 In this example, the cinder-api and cinder-volume services
224 would be restarted if /etc/ceph/ceph.conf is changed by the223 would be restarted if /etc/ceph/ceph.conf is changed by the
@@ -314,10 +313,13 @@
314313
315def cmp_pkgrevno(package, revno, pkgcache=None):314def cmp_pkgrevno(package, revno, pkgcache=None):
316 '''Compare supplied revno with the revno of the installed package315 '''Compare supplied revno with the revno of the installed package
317 1 => Installed revno is greater than supplied arg316
318 0 => Installed revno is the same as supplied arg317 * 1 => Installed revno is greater than supplied arg
319 -1 => Installed revno is less than supplied arg318 * 0 => Installed revno is the same as supplied arg
319 * -1 => Installed revno is less than supplied arg
320
320 '''321 '''
322 import apt_pkg
321 if not pkgcache:323 if not pkgcache:
322 apt_pkg.init()324 apt_pkg.init()
323 # Force Apt to build its cache in memory. That way we avoid race325 # Force Apt to build its cache in memory. That way we avoid race
324326
=== modified file 'hooks/charmhelpers/fetch/__init__.py'
--- hooks/charmhelpers/fetch/__init__.py 2014-05-19 11:37:27 +0000
+++ hooks/charmhelpers/fetch/__init__.py 2014-08-28 10:55:53 +0000
@@ -13,7 +13,6 @@
13 config,13 config,
14 log,14 log,
15)15)
16import apt_pkg
17import os16import os
1817
1918
@@ -56,6 +55,15 @@
56 'icehouse/proposed': 'precise-proposed/icehouse',55 'icehouse/proposed': 'precise-proposed/icehouse',
57 'precise-icehouse/proposed': 'precise-proposed/icehouse',56 'precise-icehouse/proposed': 'precise-proposed/icehouse',
58 'precise-proposed/icehouse': 'precise-proposed/icehouse',57 'precise-proposed/icehouse': 'precise-proposed/icehouse',
58 # Juno
59 'juno': 'trusty-updates/juno',
60 'trusty-juno': 'trusty-updates/juno',
61 'trusty-juno/updates': 'trusty-updates/juno',
62 'trusty-updates/juno': 'trusty-updates/juno',
63 'juno/proposed': 'trusty-proposed/juno',
64 'juno/proposed': 'trusty-proposed/juno',
65 'trusty-juno/proposed': 'trusty-proposed/juno',
66 'trusty-proposed/juno': 'trusty-proposed/juno',
59}67}
6068
61# The order of this list is very important. Handlers should be listed in from69# The order of this list is very important. Handlers should be listed in from
@@ -108,6 +116,7 @@
108116
109def filter_installed_packages(packages):117def filter_installed_packages(packages):
110 """Returns a list of packages that require installation"""118 """Returns a list of packages that require installation"""
119 import apt_pkg
111 apt_pkg.init()120 apt_pkg.init()
112121
113 # Tell apt to build an in-memory cache to prevent race conditions (if122 # Tell apt to build an in-memory cache to prevent race conditions (if
@@ -226,31 +235,39 @@
226 sources_var='install_sources',235 sources_var='install_sources',
227 keys_var='install_keys'):236 keys_var='install_keys'):
228 """237 """
229 Configure multiple sources from charm configuration238 Configure multiple sources from charm configuration.
239
240 The lists are encoded as yaml fragments in the configuration.
241 The frament needs to be included as a string.
230242
231 Example config:243 Example config:
232 install_sources:244 install_sources: |
233 - "ppa:foo"245 - "ppa:foo"
234 - "http://example.com/repo precise main"246 - "http://example.com/repo precise main"
235 install_keys:247 install_keys: |
236 - null248 - null
237 - "a1b2c3d4"249 - "a1b2c3d4"
238250
239 Note that 'null' (a.k.a. None) should not be quoted.251 Note that 'null' (a.k.a. None) should not be quoted.
240 """252 """
241 sources = safe_load(config(sources_var))253 sources = safe_load((config(sources_var) or '').strip()) or []
242 keys = config(keys_var)254 keys = safe_load((config(keys_var) or '').strip()) or None
243 if keys is not None:255
244 keys = safe_load(keys)256 if isinstance(sources, basestring):
245 if isinstance(sources, basestring) and (257 sources = [sources]
246 keys is None or isinstance(keys, basestring)):258
247 add_source(sources, keys)259 if keys is None:
260 for source in sources:
261 add_source(source, None)
248 else:262 else:
249 if not len(sources) == len(keys):263 if isinstance(keys, basestring):
250 msg = 'Install sources and keys lists are different lengths'264 keys = [keys]
251 raise SourceConfigError(msg)265
252 for src_num in range(len(sources)):266 if len(sources) != len(keys):
253 add_source(sources[src_num], keys[src_num])267 raise SourceConfigError(
268 'Install sources and keys lists are different lengths')
269 for source, key in zip(sources, keys):
270 add_source(source, key)
254 if update:271 if update:
255 apt_update(fatal=True)272 apt_update(fatal=True)
256273
257274
=== modified file 'hooks/hooks.py'
--- hooks/hooks.py 2014-03-25 18:44:22 +0000
+++ hooks/hooks.py 2014-08-28 10:55:53 +0000
@@ -38,6 +38,7 @@
38)38)
3939
40from charmhelpers.payload.execd import execd_preinstall40from charmhelpers.payload.execd import execd_preinstall
41from charmhelpers.core.host import cmp_pkgrevno
41from socket import gethostname as get_unit_hostname42from socket import gethostname as get_unit_hostname
4243
43hooks = Hooks()44hooks = Hooks()
@@ -73,13 +74,13 @@
73 'auth_supported': get_auth() or 'none',74 'auth_supported': get_auth() or 'none',
74 'mon_hosts': ' '.join(get_mon_hosts()),75 'mon_hosts': ' '.join(get_mon_hosts()),
75 'hostname': get_unit_hostname(),76 'hostname': get_unit_hostname(),
76 'version': ceph.get_ceph_version('radosgw'),77 'old_auth': cmp_pkgrevno('radosgw', "0.51") < 0,
77 'use_syslog': str(config('use-syslog')).lower()78 'use_syslog': str(config('use-syslog')).lower()
78 }79 }
7980
80 # Check to ensure that correct version of ceph is81 # Check to ensure that correct version of ceph is
81 # in use82 # in use
82 if ceph.get_ceph_version('radosgw') >= "0.55":83 if cmp_pkgrevno('radosgw', '0.55') >= 0:
83 # Add keystone configuration if found84 # Add keystone configuration if found
84 ks_conf = get_keystone_conf()85 ks_conf = get_keystone_conf()
85 if ks_conf:86 if ks_conf:
@@ -161,7 +162,7 @@
161 for unit in related_units(relid):162 for unit in related_units(relid):
162 ks_auth = {163 ks_auth = {
163 'auth_type': 'keystone',164 'auth_type': 'keystone',
164 'auth_protocol': 'http',165 'auth_protocol': relation_get('auth_protocol', unit, relid),
165 'auth_host': relation_get('auth_host', unit, relid),166 'auth_host': relation_get('auth_host', unit, relid),
166 'auth_port': relation_get('auth_port', unit, relid),167 'auth_port': relation_get('auth_port', unit, relid),
167 'admin_token': relation_get('admin_token', unit, relid),168 'admin_token': relation_get('admin_token', unit, relid),
@@ -208,7 +209,7 @@
208209
209@hooks.hook('identity-service-relation-joined')210@hooks.hook('identity-service-relation-joined')
210def identity_joined(relid=None):211def identity_joined(relid=None):
211 if ceph.get_ceph_version('radosgw') < "0.55":212 if cmp_pkgrevno('radosgw', '0.55') < 0:
212 log('Integration with keystone requires ceph >= 0.55')213 log('Integration with keystone requires ceph >= 0.55')
213 sys.exit(1)214 sys.exit(1)
214215
215216
=== modified file 'templates/ceph.conf'
--- templates/ceph.conf 2014-03-25 18:44:22 +0000
+++ templates/ceph.conf 2014-08-28 10:55:53 +0000
@@ -1,5 +1,5 @@
1[global]1[global]
2{% if version < "0.51" %}2{% if old_auth %}
3 auth supported = {{ auth_supported }}3 auth supported = {{ auth_supported }}
4{% else %}4{% else %}
5 auth cluster required = {{ auth_supported }}5 auth cluster required = {{ auth_supported }}

Subscribers

People subscribed via source and target branches