Merge lp:~hopem/charms/precise/rabbitmq-server/lp1281753 into lp:charms/rabbitmq-server

Proposed by Edward Hope-Morley
Status: Superseded
Proposed branch: lp:~hopem/charms/precise/rabbitmq-server/lp1281753
Merge into: lp:charms/rabbitmq-server
Diff against target: 404 lines (+120/-111)
9 files modified
charm-helpers.yaml (+1/-0)
config.yaml (+17/-0)
hooks/lib/utils.py (+0/-57)
hooks/rabbitmq_server_relations.py (+12/-0)
lib/charmhelpers/contrib/openstack/context.py (+62/-44)
lib/charmhelpers/contrib/openstack/utils.py (+9/-5)
lib/charmhelpers/core/hookenv.py (+6/-0)
lib/charmhelpers/core/host.py (+9/-3)
lib/charmhelpers/fetch/__init__.py (+4/-2)
To merge this branch: bzr merge lp:~hopem/charms/precise/rabbitmq-server/lp1281753
Reviewer Review Type Date Requested Status
Ante Karamatić (community) Needs Fixing
Review via email: mp+207149@code.launchpad.net

This proposal has been superseded by a proposal from 2014-02-20.

To post a comment you must log in.
Revision history for this message
Ante Karamatić (ivoks) wrote :

configure_sources() needs to be executed during install(), not during config_changed()

review: Needs Fixing
52. By Edward Hope-Morley

[dosaboy] added support for 'source' and 'key' config options so that
          an alternative archive can be added to get more recent
          packages e.g. Ceph packages from the Ubuntu Cloud Archive.

53. By Edward Hope-Morley

[dosaboy] added support for 'source' and 'key' config options so that
          an alternative archive can be added to get more recent
          packages e.g. Ceph packages from the Ubuntu Cloud Archive.

54. By Edward Hope-Morley

[dosaboy] added support for 'source' and 'key' config options so that
          an alternative archive can be added to get more recent
          packages e.g. Ceph packages from the Ubuntu Cloud Archive.

55. By Edward Hope-Morley

[osaboy] added support for 'source' and 'key' config options so that
         an alternative archive can be added to get more recent
         packages e.g. Ceph packages from the Ubuntu Cloud Archive.

56. By Edward Hope-Morley

