Merge lp:~james-page/charms/precise/rabbitmq-server/source-take-two into lp:charms/rabbitmq-server

Proposed by James Page
Status: Merged
Merged at revision: 51
Proposed branch: lp:~james-page/charms/precise/rabbitmq-server/source-take-two
Merge into: lp:charms/rabbitmq-server
Diff against target: 202 lines (+61/-62)
6 files modified
README (+19/-0)
charm-helpers.yaml (+1/-0)
config.yaml (+17/-0)
hooks/lib/utils.py (+0/-53)
hooks/rabbitmq_server_relations.py (+16/-7)
lib/charmhelpers/fetch/__init__.py (+8/-2)
To merge this branch: bzr merge lp:~james-page/charms/precise/rabbitmq-server/source-take-two
Reviewer Review Type Date Requested Status
Marco Ceppi (community) Approve
Review via email: mp+212576@code.launchpad.net

Description of the change

Add source and key options to allow use of different sources for packages.

Will trigger upgrades in rabbitmq if the new source has a newer rabbitmq package.

To post a comment you must log in.
53. By James Page

Add some README for source options

Revision history for this message
Edward Hope-Morley (hopem) wrote :

LGTM

Revision history for this message
Marco Ceppi (marcoceppi) wrote :

LGTM

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'README'
2--- README 2012-09-04 14:27:11 +0000
3+++ README 2014-03-25 11:07:21 +0000
4@@ -15,3 +15,22 @@
5 Enable SSL, passing in the key and certificate as configuration settings:
6
7 juju set rabbit ssl_enabled=True ssl_key="`cat rabbit-server-privkey.pem`" ssl_cert="`cat rabbit-server-cert.pem`"
8+
9+To change the source that the charm uses for packages:
10+
11+ juju set rabbit source="cloud:precise-icehouse"
12+
13+This will enable the Icehouse pocket of the Cloud Archive (which contains a new version of RabbitMQ) and upgrade the install to the new version.
14+
15+The source option can be used in a few different ways:
16+
17+ source="ppa:james-page/testing" - use the testing PPA owned by james-page
18+ source="http://myrepo/ubuntu main" - use the repository located at the provided URL
19+
20+The charm also supports use of arbitary archive key's for use with private repositories:
21+
22+ juju set rabbit key="C6CEA0C9"
23+
24+Note that in clustered configurations, the upgrade can be a bit racey as the services restart and re-cluster; this is resolvable using:
25+
26+ juju resolved --retry rabbitmq/1
27
28=== modified file 'charm-helpers.yaml'
29--- charm-helpers.yaml 2014-01-16 13:47:32 +0000
30+++ charm-helpers.yaml 2014-03-25 11:07:21 +0000
31@@ -4,3 +4,4 @@
32 - core
33 - contrib.charmsupport
34 - contrib.openstack
35+ - fetch
36\ No newline at end of file
37
38=== modified file 'config.yaml'
39--- config.yaml 2014-02-18 15:51:47 +0000
40+++ config.yaml 2014-03-25 11:07:21 +0000
41@@ -83,3 +83,20 @@
42 description: |
43 If True, services that support it will log to syslog instead of their normal
44 log location.
45+ key:
46+ type: string
47+ description: |
48+ Key ID to import to the apt keyring to support use with arbitary source
49+ configuration from outside of Launchpad archives or PPA's.
50+ source:
51+ type: string
52+ description: |
53+ Optional configuration to support use of additional sources such as:
54+ .
55+ - ppa:myteam/ppa
56+ - cloud:precise-proposed/folsom
57+ - http://my.archive.com/ubuntu main
58+ .
59+ The last option should be used in conjunction with the key configuration
60+ option.
61+
62
63=== modified file 'hooks/lib/utils.py'
64--- hooks/lib/utils.py 2014-02-27 17:36:04 +0000
65+++ hooks/lib/utils.py 2014-03-25 11:07:21 +0000
66@@ -58,59 +58,6 @@
67 template = templates.get_template(template_name)
68 return template.render(context)
69
70-CLOUD_ARCHIVE = """
71-# Ubuntu Cloud Archive
72-deb http://ubuntu-cloud.archive.canonical.com/ubuntu {} main
73-"""
74-
75-CLOUD_ARCHIVE_POCKETS = {
76- 'folsom': 'precise-updates/folsom',
77- 'folsom/updates': 'precise-updates/folsom',
78- 'folsom/proposed': 'precise-proposed/folsom',
79- 'grizzly': 'precise-updates/grizzly',
80- 'grizzly/updates': 'precise-updates/grizzly',
81- 'grizzly/proposed': 'precise-proposed/grizzly',
82- 'havana': 'precise-updates/havana',
83- 'havana/updates': 'precise-updates/havana',
84- 'havana/proposed': 'precise-proposed/havana'}
85-
86-
87-def configure_source():
88- source = str(config_get('openstack-origin'))
89- if not source:
90- return
91- if source.startswith('ppa:'):
92- cmd = [
93- 'add-apt-repository',
94- source]
95- subprocess.check_call(cmd)
96- if source.startswith('cloud:'):
97- # CA values should be formatted as cloud:ubuntu-openstack/pocket, eg:
98- # cloud:precise-folsom/updates or cloud:precise-folsom/proposed
99- install('ubuntu-cloud-keyring')
100- pocket = source.split(':')[1]
101- pocket = pocket.split('-')[1]
102- with open('/etc/apt/sources.list.d/cloud-archive.list', 'w') as apt:
103- apt.write(CLOUD_ARCHIVE.format(CLOUD_ARCHIVE_POCKETS[pocket]))
104- if source.startswith('deb'):
105- l = len(source.split('|'))
106- if l == 2:
107- (apt_line, key) = source.split('|')
108- cmd = [
109- 'apt-key',
110- 'adv', '--keyserver keyserver.ubuntu.com',
111- '--recv-keys', key]
112- subprocess.check_call(cmd)
113- elif l == 1:
114- apt_line = source
115-
116- with open('/etc/apt/sources.list.d/quantum.list', 'w') as apt:
117- apt.write(apt_line + "\n")
118- cmd = [
119- 'apt-get',
120- 'update']
121- subprocess.check_call(cmd)
122-
123 # Protocols
124 TCP = 'TCP'
125 UDP = 'UDP'
126
127=== modified file 'hooks/rabbitmq_server_relations.py'
128--- hooks/rabbitmq_server_relations.py 2014-02-27 17:36:04 +0000
129+++ hooks/rabbitmq_server_relations.py 2014-03-25 11:07:21 +0000
130@@ -20,6 +20,10 @@
131 from charmhelpers.core import hookenv
132 from charmhelpers.core.host import rsync
133 from charmhelpers.contrib.charmsupport.nrpe import NRPE
134+from charmhelpers.fetch import (
135+ apt_update,
136+ add_source
137+)
138
139
140 SERVICE_NAME = os.getenv('JUJU_UNIT_NAME').split('/')[0]
141@@ -35,12 +39,7 @@
142
143 def install():
144 pre_install_hooks()
145- utils.install(*rabbit.PACKAGES)
146- utils.expose(5672)
147- # ensure user + permissions for peer relations that
148- # may be syncing data there via SSH_USER.
149- unison.ensure_user(user=rabbit.SSH_USER, group=rabbit.RABBIT_USER)
150- ensure_unison_rabbit_permissions()
151+ # NOTE(jamespage) install actually happens in config_changed hook
152
153
154 def configure_amqp(username, vhost):
155@@ -365,7 +364,17 @@
156
157
158 def config_changed():
159- unison.ensure_user(user=rabbit.SSH_USER, group='rabbit')
160+ # Add archive source if provided
161+ add_source(utils.config_get('source'), utils.config_get('key'))
162+ apt_update(fatal=True)
163+
164+ # Install packages to ensure any changes to source
165+ # result in an upgrade if applicable.
166+ utils.install(*rabbit.PACKAGES)
167+
168+ utils.expose(5672)
169+
170+ unison.ensure_user(user=rabbit.SSH_USER, group=rabbit.RABBIT_USER)
171 ensure_unison_rabbit_permissions()
172
173 if utils.config_get('management_plugin') is True:
174
175=== modified file 'lib/charmhelpers/fetch/__init__.py'
176--- lib/charmhelpers/fetch/__init__.py 2014-01-10 11:16:09 +0000
177+++ lib/charmhelpers/fetch/__init__.py 2014-03-25 11:07:21 +0000
178@@ -135,8 +135,12 @@
179
180
181 def add_source(source, key=None):
182+ if source is None:
183+ log('Source is not present. Skipping')
184+ return
185+
186 if (source.startswith('ppa:') or
187- source.startswith('http:') or
188+ source.startswith('http') or
189 source.startswith('deb ') or
190 source.startswith('cloud-archive:')):
191 subprocess.check_call(['add-apt-repository', '--yes', source])
192@@ -156,7 +160,9 @@
193 with open('/etc/apt/sources.list.d/proposed.list', 'w') as apt:
194 apt.write(PROPOSED_POCKET.format(release))
195 if key:
196- subprocess.check_call(['apt-key', 'import', key])
197+ subprocess.check_call(['apt-key', 'adv', '--keyserver',
198+ 'keyserver.ubuntu.com', '--recv',
199+ key])
200
201
202 class SourceConfigError(Exception):

Subscribers

People subscribed via source and target branches