fixed default string values for key and source cfg options

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'charm-helpers.yaml'
2--- charm-helpers.yaml 2014-01-16 13:47:32 +0000
3+++ charm-helpers.yaml 2014-02-20 11:43:31 +0000
4@@ -4,3 +4,4 @@
5 - core
6 - contrib.charmsupport
7 - contrib.openstack
8+ - fetch
9\ No newline at end of file
10
11=== modified file 'config.yaml'
12--- config.yaml 2014-02-11 14:18:05 +0000
13+++ config.yaml 2014-02-20 11:43:31 +0000
14@@ -77,3 +77,20 @@
15 rbd pool has been created, changing this value will not have any
16 effect (although it can be changed in ceph by manually configuring
17 your ceph cluster).
18+ key:
19+ type: string
20+ description: |
21+ Key ID to import to the apt keyring to support use with arbitary source
22+ configuration from outside of Launchpad archives or PPA's.
23+ source:
24+ type: string
25+ default: None
26+ description: |
27+ Optional configuration to support use of additional sources such as:
28+ .
29+ - ppa:myteam/ppa
30+ - cloud:precise-proposed/folsom
31+ - http://my.archive.com/ubuntu main
32+ .
33+ The last option should be used in conjunction with the key configuration
34+ option.
35
36=== modified file 'hooks/lib/utils.py'
37--- hooks/lib/utils.py 2014-01-08 15:22:21 +0000
38+++ hooks/lib/utils.py 2014-02-20 11:43:31 +0000
39@@ -60,63 +60,6 @@
40 template = templates.get_template(template_name)
41 return template.render(context)
42
43-CLOUD_ARCHIVE = \
44-""" # Ubuntu Cloud Archive
45-deb http://ubuntu-cloud.archive.canonical.com/ubuntu {} main
46-"""
47-
48-CLOUD_ARCHIVE_POCKETS = {
49- 'folsom': 'precise-updates/folsom',
50- 'folsom/updates': 'precise-updates/folsom',
51- 'folsom/proposed': 'precise-proposed/folsom',
52- 'grizzly': 'precise-updates/grizzly',
53- 'grizzly/updates': 'precise-updates/grizzly',
54- 'grizzly/proposed': 'precise-proposed/grizzly',
55- 'havana': 'precise-updates/havana',
56- 'havana/updates': 'precise-updates/havana',
57- 'havana/proposed': 'precise-proposed/havana',
58- }
59-
60-
61-def configure_source():
62- source = str(config_get('openstack-origin'))
63- if not source:
64- return
65- if source.startswith('ppa:'):
66- cmd = [
67- 'add-apt-repository',
68- source
69- ]
70- subprocess.check_call(cmd)
71- if source.startswith('cloud:'):
72- # CA values should be formatted as cloud:ubuntu-openstack/pocket, eg:
73- # cloud:precise-folsom/updates or cloud:precise-folsom/proposed
74- install('ubuntu-cloud-keyring')
75- pocket = source.split(':')[1]
76- pocket = pocket.split('-')[1]
77- with open('/etc/apt/sources.list.d/cloud-archive.list', 'w') as apt:
78- apt.write(CLOUD_ARCHIVE.format(CLOUD_ARCHIVE_POCKETS[pocket]))
79- if source.startswith('deb'):
80- l = len(source.split('|'))
81- if l == 2:
82- (apt_line, key) = source.split('|')
83- cmd = [
84- 'apt-key',
85- 'adv', '--keyserver keyserver.ubuntu.com',
86- '--recv-keys', key
87- ]
88- subprocess.check_call(cmd)
89- elif l == 1:
90- apt_line = source
91-
92- with open('/etc/apt/sources.list.d/quantum.list', 'w') as apt:
93- apt.write(apt_line + "\n")
94- cmd = [
95- 'apt-get',
96- 'update'
97- ]
98- subprocess.check_call(cmd)
99-
100 # Protocols
101 TCP = 'TCP'
102 UDP = 'UDP'
103
104=== modified file 'hooks/rabbitmq_server_relations.py'
105--- hooks/rabbitmq_server_relations.py 2014-02-10 09:25:06 +0000
106+++ hooks/rabbitmq_server_relations.py 2014-02-20 11:43:31 +0000
107@@ -20,6 +20,10 @@
108 from charmhelpers.core import hookenv
109 from charmhelpers.core.host import rsync
110 from charmhelpers.contrib.charmsupport.nrpe import NRPE
111+from charmhelpers.fetch import (
112+ apt_update,
113+ add_source
114+)
115
116
117 SERVICE_NAME = os.getenv('JUJU_UNIT_NAME').split('/')[0]
118@@ -34,6 +38,10 @@
119
120
121 def install():
122+ # Add archive source if provided
123+ add_source(utils.config_get('source'), utils.config_get('key'))
124+ apt_update()
125+
126 pre_install_hooks()
127 utils.install(*rabbit.PACKAGES)
128 utils.expose(5672)
129@@ -362,6 +370,10 @@
130
131
132 def config_changed():
133+ # Add archive source if provided
134+ add_source(utils.config_get('source'), utils.config_get('key'))
135+ apt_update()
136+
137 unison.ensure_user(user=rabbit.SSH_USER, group='rabbit')
138 ensure_unison_rabbit_permissions()
139
140
141=== modified file 'lib/charmhelpers/contrib/openstack/context.py'
142--- lib/charmhelpers/contrib/openstack/context.py 2014-01-16 13:47:32 +0000
143+++ lib/charmhelpers/contrib/openstack/context.py 2014-02-20 11:43:31 +0000
144@@ -26,11 +26,9 @@
145 )
146
147 from charmhelpers.contrib.hahelpers.cluster import (
148+ determine_apache_port,
149 determine_api_port,
150- determine_haproxy_port,
151 https,
152- is_clustered,
153- peer_units,
154 )
155
156 from charmhelpers.contrib.hahelpers.apache import (
157@@ -67,6 +65,43 @@
158 return True
159
160
161+def config_flags_parser(config_flags):
162+ if config_flags.find('==') >= 0:
163+ log("config_flags is not in expected format (key=value)",
164+ level=ERROR)
165+ raise OSContextError
166+ # strip the following from each value.
167+ post_strippers = ' ,'
168+ # we strip any leading/trailing '=' or ' ' from the string then
169+ # split on '='.
170+ split = config_flags.strip(' =').split('=')
171+ limit = len(split)
172+ flags = {}
173+ for i in xrange(0, limit - 1):
174+ current = split[i]
175+ next = split[i + 1]
176+ vindex = next.rfind(',')
177+ if (i == limit - 2) or (vindex < 0):
178+ value = next
179+ else:
180+ value = next[:vindex]
181+
182+ if i == 0:
183+ key = current
184+ else:
185+ # if this not the first entry, expect an embedded key.
186+ index = current.rfind(',')
187+ if index < 0:
188+ log("invalid config value(s) at index %s" % (i),
189+ level=ERROR)
190+ raise OSContextError
191+ key = current[index + 1:]
192+
193+ # Add to collection.
194+ flags[key.strip(post_strippers)] = value.rstrip(post_strippers)
195+ return flags
196+
197+
198 class OSContextGenerator(object):
199 interfaces = []
200
201@@ -181,7 +216,12 @@
202 # Sufficient information found = break out!
203 break
204 # Used for active/active rabbitmq >= grizzly
205- if 'clustered' not in ctxt and len(related_units(rid)) > 1:
206+ if ('clustered' not in ctxt or relation_get('ha-vip-only') == 'True') and \
207+ len(related_units(rid)) > 1:
208+ if relation_get('ha_queues'):
209+ ctxt['rabbitmq_ha_queues'] = relation_get('ha_queues')
210+ else:
211+ ctxt['rabbitmq_ha_queues'] = False
212 rabbitmq_hosts = []
213 for unit in related_units(rid):
214 rabbitmq_hosts.append(relation_get('private-address',
215@@ -343,11 +383,9 @@
216 'private_address': unit_get('private-address'),
217 'endpoints': []
218 }
219- for ext_port in self.external_ports:
220- if peer_units() or is_clustered():
221- int_port = determine_haproxy_port(ext_port)
222- else:
223- int_port = determine_api_port(ext_port)
224+ for api_port in self.external_ports:
225+ ext_port = determine_apache_port(api_port)
226+ int_port = determine_api_port(api_port)
227 portmap = (int(ext_port), int(int_port))
228 ctxt['endpoints'].append(portmap)
229 return ctxt
230@@ -430,6 +468,11 @@
231 elif self.plugin == 'nvp':
232 ctxt.update(self.nvp_ctxt())
233
234+ alchemy_flags = config('neutron-alchemy-flags')
235+ if alchemy_flags:
236+ flags = config_flags_parser(alchemy_flags)
237+ ctxt['neutron_alchemy_flags'] = flags
238+
239 self._save_flag_file()
240 return ctxt
241
242@@ -450,41 +493,7 @@
243 if not config_flags:
244 return {}
245
246- if config_flags.find('==') >= 0:
247- log("config_flags is not in expected format (key=value)",
248- level=ERROR)
249- raise OSContextError
250-
251- # strip the following from each value.
252- post_strippers = ' ,'
253- # we strip any leading/trailing '=' or ' ' from the string then
254- # split on '='.
255- split = config_flags.strip(' =').split('=')
256- limit = len(split)
257- flags = {}
258- for i in xrange(0, limit - 1):
259- current = split[i]
260- next = split[i + 1]
261- vindex = next.rfind(',')
262- if (i == limit - 2) or (vindex < 0):
263- value = next
264- else:
265- value = next[:vindex]
266-
267- if i == 0:
268- key = current
269- else:
270- # if this not the first entry, expect an embedded key.
271- index = current.rfind(',')
272- if index < 0:
273- log("invalid config value(s) at index %s" % (i),
274- level=ERROR)
275- raise OSContextError
276- key = current[index + 1:]
277-
278- # Add to collection.
279- flags[key.strip(post_strippers)] = value.rstrip(post_strippers)
280-
281+ flags = config_flags_parser(config_flags)
282 return {'user_config_flags': flags}
283
284
285@@ -575,3 +584,12 @@
286 ctxt['sections'] = {}
287
288 return ctxt
289+
290+
291+class SyslogContext(OSContextGenerator):
292+
293+ def __call__(self):
294+ ctxt = {
295+ 'use_syslog': config('use-syslog')
296+ }
297+ return ctxt
298
299=== modified file 'lib/charmhelpers/contrib/openstack/utils.py'
300--- lib/charmhelpers/contrib/openstack/utils.py 2014-01-16 13:47:32 +0000
301+++ lib/charmhelpers/contrib/openstack/utils.py 2014-02-20 11:43:31 +0000
302@@ -415,7 +415,7 @@
303 return ns_query(hostname)
304
305
306-def get_hostname(address):
307+def get_hostname(address, fqdn=True):
308 """
309 Resolves hostname for given IP, or returns the input
310 if it is already a hostname.
311@@ -434,7 +434,11 @@
312 if not result:
313 return None
314
315- # strip trailing .
316- if result.endswith('.'):
317- return result[:-1]
318- return result
319+ if fqdn:
320+ # strip trailing .
321+ if result.endswith('.'):
322+ return result[:-1]
323+ else:
324+ return result
325+ else:
326+ return result.split('.')[0]
327
328=== modified file 'lib/charmhelpers/core/hookenv.py'
329--- lib/charmhelpers/core/hookenv.py 2013-11-15 19:15:16 +0000
330+++ lib/charmhelpers/core/hookenv.py 2014-02-20 11:43:31 +0000
331@@ -8,6 +8,7 @@
332 import json
333 import yaml
334 import subprocess
335+import sys
336 import UserDict
337 from subprocess import CalledProcessError
338
339@@ -149,6 +150,11 @@
340 return local_unit().split('/')[0]
341
342
343+def hook_name():
344+ """The name of the currently executing hook"""
345+ return os.path.basename(sys.argv[0])
346+
347+
348 @cached
349 def config(scope=None):
350 """Juju charm configuration"""
351
352=== modified file 'lib/charmhelpers/core/host.py'
353--- lib/charmhelpers/core/host.py 2014-01-10 11:16:09 +0000
354+++ lib/charmhelpers/core/host.py 2014-02-20 11:43:31 +0000
355@@ -194,7 +194,7 @@
356 return None
357
358
359-def restart_on_change(restart_map):
360+def restart_on_change(restart_map, stopstart=False):
361 """Restart services based on configuration files changing
362
363 This function is used a decorator, for example
364@@ -219,8 +219,14 @@
365 for path in restart_map:
366 if checksums[path] != file_hash(path):
367 restarts += restart_map[path]
368- for service_name in list(OrderedDict.fromkeys(restarts)):
369- service('restart', service_name)
370+ services_list = list(OrderedDict.fromkeys(restarts))
371+ if not stopstart:
372+ for service_name in services_list:
373+ service('restart', service_name)
374+ else:
375+ for action in ['stop', 'start']:
376+ for service_name in services_list:
377+ service(action, service_name)
378 return wrapped_f
379 return wrap
380
381
382=== modified file 'lib/charmhelpers/fetch/__init__.py'
383--- lib/charmhelpers/fetch/__init__.py 2014-01-10 11:16:09 +0000
384+++ lib/charmhelpers/fetch/__init__.py 2014-02-20 11:43:31 +0000
385@@ -136,7 +136,7 @@
386
387 def add_source(source, key=None):
388 if (source.startswith('ppa:') or
389- source.startswith('http:') or
390+ source.startswith('http') or
391 source.startswith('deb ') or
392 source.startswith('cloud-archive:')):
393 subprocess.check_call(['add-apt-repository', '--yes', source])
394@@ -156,7 +156,9 @@
395 with open('/etc/apt/sources.list.d/proposed.list', 'w') as apt:
396 apt.write(PROPOSED_POCKET.format(release))
397 if key:
398- subprocess.check_call(['apt-key', 'import', key])
399+ subprocess.check_call(['apt-key', 'adv', '--keyserver',
400+ 'keyserver.ubuntu.com', '--recv',
401+ key])
402
403
404 class SourceConfigError(Exception):

Subscribers

People subscribed via source and target branches