Merge lp:~jjo/charms/trusty/swift-proxy/swift_hash-from-JUJU_ENV_UUID-and-service_name into lp:~openstack-charmers-archive/charms/trusty/swift-proxy/trunk
- Trusty Tahr (14.04)
- swift_hash-from-JUJU_ENV_UUID-and-service_name
- Merge into trunk
Proposed by
JuanJo Ciarlante
Status: | Superseded |
---|---|
Proposed branch: | lp:~jjo/charms/trusty/swift-proxy/swift_hash-from-JUJU_ENV_UUID-and-service_name |
Merge into: | lp:~openstack-charmers-archive/charms/trusty/swift-proxy/trunk |
Diff against target: |
5652 lines (+4171/-249) (has conflicts) 52 files modified
.bzrignore (+2/-0) Makefile (+24/-1) charm-helpers-hooks.yaml (+13/-0) charm-helpers-tests.yaml (+5/-0) config.yaml (+53/-9) hooks/charmhelpers/contrib/hahelpers/apache.py (+10/-3) hooks/charmhelpers/contrib/hahelpers/cluster.py (+59/-17) hooks/charmhelpers/contrib/network/ip.py (+343/-0) hooks/charmhelpers/contrib/openstack/amulet/deployment.py (+94/-0) hooks/charmhelpers/contrib/openstack/amulet/utils.py (+276/-0) hooks/charmhelpers/contrib/openstack/context.py (+237/-59) hooks/charmhelpers/contrib/openstack/ip.py (+79/-0) hooks/charmhelpers/contrib/openstack/neutron.py (+14/-0) hooks/charmhelpers/contrib/openstack/templates/haproxy.cfg (+18/-4) hooks/charmhelpers/contrib/openstack/templates/openstack_https_frontend (+9/-8) hooks/charmhelpers/contrib/openstack/templates/openstack_https_frontend.conf (+9/-8) hooks/charmhelpers/contrib/openstack/templating.py (+22/-23) hooks/charmhelpers/contrib/openstack/utils.py (+45/-6) hooks/charmhelpers/contrib/peerstorage/__init__.py (+131/-0) hooks/charmhelpers/contrib/storage/linux/ceph.py (+1/-1) hooks/charmhelpers/core/fstab.py (+116/-0) hooks/charmhelpers/core/hookenv.py (+49/-21) hooks/charmhelpers/core/host.py (+75/-11) hooks/charmhelpers/core/services/__init__.py (+2/-0) hooks/charmhelpers/core/services/base.py (+313/-0) hooks/charmhelpers/core/services/helpers.py (+239/-0) hooks/charmhelpers/core/templating.py (+51/-0) hooks/charmhelpers/fetch/__init__.py (+115/-32) hooks/charmhelpers/fetch/archiveurl.py (+49/-4) hooks/swift_context.py (+30/-11) hooks/swift_hooks.py (+78/-23) hooks/swift_utils.py (+26/-3) revision (+1/-1) templates/essex/proxy-server.conf (+2/-0) templates/grizzly/proxy-server.conf (+2/-0) templates/havana/proxy-server.conf (+2/-0) templates/icehouse/proxy-server.conf (+4/-1) templates/memcached.conf (+1/-1) tests/00-setup (+11/-0) tests/10-basic-precise-essex (+9/-0) tests/11-basic-precise-folsom (+11/-0) tests/12-basic-precise-grizzly (+11/-0) tests/13-basic-precise-havana (+11/-0) tests/14-basic-precise-icehouse (+11/-0) tests/15-basic-trusty-icehouse (+9/-0) tests/README (+52/-0) tests/basic_deployment.py (+827/-0) tests/charmhelpers/contrib/amulet/deployment.py (+72/-0) tests/charmhelpers/contrib/amulet/utils.py (+176/-0) tests/charmhelpers/contrib/openstack/amulet/deployment.py (+94/-0) tests/charmhelpers/contrib/openstack/amulet/utils.py (+276/-0) unit_tests/test_templates.py (+2/-2) Conflict adding file .bzrignore. Moved existing file to .bzrignore.moved. Text conflict in Makefile Contents conflict in charm-helpers.yaml Text conflict in hooks/charmhelpers/contrib/openstack/context.py Text conflict in hooks/charmhelpers/contrib/openstack/utils.py Conflict adding file hooks/charmhelpers/core/fstab.py. Moved existing file to hooks/charmhelpers/core/fstab.py.moved. Text conflict in hooks/charmhelpers/core/host.py Text conflict in hooks/charmhelpers/fetch/__init__.py |
To merge this branch: | bzr merge lp:~jjo/charms/trusty/swift-proxy/swift_hash-from-JUJU_ENV_UUID-and-service_name |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
OpenStack Charmers | Pending | ||
Review via email: mp+237290@code.launchpad.net |
This proposal supersedes a proposal from 2014-10-06.
This proposal has been superseded by a proposal from 2014-10-06.
Commit message
Description of the change
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 | === added file '.bzrignore' | |||
2 | --- .bzrignore 1970-01-01 00:00:00 +0000 | |||
3 | +++ .bzrignore 2014-10-06 15:38:41 +0000 | |||
4 | @@ -0,0 +1,2 @@ | |||
5 | 1 | .coverage | ||
6 | 2 | bin | ||
7 | 0 | 3 | ||
8 | === renamed file '.bzrignore' => '.bzrignore.moved' | |||
9 | === modified file 'Makefile' | |||
10 | --- Makefile 2014-08-13 15:57:07 +0000 | |||
11 | +++ Makefile 2014-10-06 15:38:41 +0000 | |||
12 | @@ -3,10 +3,15 @@ | |||
13 | 3 | 3 | ||
14 | 4 | lint: | 4 | lint: |
15 | 5 | @flake8 --exclude hooks/charmhelpers --ignore=E125 hooks | 5 | @flake8 --exclude hooks/charmhelpers --ignore=E125 hooks |
17 | 6 | @flake8 --exclude hooks/charmhelpers --ignore=E125 unit_tests | 6 | @flake8 --exclude hooks/charmhelpers --ignore=E125 unit_tests tests |
18 | 7 | @charm proof | 7 | @charm proof |
19 | 8 | 8 | ||
20 | 9 | unit_test: | ||
21 | 10 | @echo Starting unit tests... | ||
22 | 11 | @$(PYTHON) /usr/bin/nosetests --nologcapture --with-coverage unit_tests | ||
23 | 12 | |||
24 | 9 | test: | 13 | test: |
25 | 14 | <<<<<<< TREE | ||
26 | 10 | @echo Starting tests... | 15 | @echo Starting tests... |
27 | 11 | @$(PYTHON) /usr/bin/nosetests --nologcapture --with-coverage unit_tests | 16 | @$(PYTHON) /usr/bin/nosetests --nologcapture --with-coverage unit_tests |
28 | 12 | 17 | ||
29 | @@ -19,5 +24,23 @@ | |||
30 | 19 | @$(PYTHON) bin/charm_helpers_sync.py -c charm-helpers.yaml | 24 | @$(PYTHON) bin/charm_helpers_sync.py -c charm-helpers.yaml |
31 | 20 | 25 | ||
32 | 21 | publish: lint test | 26 | publish: lint test |
33 | 27 | ======= | ||
34 | 28 | @echo Starting Amulet tests... | ||
35 | 29 | # coreycb note: The -v should only be temporary until Amulet sends | ||
36 | 30 | # raise_status() messages to stderr: | ||
37 | 31 | # https://bugs.launchpad.net/amulet/+bug/1320357 | ||
38 | 32 | @juju test -v -p AMULET_HTTP_PROXY | ||
39 | 33 | |||
40 | 34 | bin/charm_helpers_sync.py: | ||
41 | 35 | @mkdir -p bin | ||
42 | 36 | @bzr cat lp:charm-helpers/tools/charm_helpers_sync/charm_helpers_sync.py \ | ||
43 | 37 | > bin/charm_helpers_sync.py | ||
44 | 38 | |||
45 | 39 | sync: bin/charm_helpers_sync.py | ||
46 | 40 | @$(PYTHON) bin/charm_helpers_sync.py -c charm-helpers-hooks.yaml | ||
47 | 41 | @$(PYTHON) bin/charm_helpers_sync.py -c charm-helpers-tests.yaml | ||
48 | 42 | |||
49 | 43 | publish: lint unit_test | ||
50 | 44 | >>>>>>> MERGE-SOURCE | ||
51 | 22 | bzr push lp:charms/swift-proxy | 45 | bzr push lp:charms/swift-proxy |
52 | 23 | bzr push lp:charms/trusty/swift-proxy | 46 | bzr push lp:charms/trusty/swift-proxy |
53 | 24 | 47 | ||
54 | === added file 'charm-helpers-hooks.yaml' | |||
55 | --- charm-helpers-hooks.yaml 1970-01-01 00:00:00 +0000 | |||
56 | +++ charm-helpers-hooks.yaml 2014-10-06 15:38:41 +0000 | |||
57 | @@ -0,0 +1,13 @@ | |||
58 | 1 | branch: lp:charm-helpers | ||
59 | 2 | destination: hooks/charmhelpers | ||
60 | 3 | include: | ||
61 | 4 | - core | ||
62 | 5 | - fetch | ||
63 | 6 | - contrib.openstack|inc=* | ||
64 | 7 | - contrib.storage.linux | ||
65 | 8 | - contrib.hahelpers: | ||
66 | 9 | - apache | ||
67 | 10 | - cluster | ||
68 | 11 | - payload.execd | ||
69 | 12 | - contrib.network.ip | ||
70 | 13 | - contrib.peerstorage | ||
71 | 0 | 14 | ||
72 | === added file 'charm-helpers-tests.yaml' | |||
73 | --- charm-helpers-tests.yaml 1970-01-01 00:00:00 +0000 | |||
74 | +++ charm-helpers-tests.yaml 2014-10-06 15:38:41 +0000 | |||
75 | @@ -0,0 +1,5 @@ | |||
76 | 1 | branch: lp:charm-helpers | ||
77 | 2 | destination: tests/charmhelpers | ||
78 | 3 | include: | ||
79 | 4 | - contrib.amulet | ||
80 | 5 | - contrib.openstack.amulet | ||
81 | 0 | 6 | ||
82 | === renamed file 'charm-helpers.yaml' => 'charm-helpers.yaml.THIS' | |||
83 | === modified file 'config.yaml' | |||
84 | --- config.yaml 2013-04-15 19:41:45 +0000 | |||
85 | +++ config.yaml 2014-10-06 15:38:41 +0000 | |||
86 | @@ -106,6 +106,19 @@ | |||
87 | 106 | default: true | 106 | default: true |
88 | 107 | type: boolean | 107 | type: boolean |
89 | 108 | description: Delay authentication to downstream WSGI services. | 108 | description: Delay authentication to downstream WSGI services. |
90 | 109 | node-timeout: | ||
91 | 110 | default: 60 | ||
92 | 111 | type: int | ||
93 | 112 | description: How long the proxy server will wait on responses from the a/c/o servers. | ||
94 | 113 | recoverable-node-timeout: | ||
95 | 114 | default: 30 | ||
96 | 115 | type: int | ||
97 | 116 | description: | | ||
98 | 117 | How long the proxy server will wait for an initial response and to read a | ||
99 | 118 | chunk of data from the object servers while serving GET / HEAD requests. | ||
100 | 119 | Timeouts from these requests can be recovered from so setting this to | ||
101 | 120 | something lower than node-timeout would provide quicker error recovery | ||
102 | 121 | while allowing for a longer timeout for non-recoverable requests (PUTs). | ||
103 | 109 | # Manual Keystone configuration. | 122 | # Manual Keystone configuration. |
104 | 110 | keystone-auth-host: | 123 | keystone-auth-host: |
105 | 111 | type: string | 124 | type: string |
106 | @@ -134,15 +147,11 @@ | |||
107 | 134 | description: Hash to use across all swift-proxy servers - don't loose | 147 | description: Hash to use across all swift-proxy servers - don't loose |
108 | 135 | vip: | 148 | vip: |
109 | 136 | type: string | 149 | type: string |
119 | 137 | description: "Virtual IP to use to front swift-proxy in ha configuration" | 150 | description: | |
120 | 138 | vip_iface: | 151 | Virtual IP(s) to use to front API services in HA configuration. |
121 | 139 | type: string | 152 | . |
122 | 140 | default: eth0 | 153 | If multiple networks are being used, a VIP should be provided for each |
123 | 141 | description: "Network Interface where to place the Virtual IP" | 154 | network, separated by spaces. |
115 | 142 | vip_cidr: | ||
116 | 143 | type: int | ||
117 | 144 | default: 24 | ||
118 | 145 | description: "Netmask that will be used for the Virtual IP" | ||
124 | 146 | ha-bindiface: | 155 | ha-bindiface: |
125 | 147 | type: string | 156 | type: string |
126 | 148 | default: eth0 | 157 | default: eth0 |
127 | @@ -155,3 +164,38 @@ | |||
128 | 155 | description: | | 164 | description: | |
129 | 156 | Default multicast port number that will be used to communicate between | 165 | Default multicast port number that will be used to communicate between |
130 | 157 | HA Cluster nodes. | 166 | HA Cluster nodes. |
131 | 167 | # Network configuration options | ||
132 | 168 | # by default all access is over 'private-address' | ||
133 | 169 | os-admin-network: | ||
134 | 170 | type: string | ||
135 | 171 | description: | | ||
136 | 172 | The IP address and netmask of the OpenStack Admin network (e.g., | ||
137 | 173 | 192.168.0.0/24) | ||
138 | 174 | . | ||
139 | 175 | This network will be used for admin endpoints. | ||
140 | 176 | os-internal-network: | ||
141 | 177 | type: string | ||
142 | 178 | description: | | ||
143 | 179 | The IP address and netmask of the OpenStack Internal network (e.g., | ||
144 | 180 | 192.168.0.0/24) | ||
145 | 181 | . | ||
146 | 182 | This network will be used for internal endpoints. | ||
147 | 183 | os-public-network: | ||
148 | 184 | type: string | ||
149 | 185 | description: | | ||
150 | 186 | The IP address and netmask of the OpenStack Public network (e.g., | ||
151 | 187 | 192.168.0.0/24) | ||
152 | 188 | . | ||
153 | 189 | This network will be used for public endpoints. | ||
154 | 190 | prefer-ipv6: | ||
155 | 191 | type: boolean | ||
156 | 192 | default: False | ||
157 | 193 | description: | | ||
158 | 194 | If True enables IPv6 support. The charm will expect network interfaces | ||
159 | 195 | to be configured with an IPv6 address. If set to False (default) IPv4 | ||
160 | 196 | is expected. | ||
161 | 197 | . | ||
162 | 198 | NOTE: these charms do not currently support IPv6 privacy extension. In | ||
163 | 199 | order for this charm to function correctly, the privacy extension must be | ||
164 | 200 | disabled and a non-temporary address must be configured/available on | ||
165 | 201 | your network interface. | ||
166 | 158 | 202 | ||
167 | === modified file 'hooks/charmhelpers/contrib/hahelpers/apache.py' | |||
168 | --- hooks/charmhelpers/contrib/hahelpers/apache.py 2014-03-27 11:23:24 +0000 | |||
169 | +++ hooks/charmhelpers/contrib/hahelpers/apache.py 2014-10-06 15:38:41 +0000 | |||
170 | @@ -20,20 +20,27 @@ | |||
171 | 20 | ) | 20 | ) |
172 | 21 | 21 | ||
173 | 22 | 22 | ||
175 | 23 | def get_cert(): | 23 | def get_cert(cn=None): |
176 | 24 | # TODO: deal with multiple https endpoints via charm config | ||
177 | 24 | cert = config_get('ssl_cert') | 25 | cert = config_get('ssl_cert') |
178 | 25 | key = config_get('ssl_key') | 26 | key = config_get('ssl_key') |
179 | 26 | if not (cert and key): | 27 | if not (cert and key): |
180 | 27 | log("Inspecting identity-service relations for SSL certificate.", | 28 | log("Inspecting identity-service relations for SSL certificate.", |
181 | 28 | level=INFO) | 29 | level=INFO) |
182 | 29 | cert = key = None | 30 | cert = key = None |
183 | 31 | if cn: | ||
184 | 32 | ssl_cert_attr = 'ssl_cert_{}'.format(cn) | ||
185 | 33 | ssl_key_attr = 'ssl_key_{}'.format(cn) | ||
186 | 34 | else: | ||
187 | 35 | ssl_cert_attr = 'ssl_cert' | ||
188 | 36 | ssl_key_attr = 'ssl_key' | ||
189 | 30 | for r_id in relation_ids('identity-service'): | 37 | for r_id in relation_ids('identity-service'): |
190 | 31 | for unit in relation_list(r_id): | 38 | for unit in relation_list(r_id): |
191 | 32 | if not cert: | 39 | if not cert: |
193 | 33 | cert = relation_get('ssl_cert', | 40 | cert = relation_get(ssl_cert_attr, |
194 | 34 | rid=r_id, unit=unit) | 41 | rid=r_id, unit=unit) |
195 | 35 | if not key: | 42 | if not key: |
197 | 36 | key = relation_get('ssl_key', | 43 | key = relation_get(ssl_key_attr, |
198 | 37 | rid=r_id, unit=unit) | 44 | rid=r_id, unit=unit) |
199 | 38 | return (cert, key) | 45 | return (cert, key) |
200 | 39 | 46 | ||
201 | 40 | 47 | ||
202 | === modified file 'hooks/charmhelpers/contrib/hahelpers/cluster.py' | |||
203 | --- hooks/charmhelpers/contrib/hahelpers/cluster.py 2014-03-27 11:23:24 +0000 | |||
204 | +++ hooks/charmhelpers/contrib/hahelpers/cluster.py 2014-10-06 15:38:41 +0000 | |||
205 | @@ -6,6 +6,11 @@ | |||
206 | 6 | # Adam Gandelman <adamg@ubuntu.com> | 6 | # Adam Gandelman <adamg@ubuntu.com> |
207 | 7 | # | 7 | # |
208 | 8 | 8 | ||
209 | 9 | """ | ||
210 | 10 | Helpers for clustering and determining "cluster leadership" and other | ||
211 | 11 | clustering-related helpers. | ||
212 | 12 | """ | ||
213 | 13 | |||
214 | 9 | import subprocess | 14 | import subprocess |
215 | 10 | import os | 15 | import os |
216 | 11 | 16 | ||
217 | @@ -19,6 +24,7 @@ | |||
218 | 19 | config as config_get, | 24 | config as config_get, |
219 | 20 | INFO, | 25 | INFO, |
220 | 21 | ERROR, | 26 | ERROR, |
221 | 27 | WARNING, | ||
222 | 22 | unit_get, | 28 | unit_get, |
223 | 23 | ) | 29 | ) |
224 | 24 | 30 | ||
225 | @@ -27,6 +33,29 @@ | |||
226 | 27 | pass | 33 | pass |
227 | 28 | 34 | ||
228 | 29 | 35 | ||
229 | 36 | def is_elected_leader(resource): | ||
230 | 37 | """ | ||
231 | 38 | Returns True if the charm executing this is the elected cluster leader. | ||
232 | 39 | |||
233 | 40 | It relies on two mechanisms to determine leadership: | ||
234 | 41 | 1. If the charm is part of a corosync cluster, call corosync to | ||
235 | 42 | determine leadership. | ||
236 | 43 | 2. If the charm is not part of a corosync cluster, the leader is | ||
237 | 44 | determined as being "the alive unit with the lowest unit numer". In | ||
238 | 45 | other words, the oldest surviving unit. | ||
239 | 46 | """ | ||
240 | 47 | if is_clustered(): | ||
241 | 48 | if not is_crm_leader(resource): | ||
242 | 49 | log('Deferring action to CRM leader.', level=INFO) | ||
243 | 50 | return False | ||
244 | 51 | else: | ||
245 | 52 | peers = peer_units() | ||
246 | 53 | if peers and not oldest_peer(peers): | ||
247 | 54 | log('Deferring action to oldest service unit.', level=INFO) | ||
248 | 55 | return False | ||
249 | 56 | return True | ||
250 | 57 | |||
251 | 58 | |||
252 | 30 | def is_clustered(): | 59 | def is_clustered(): |
253 | 31 | for r_id in (relation_ids('ha') or []): | 60 | for r_id in (relation_ids('ha') or []): |
254 | 32 | for unit in (relation_list(r_id) or []): | 61 | for unit in (relation_list(r_id) or []): |
255 | @@ -38,7 +67,11 @@ | |||
256 | 38 | return False | 67 | return False |
257 | 39 | 68 | ||
258 | 40 | 69 | ||
260 | 41 | def is_leader(resource): | 70 | def is_crm_leader(resource): |
261 | 71 | """ | ||
262 | 72 | Returns True if the charm calling this is the elected corosync leader, | ||
263 | 73 | as returned by calling the external "crm" command. | ||
264 | 74 | """ | ||
265 | 42 | cmd = [ | 75 | cmd = [ |
266 | 43 | "crm", "resource", | 76 | "crm", "resource", |
267 | 44 | "show", resource | 77 | "show", resource |
268 | @@ -54,15 +87,31 @@ | |||
269 | 54 | return False | 87 | return False |
270 | 55 | 88 | ||
271 | 56 | 89 | ||
273 | 57 | def peer_units(): | 90 | def is_leader(resource): |
274 | 91 | log("is_leader is deprecated. Please consider using is_crm_leader " | ||
275 | 92 | "instead.", level=WARNING) | ||
276 | 93 | return is_crm_leader(resource) | ||
277 | 94 | |||
278 | 95 | |||
279 | 96 | def peer_units(peer_relation="cluster"): | ||
280 | 58 | peers = [] | 97 | peers = [] |
282 | 59 | for r_id in (relation_ids('cluster') or []): | 98 | for r_id in (relation_ids(peer_relation) or []): |
283 | 60 | for unit in (relation_list(r_id) or []): | 99 | for unit in (relation_list(r_id) or []): |
284 | 61 | peers.append(unit) | 100 | peers.append(unit) |
285 | 62 | return peers | 101 | return peers |
286 | 63 | 102 | ||
287 | 64 | 103 | ||
288 | 104 | def peer_ips(peer_relation='cluster', addr_key='private-address'): | ||
289 | 105 | '''Return a dict of peers and their private-address''' | ||
290 | 106 | peers = {} | ||
291 | 107 | for r_id in relation_ids(peer_relation): | ||
292 | 108 | for unit in relation_list(r_id): | ||
293 | 109 | peers[unit] = relation_get(addr_key, rid=r_id, unit=unit) | ||
294 | 110 | return peers | ||
295 | 111 | |||
296 | 112 | |||
297 | 65 | def oldest_peer(peers): | 113 | def oldest_peer(peers): |
298 | 114 | """Determines who the oldest peer is by comparing unit numbers.""" | ||
299 | 66 | local_unit_no = int(os.getenv('JUJU_UNIT_NAME').split('/')[1]) | 115 | local_unit_no = int(os.getenv('JUJU_UNIT_NAME').split('/')[1]) |
300 | 67 | for peer in peers: | 116 | for peer in peers: |
301 | 68 | remote_unit_no = int(peer.split('/')[1]) | 117 | remote_unit_no = int(peer.split('/')[1]) |
302 | @@ -72,16 +121,9 @@ | |||
303 | 72 | 121 | ||
304 | 73 | 122 | ||
305 | 74 | def eligible_leader(resource): | 123 | def eligible_leader(resource): |
316 | 75 | if is_clustered(): | 124 | log("eligible_leader is deprecated. Please consider using " |
317 | 76 | if not is_leader(resource): | 125 | "is_elected_leader instead.", level=WARNING) |
318 | 77 | log('Deferring action to CRM leader.', level=INFO) | 126 | return is_elected_leader(resource) |
309 | 78 | return False | ||
310 | 79 | else: | ||
311 | 80 | peers = peer_units() | ||
312 | 81 | if peers and not oldest_peer(peers): | ||
313 | 82 | log('Deferring action to oldest service unit.', level=INFO) | ||
314 | 83 | return False | ||
315 | 84 | return True | ||
319 | 85 | 127 | ||
320 | 86 | 128 | ||
321 | 87 | def https(): | 129 | def https(): |
322 | @@ -97,10 +139,9 @@ | |||
323 | 97 | return True | 139 | return True |
324 | 98 | for r_id in relation_ids('identity-service'): | 140 | for r_id in relation_ids('identity-service'): |
325 | 99 | for unit in relation_list(r_id): | 141 | for unit in relation_list(r_id): |
326 | 142 | # TODO - needs fixing for new helper as ssl_cert/key suffixes with CN | ||
327 | 100 | rel_state = [ | 143 | rel_state = [ |
328 | 101 | relation_get('https_keystone', rid=r_id, unit=unit), | 144 | relation_get('https_keystone', rid=r_id, unit=unit), |
329 | 102 | relation_get('ssl_cert', rid=r_id, unit=unit), | ||
330 | 103 | relation_get('ssl_key', rid=r_id, unit=unit), | ||
331 | 104 | relation_get('ca_cert', rid=r_id, unit=unit), | 145 | relation_get('ca_cert', rid=r_id, unit=unit), |
332 | 105 | ] | 146 | ] |
333 | 106 | # NOTE: works around (LP: #1203241) | 147 | # NOTE: works around (LP: #1203241) |
334 | @@ -146,12 +187,12 @@ | |||
335 | 146 | Obtains all relevant configuration from charm configuration required | 187 | Obtains all relevant configuration from charm configuration required |
336 | 147 | for initiating a relation to hacluster: | 188 | for initiating a relation to hacluster: |
337 | 148 | 189 | ||
339 | 149 | ha-bindiface, ha-mcastport, vip, vip_iface, vip_cidr | 190 | ha-bindiface, ha-mcastport, vip |
340 | 150 | 191 | ||
341 | 151 | returns: dict: A dict containing settings keyed by setting name. | 192 | returns: dict: A dict containing settings keyed by setting name. |
342 | 152 | raises: HAIncompleteConfig if settings are missing. | 193 | raises: HAIncompleteConfig if settings are missing. |
343 | 153 | ''' | 194 | ''' |
345 | 154 | settings = ['ha-bindiface', 'ha-mcastport', 'vip', 'vip_iface', 'vip_cidr'] | 195 | settings = ['ha-bindiface', 'ha-mcastport', 'vip'] |
346 | 155 | conf = {} | 196 | conf = {} |
347 | 156 | for setting in settings: | 197 | for setting in settings: |
348 | 157 | conf[setting] = config_get(setting) | 198 | conf[setting] = config_get(setting) |
349 | @@ -170,6 +211,7 @@ | |||
350 | 170 | 211 | ||
351 | 171 | :configs : OSTemplateRenderer: A config tempating object to inspect for | 212 | :configs : OSTemplateRenderer: A config tempating object to inspect for |
352 | 172 | a complete https context. | 213 | a complete https context. |
353 | 214 | |||
354 | 173 | :vip_setting: str: Setting in charm config that specifies | 215 | :vip_setting: str: Setting in charm config that specifies |
355 | 174 | VIP address. | 216 | VIP address. |
356 | 175 | ''' | 217 | ''' |
357 | 176 | 218 | ||
358 | === added directory 'hooks/charmhelpers/contrib/network' | |||
359 | === added file 'hooks/charmhelpers/contrib/network/__init__.py' | |||
360 | === added file 'hooks/charmhelpers/contrib/network/ip.py' | |||
361 | --- hooks/charmhelpers/contrib/network/ip.py 1970-01-01 00:00:00 +0000 | |||
362 | +++ hooks/charmhelpers/contrib/network/ip.py 2014-10-06 15:38:41 +0000 | |||
363 | @@ -0,0 +1,343 @@ | |||
364 | 1 | import glob | ||
365 | 2 | import re | ||
366 | 3 | import subprocess | ||
367 | 4 | import sys | ||
368 | 5 | |||
369 | 6 | from functools import partial | ||
370 | 7 | |||
371 | 8 | from charmhelpers.core.hookenv import unit_get | ||
372 | 9 | from charmhelpers.fetch import apt_install | ||
373 | 10 | from charmhelpers.core.hookenv import ( | ||
374 | 11 | WARNING, | ||
375 | 12 | ERROR, | ||
376 | 13 | log | ||
377 | 14 | ) | ||
378 | 15 | |||
379 | 16 | try: | ||
380 | 17 | import netifaces | ||
381 | 18 | except ImportError: | ||
382 | 19 | apt_install('python-netifaces') | ||
383 | 20 | import netifaces | ||
384 | 21 | |||
385 | 22 | try: | ||
386 | 23 | import netaddr | ||
387 | 24 | except ImportError: | ||
388 | 25 | apt_install('python-netaddr') | ||
389 | 26 | import netaddr | ||
390 | 27 | |||
391 | 28 | |||
392 | 29 | def _validate_cidr(network): | ||
393 | 30 | try: | ||
394 | 31 | netaddr.IPNetwork(network) | ||
395 | 32 | except (netaddr.core.AddrFormatError, ValueError): | ||
396 | 33 | raise ValueError("Network (%s) is not in CIDR presentation format" % | ||
397 | 34 | network) | ||
398 | 35 | |||
399 | 36 | |||
400 | 37 | def get_address_in_network(network, fallback=None, fatal=False): | ||
401 | 38 | """ | ||
402 | 39 | Get an IPv4 or IPv6 address within the network from the host. | ||
403 | 40 | |||
404 | 41 | :param network (str): CIDR presentation format. For example, | ||
405 | 42 | '192.168.1.0/24'. | ||
406 | 43 | :param fallback (str): If no address is found, return fallback. | ||
407 | 44 | :param fatal (boolean): If no address is found, fallback is not | ||
408 | 45 | set and fatal is True then exit(1). | ||
409 | 46 | |||
410 | 47 | """ | ||
411 | 48 | |||
412 | 49 | def not_found_error_out(): | ||
413 | 50 | log("No IP address found in network: %s" % network, | ||
414 | 51 | level=ERROR) | ||
415 | 52 | sys.exit(1) | ||
416 | 53 | |||
417 | 54 | if network is None: | ||
418 | 55 | if fallback is not None: | ||
419 | 56 | return fallback | ||
420 | 57 | else: | ||
421 | 58 | if fatal: | ||
422 | 59 | not_found_error_out() | ||
423 | 60 | |||
424 | 61 | _validate_cidr(network) | ||
425 | 62 | network = netaddr.IPNetwork(network) | ||
426 | 63 | for iface in netifaces.interfaces(): | ||
427 | 64 | addresses = netifaces.ifaddresses(iface) | ||
428 | 65 | if network.version == 4 and netifaces.AF_INET in addresses: | ||
429 | 66 | addr = addresses[netifaces.AF_INET][0]['addr'] | ||
430 | 67 | netmask = addresses[netifaces.AF_INET][0]['netmask'] | ||
431 | 68 | cidr = netaddr.IPNetwork("%s/%s" % (addr, netmask)) | ||
432 | 69 | if cidr in network: | ||
433 | 70 | return str(cidr.ip) | ||
434 | 71 | if network.version == 6 and netifaces.AF_INET6 in addresses: | ||
435 | 72 | for addr in addresses[netifaces.AF_INET6]: | ||
436 | 73 | if not addr['addr'].startswith('fe80'): | ||
437 | 74 | cidr = netaddr.IPNetwork("%s/%s" % (addr['addr'], | ||
438 | 75 | addr['netmask'])) | ||
439 | 76 | if cidr in network: | ||
440 | 77 | return str(cidr.ip) | ||
441 | 78 | |||
442 | 79 | if fallback is not None: | ||
443 | 80 | return fallback | ||
444 | 81 | |||
445 | 82 | if fatal: | ||
446 | 83 | not_found_error_out() | ||
447 | 84 | |||
448 | 85 | return None | ||
449 | 86 | |||
450 | 87 | |||
451 | 88 | def is_ipv6(address): | ||
452 | 89 | '''Determine whether provided address is IPv6 or not''' | ||
453 | 90 | try: | ||
454 | 91 | address = netaddr.IPAddress(address) | ||
455 | 92 | except netaddr.AddrFormatError: | ||
456 | 93 | # probably a hostname - so not an address at all! | ||
457 | 94 | return False | ||
458 | 95 | else: | ||
459 | 96 | return address.version == 6 | ||
460 | 97 | |||
461 | 98 | |||
462 | 99 | def is_address_in_network(network, address): | ||
463 | 100 | """ | ||
464 | 101 | Determine whether the provided address is within a network range. | ||
465 | 102 | |||
466 | 103 | :param network (str): CIDR presentation format. For example, | ||
467 | 104 | '192.168.1.0/24'. | ||
468 | 105 | :param address: An individual IPv4 or IPv6 address without a net | ||
469 | 106 | mask or subnet prefix. For example, '192.168.1.1'. | ||
470 | 107 | :returns boolean: Flag indicating whether address is in network. | ||
471 | 108 | """ | ||
472 | 109 | try: | ||
473 | 110 | network = netaddr.IPNetwork(network) | ||
474 | 111 | except (netaddr.core.AddrFormatError, ValueError): | ||
475 | 112 | raise ValueError("Network (%s) is not in CIDR presentation format" % | ||
476 | 113 | network) | ||
477 | 114 | try: | ||
478 | 115 | address = netaddr.IPAddress(address) | ||
479 | 116 | except (netaddr.core.AddrFormatError, ValueError): | ||
480 | 117 | raise ValueError("Address (%s) is not in correct presentation format" % | ||
481 | 118 | address) | ||
482 | 119 | if address in network: | ||
483 | 120 | return True | ||
484 | 121 | else: | ||
485 | 122 | return False | ||
486 | 123 | |||
487 | 124 | |||
488 | 125 | def _get_for_address(address, key): | ||
489 | 126 | """Retrieve an attribute of or the physical interface that | ||
490 | 127 | the IP address provided could be bound to. | ||
491 | 128 | |||
492 | 129 | :param address (str): An individual IPv4 or IPv6 address without a net | ||
493 | 130 | mask or subnet prefix. For example, '192.168.1.1'. | ||
494 | 131 | :param key: 'iface' for the physical interface name or an attribute | ||
495 | 132 | of the configured interface, for example 'netmask'. | ||
496 | 133 | :returns str: Requested attribute or None if address is not bindable. | ||
497 | 134 | """ | ||
498 | 135 | address = netaddr.IPAddress(address) | ||
499 | 136 | for iface in netifaces.interfaces(): | ||
500 | 137 | addresses = netifaces.ifaddresses(iface) | ||
501 | 138 | if address.version == 4 and netifaces.AF_INET in addresses: | ||
502 | 139 | addr = addresses[netifaces.AF_INET][0]['addr'] | ||
503 | 140 | netmask = addresses[netifaces.AF_INET][0]['netmask'] | ||
504 | 141 | cidr = netaddr.IPNetwork("%s/%s" % (addr, netmask)) | ||
505 | 142 | if address in cidr: | ||
506 | 143 | if key == 'iface': | ||
507 | 144 | return iface | ||
508 | 145 | else: | ||
509 | 146 | return addresses[netifaces.AF_INET][0][key] | ||
510 | 147 | if address.version == 6 and netifaces.AF_INET6 in addresses: | ||
511 | 148 | for addr in addresses[netifaces.AF_INET6]: | ||
512 | 149 | if not addr['addr'].startswith('fe80'): | ||
513 | 150 | cidr = netaddr.IPNetwork("%s/%s" % (addr['addr'], | ||
514 | 151 | addr['netmask'])) | ||
515 | 152 | if address in cidr: | ||
516 | 153 | if key == 'iface': | ||
517 | 154 | return iface | ||
518 | 155 | else: | ||
519 | 156 | return addr[key] | ||
520 | 157 | return None | ||
521 | 158 | |||
522 | 159 | |||
523 | 160 | get_iface_for_address = partial(_get_for_address, key='iface') | ||
524 | 161 | |||
525 | 162 | get_netmask_for_address = partial(_get_for_address, key='netmask') | ||
526 | 163 | |||
527 | 164 | |||
528 | 165 | def format_ipv6_addr(address): | ||
529 | 166 | """ | ||
530 | 167 | IPv6 needs to be wrapped with [] in url link to parse correctly. | ||
531 | 168 | """ | ||
532 | 169 | if is_ipv6(address): | ||
533 | 170 | address = "[%s]" % address | ||
534 | 171 | else: | ||
535 | 172 | log("Not a valid ipv6 address: %s" % address, level=WARNING) | ||
536 | 173 | address = None | ||
537 | 174 | |||
538 | 175 | return address | ||
539 | 176 | |||
540 | 177 | |||
541 | 178 | def get_iface_addr(iface='eth0', inet_type='AF_INET', inc_aliases=False, | ||
542 | 179 | fatal=True, exc_list=None): | ||
543 | 180 | """ | ||
544 | 181 | Return the assigned IP address for a given interface, if any, or []. | ||
545 | 182 | """ | ||
546 | 183 | # Extract nic if passed /dev/ethX | ||
547 | 184 | if '/' in iface: | ||
548 | 185 | iface = iface.split('/')[-1] | ||
549 | 186 | if not exc_list: | ||
550 | 187 | exc_list = [] | ||
551 | 188 | try: | ||
552 | 189 | inet_num = getattr(netifaces, inet_type) | ||
553 | 190 | except AttributeError: | ||
554 | 191 | raise Exception('Unknown inet type ' + str(inet_type)) | ||
555 | 192 | |||
556 | 193 | interfaces = netifaces.interfaces() | ||
557 | 194 | if inc_aliases: | ||
558 | 195 | ifaces = [] | ||
559 | 196 | for _iface in interfaces: | ||
560 | 197 | if iface == _iface or _iface.split(':')[0] == iface: | ||
561 | 198 | ifaces.append(_iface) | ||
562 | 199 | if fatal and not ifaces: | ||
563 | 200 | raise Exception("Invalid interface '%s'" % iface) | ||
564 | 201 | ifaces.sort() | ||
565 | 202 | else: | ||
566 | 203 | if iface not in interfaces: | ||
567 | 204 | if fatal: | ||
568 | 205 | raise Exception("%s not found " % (iface)) | ||
569 | 206 | else: | ||
570 | 207 | return [] | ||
571 | 208 | else: | ||
572 | 209 | ifaces = [iface] | ||
573 | 210 | |||
574 | 211 | addresses = [] | ||
575 | 212 | for netiface in ifaces: | ||
576 | 213 | net_info = netifaces.ifaddresses(netiface) | ||
577 | 214 | if inet_num in net_info: | ||
578 | 215 | for entry in net_info[inet_num]: | ||
579 | 216 | if 'addr' in entry and entry['addr'] not in exc_list: | ||
580 | 217 | addresses.append(entry['addr']) | ||
581 | 218 | if fatal and not addresses: | ||
582 | 219 | raise Exception("Interface '%s' doesn't have any %s addresses." % | ||
583 | 220 | (iface, inet_type)) | ||
584 | 221 | return addresses | ||
585 | 222 | |||
586 | 223 | get_ipv4_addr = partial(get_iface_addr, inet_type='AF_INET') | ||
587 | 224 | |||
588 | 225 | |||
589 | 226 | def get_iface_from_addr(addr): | ||
590 | 227 | """Work out on which interface the provided address is configured.""" | ||
591 | 228 | for iface in netifaces.interfaces(): | ||
592 | 229 | addresses = netifaces.ifaddresses(iface) | ||
593 | 230 | for inet_type in addresses: | ||
594 | 231 | for _addr in addresses[inet_type]: | ||
595 | 232 | _addr = _addr['addr'] | ||
596 | 233 | # link local | ||
597 | 234 | ll_key = re.compile("(.+)%.*") | ||
598 | 235 | raw = re.match(ll_key, _addr) | ||
599 | 236 | if raw: | ||
600 | 237 | _addr = raw.group(1) | ||
601 | 238 | if _addr == addr: | ||
602 | 239 | log("Address '%s' is configured on iface '%s'" % | ||
603 | 240 | (addr, iface)) | ||
604 | 241 | return iface | ||
605 | 242 | |||
606 | 243 | msg = "Unable to infer net iface on which '%s' is configured" % (addr) | ||
607 | 244 | raise Exception(msg) | ||
608 | 245 | |||
609 | 246 | |||
610 | 247 | def sniff_iface(f): | ||
611 | 248 | """If no iface provided, inject net iface inferred from unit private | ||
612 | 249 | address. | ||
613 | 250 | """ | ||
614 | 251 | def iface_sniffer(*args, **kwargs): | ||
615 | 252 | if not kwargs.get('iface', None): | ||
616 | 253 | kwargs['iface'] = get_iface_from_addr(unit_get('private-address')) | ||
617 | 254 | |||
618 | 255 | return f(*args, **kwargs) | ||
619 | 256 | |||
620 | 257 | return iface_sniffer | ||
621 | 258 | |||
622 | 259 | |||
623 | 260 | @sniff_iface | ||
624 | 261 | def get_ipv6_addr(iface=None, inc_aliases=False, fatal=True, exc_list=None, | ||
625 | 262 | dynamic_only=True): | ||
626 | 263 | """Get assigned IPv6 address for a given interface. | ||
627 | 264 | |||
628 | 265 | Returns list of addresses found. If no address found, returns empty list. | ||
629 | 266 | |||
630 | 267 | If iface is None, we infer the current primary interface by doing a reverse | ||
631 | 268 | lookup on the unit private-address. | ||
632 | 269 | |||
633 | 270 | We currently only support scope global IPv6 addresses i.e. non-temporary | ||
634 | 271 | addresses. If no global IPv6 address is found, return the first one found | ||
635 | 272 | in the ipv6 address list. | ||
636 | 273 | """ | ||
637 | 274 | addresses = get_iface_addr(iface=iface, inet_type='AF_INET6', | ||
638 | 275 | inc_aliases=inc_aliases, fatal=fatal, | ||
639 | 276 | exc_list=exc_list) | ||
640 | 277 | |||
641 | 278 | if addresses: | ||
642 | 279 | global_addrs = [] | ||
643 | 280 | for addr in addresses: | ||
644 | 281 | key_scope_link_local = re.compile("^fe80::..(.+)%(.+)") | ||
645 | 282 | m = re.match(key_scope_link_local, addr) | ||
646 | 283 | if m: | ||
647 | 284 | eui_64_mac = m.group(1) | ||
648 | 285 | iface = m.group(2) | ||
649 | 286 | else: | ||
650 | 287 | global_addrs.append(addr) | ||
651 | 288 | |||
652 | 289 | if global_addrs: | ||
653 | 290 | # Make sure any found global addresses are not temporary | ||
654 | 291 | cmd = ['ip', 'addr', 'show', iface] | ||
655 | 292 | out = subprocess.check_output(cmd) | ||
656 | 293 | if dynamic_only: | ||
657 | 294 | key = re.compile("inet6 (.+)/[0-9]+ scope global dynamic.*") | ||
658 | 295 | else: | ||
659 | 296 | key = re.compile("inet6 (.+)/[0-9]+ scope global.*") | ||
660 | 297 | |||
661 | 298 | addrs = [] | ||
662 | 299 | for line in out.split('\n'): | ||
663 | 300 | line = line.strip() | ||
664 | 301 | m = re.match(key, line) | ||
665 | 302 | if m and 'temporary' not in line: | ||
666 | 303 | # Return the first valid address we find | ||
667 | 304 | for addr in global_addrs: | ||
668 | 305 | if m.group(1) == addr: | ||
669 | 306 | if not dynamic_only or \ | ||
670 | 307 | m.group(1).endswith(eui_64_mac): | ||
671 | 308 | addrs.append(addr) | ||
672 | 309 | |||
673 | 310 | if addrs: | ||
674 | 311 | return addrs | ||
675 | 312 | |||
676 | 313 | if fatal: | ||
677 | 314 | raise Exception("Interface '%s' doesn't have a scope global " | ||
678 | 315 | "non-temporary ipv6 address." % iface) | ||
679 | 316 | |||
680 | 317 | return [] | ||
681 | 318 | |||
682 | 319 | |||
683 | 320 | def get_bridges(vnic_dir='/sys/devices/virtual/net'): | ||
684 | 321 | """ | ||
685 | 322 | Return a list of bridges on the system or [] | ||
686 | 323 | """ | ||
687 | 324 | b_rgex = vnic_dir + '/*/bridge' | ||
688 | 325 | return [x.replace(vnic_dir, '').split('/')[1] for x in glob.glob(b_rgex)] | ||
689 | 326 | |||
690 | 327 | |||
691 | 328 | def get_bridge_nics(bridge, vnic_dir='/sys/devices/virtual/net'): | ||
692 | 329 | """ | ||
693 | 330 | Return a list of nics comprising a given bridge on the system or [] | ||
694 | 331 | """ | ||
695 | 332 | brif_rgex = "%s/%s/brif/*" % (vnic_dir, bridge) | ||
696 | 333 | return [x.split('/')[-1] for x in glob.glob(brif_rgex)] | ||
697 | 334 | |||
698 | 335 | |||
699 | 336 | def is_bridge_member(nic): | ||
700 | 337 | """ | ||
701 | 338 | Check if a given nic is a member of a bridge | ||
702 | 339 | """ | ||
703 | 340 | for bridge in get_bridges(): | ||
704 | 341 | if nic in get_bridge_nics(bridge): | ||
705 | 342 | return True | ||
706 | 343 | return False | ||
707 | 0 | 344 | ||
708 | === added directory 'hooks/charmhelpers/contrib/openstack/amulet' | |||
709 | === added file 'hooks/charmhelpers/contrib/openstack/amulet/__init__.py' | |||
710 | === added file 'hooks/charmhelpers/contrib/openstack/amulet/deployment.py' | |||
711 | --- hooks/charmhelpers/contrib/openstack/amulet/deployment.py 1970-01-01 00:00:00 +0000 | |||
712 | +++ hooks/charmhelpers/contrib/openstack/amulet/deployment.py 2014-10-06 15:38:41 +0000 | |||
713 | @@ -0,0 +1,94 @@ | |||
714 | 1 | from bzrlib.branch import Branch | ||
715 | 2 | import os | ||
716 | 3 | import re | ||
717 | 4 | from charmhelpers.contrib.amulet.deployment import ( | ||
718 | 5 | AmuletDeployment | ||
719 | 6 | ) | ||
720 | 7 | |||
721 | 8 | |||
722 | 9 | class OpenStackAmuletDeployment(AmuletDeployment): | ||
723 | 10 | """OpenStack amulet deployment. | ||
724 | 11 | |||
725 | 12 | This class inherits from AmuletDeployment and has additional support | ||
726 | 13 | that is specifically for use by OpenStack charms. | ||
727 | 14 | """ | ||
728 | 15 | |||
729 | 16 | def __init__(self, series=None, openstack=None, source=None): | ||
730 | 17 | """Initialize the deployment environment.""" | ||
731 | 18 | super(OpenStackAmuletDeployment, self).__init__(series) | ||
732 | 19 | self.openstack = openstack | ||
733 | 20 | self.source = source | ||
734 | 21 | |||
735 | 22 | def _is_dev_branch(self): | ||
736 | 23 | """Determine if branch being tested is a dev (i.e. next) branch.""" | ||
737 | 24 | branch = Branch.open(os.getcwd()) | ||
738 | 25 | parent = branch.get_parent() | ||
739 | 26 | pattern = re.compile("^.*/next/$") | ||
740 | 27 | if (pattern.match(parent)): | ||
741 | 28 | return True | ||
742 | 29 | else: | ||
743 | 30 | return False | ||
744 | 31 | |||
745 | 32 | def _determine_branch_locations(self, other_services): | ||
746 | 33 | """Determine the branch locations for the other services. | ||
747 | 34 | |||
748 | 35 | If the branch being tested is a dev branch, then determine the | ||
749 | 36 | development branch locations for the other services. Otherwise, | ||
750 | 37 | the default charm store branches will be used.""" | ||
751 | 38 | name = 0 | ||
752 | 39 | if self._is_dev_branch(): | ||
753 | 40 | updated_services = [] | ||
754 | 41 | for svc in other_services: | ||
755 | 42 | if svc[name] in ['mysql', 'mongodb', 'rabbitmq-server']: | ||
756 | 43 | location = 'lp:charms/{}'.format(svc[name]) | ||
757 | 44 | else: | ||
758 | 45 | temp = 'lp:~openstack-charmers/charms/trusty/{}/next' | ||
759 | 46 | location = temp.format(svc[name]) | ||
760 | 47 | updated_services.append(svc + (location,)) | ||
761 | 48 | other_services = updated_services | ||
762 | 49 | return other_services | ||
763 | 50 | |||
764 | 51 | def _add_services(self, this_service, other_services): | ||
765 | 52 | """Add services to the deployment and set openstack-origin/source.""" | ||
766 | 53 | name = 0 | ||
767 | 54 | other_services = self._determine_branch_locations(other_services) | ||
768 | 55 | super(OpenStackAmuletDeployment, self)._add_services(this_service, | ||
769 | 56 | other_services) | ||
770 | 57 | services = other_services | ||
771 | 58 | services.append(this_service) | ||
772 | 59 | use_source = ['mysql', 'mongodb', 'rabbitmq-server', 'ceph'] | ||
773 | 60 | |||
774 | 61 | if self.openstack: | ||
775 | 62 | for svc in services: | ||
776 | 63 | if svc[name] not in use_source: | ||
777 | 64 | config = {'openstack-origin': self.openstack} | ||
778 | 65 | self.d.configure(svc[name], config) | ||
779 | 66 | |||
780 | 67 | if self.source: | ||
781 | 68 | for svc in services: | ||
782 | 69 | if svc[name] in use_source: | ||
783 | 70 | config = {'source': self.source} | ||
784 | 71 | self.d.configure(svc[name], config) | ||
785 | 72 | |||
786 | 73 | def _configure_services(self, configs): | ||
787 | 74 | """Configure all of the services.""" | ||
788 | 75 | for service, config in configs.iteritems(): | ||
789 | 76 | self.d.configure(service, config) | ||
790 | 77 | |||
791 | 78 | def _get_openstack_release(self): | ||
792 | 79 | """Get openstack release. | ||
793 | 80 | |||
794 | 81 | Return an integer representing the enum value of the openstack | ||
795 | 82 | release. | ||
796 | 83 | """ | ||
797 | 84 | (self.precise_essex, self.precise_folsom, self.precise_grizzly, | ||
798 | 85 | self.precise_havana, self.precise_icehouse, | ||
799 | 86 | self.trusty_icehouse) = range(6) | ||
800 | 87 | releases = { | ||
801 | 88 | ('precise', None): self.precise_essex, | ||
802 | 89 | ('precise', 'cloud:precise-folsom'): self.precise_folsom, | ||
803 | 90 | ('precise', 'cloud:precise-grizzly'): self.precise_grizzly, | ||
804 | 91 | ('precise', 'cloud:precise-havana'): self.precise_havana, | ||
805 | 92 | ('precise', 'cloud:precise-icehouse'): self.precise_icehouse, | ||
806 | 93 | ('trusty', None): self.trusty_icehouse} | ||
807 | 94 | return releases[(self.series, self.openstack)] | ||
808 | 0 | 95 | ||
809 | === added file 'hooks/charmhelpers/contrib/openstack/amulet/utils.py' | |||
810 | --- hooks/charmhelpers/contrib/openstack/amulet/utils.py 1970-01-01 00:00:00 +0000 | |||
811 | +++ hooks/charmhelpers/contrib/openstack/amulet/utils.py 2014-10-06 15:38:41 +0000 | |||
812 | @@ -0,0 +1,276 @@ | |||
813 | 1 | import logging | ||
814 | 2 | import os | ||
815 | 3 | import time | ||
816 | 4 | import urllib | ||
817 | 5 | |||
818 | 6 | import glanceclient.v1.client as glance_client | ||
819 | 7 | import keystoneclient.v2_0 as keystone_client | ||
820 | 8 | import novaclient.v1_1.client as nova_client | ||
821 | 9 | |||
822 | 10 | from charmhelpers.contrib.amulet.utils import ( | ||
823 | 11 | AmuletUtils | ||
824 | 12 | ) | ||
825 | 13 | |||
826 | 14 | DEBUG = logging.DEBUG | ||
827 | 15 | ERROR = logging.ERROR | ||
828 | 16 | |||
829 | 17 | |||
830 | 18 | class OpenStackAmuletUtils(AmuletUtils): | ||
831 | 19 | """OpenStack amulet utilities. | ||
832 | 20 | |||
833 | 21 | This class inherits from AmuletUtils and has additional support | ||
834 | 22 | that is specifically for use by OpenStack charms. | ||
835 | 23 | """ | ||
836 | 24 | |||
837 | 25 | def __init__(self, log_level=ERROR): | ||
838 | 26 | """Initialize the deployment environment.""" | ||
839 | 27 | super(OpenStackAmuletUtils, self).__init__(log_level) | ||
840 | 28 | |||
841 | 29 | def validate_endpoint_data(self, endpoints, admin_port, internal_port, | ||
842 | 30 | public_port, expected): | ||
843 | 31 | """Validate endpoint data. | ||
844 | 32 | |||
845 | 33 | Validate actual endpoint data vs expected endpoint data. The ports | ||
846 | 34 | are used to find the matching endpoint. | ||
847 | 35 | """ | ||
848 | 36 | found = False | ||
849 | 37 | for ep in endpoints: | ||
850 | 38 | self.log.debug('endpoint: {}'.format(repr(ep))) | ||
851 | 39 | if (admin_port in ep.adminurl and | ||
852 | 40 | internal_port in ep.internalurl and | ||
853 | 41 | public_port in ep.publicurl): | ||
854 | 42 | found = True | ||
855 | 43 | actual = {'id': ep.id, | ||
856 | 44 | 'region': ep.region, | ||
857 | 45 | 'adminurl': ep.adminurl, | ||
858 | 46 | 'internalurl': ep.internalurl, | ||
859 | 47 | 'publicurl': ep.publicurl, | ||
860 | 48 | 'service_id': ep.service_id} | ||
861 | 49 | ret = self._validate_dict_data(expected, actual) | ||
862 | 50 | if ret: | ||
863 | 51 | return 'unexpected endpoint data - {}'.format(ret) | ||
864 | 52 | |||
865 | 53 | if not found: | ||
866 | 54 | return 'endpoint not found' | ||
867 | 55 | |||
868 | 56 | def validate_svc_catalog_endpoint_data(self, expected, actual): | ||
869 | 57 | """Validate service catalog endpoint data. | ||
870 | 58 | |||
871 | 59 | Validate a list of actual service catalog endpoints vs a list of | ||
872 | 60 | expected service catalog endpoints. | ||
873 | 61 | """ | ||
874 | 62 | self.log.debug('actual: {}'.format(repr(actual))) | ||
875 | 63 | for k, v in expected.iteritems(): | ||
876 | 64 | if k in actual: | ||
877 | 65 | ret = self._validate_dict_data(expected[k][0], actual[k][0]) | ||
878 | 66 | if ret: | ||
879 | 67 | return self.endpoint_error(k, ret) | ||
880 | 68 | else: | ||
881 | 69 | return "endpoint {} does not exist".format(k) | ||
882 | 70 | return ret | ||
883 | 71 | |||
884 | 72 | def validate_tenant_data(self, expected, actual): | ||
885 | 73 | """Validate tenant data. | ||
886 | 74 | |||
887 | 75 | Validate a list of actual tenant data vs list of expected tenant | ||
888 | 76 | data. | ||
889 | 77 | """ | ||
890 | 78 | self.log.debug('actual: {}'.format(repr(actual))) | ||
891 | 79 | for e in expected: | ||
892 | 80 | found = False | ||
893 | 81 | for act in actual: | ||
894 | 82 | a = {'enabled': act.enabled, 'description': act.description, | ||
895 | 83 | 'name': act.name, 'id': act.id} | ||
896 | 84 | if e['name'] == a['name']: | ||
897 | 85 | found = True | ||
898 | 86 | ret = self._validate_dict_data(e, a) | ||
899 | 87 | if ret: | ||
900 | 88 | return "unexpected tenant data - {}".format(ret) | ||
901 | 89 | if not found: | ||
902 | 90 | return "tenant {} does not exist".format(e['name']) | ||
903 | 91 | return ret | ||
904 | 92 | |||
905 | 93 | def validate_role_data(self, expected, actual): | ||
906 | 94 | """Validate role data. | ||
907 | 95 | |||
908 | 96 | Validate a list of actual role data vs a list of expected role | ||
909 | 97 | data. | ||
910 | 98 | """ | ||
911 | 99 | self.log.debug('actual: {}'.format(repr(actual))) | ||
912 | 100 | for e in expected: | ||
913 | 101 | found = False | ||
914 | 102 | for act in actual: | ||
915 | 103 | a = {'name': act.name, 'id': act.id} | ||
916 | 104 | if e['name'] == a['name']: | ||
917 | 105 | found = True | ||
918 | 106 | ret = self._validate_dict_data(e, a) | ||
919 | 107 | if ret: | ||
920 | 108 | return "unexpected role data - {}".format(ret) | ||
921 | 109 | if not found: | ||
922 | 110 | return "role {} does not exist".format(e['name']) | ||
923 | 111 | return ret | ||
924 | 112 | |||
925 | 113 | def validate_user_data(self, expected, actual): | ||
926 | 114 | """Validate user data. | ||
927 | 115 | |||
928 | 116 | Validate a list of actual user data vs a list of expected user | ||
929 | 117 | data. | ||
930 | 118 | """ | ||
931 | 119 | self.log.debug('actual: {}'.format(repr(actual))) | ||
932 | 120 | for e in expected: | ||
933 | 121 | found = False | ||
934 | 122 | for act in actual: | ||
935 | 123 | a = {'enabled': act.enabled, 'name': act.name, | ||
936 | 124 | 'email': act.email, 'tenantId': act.tenantId, | ||
937 | 125 | 'id': act.id} | ||
938 | 126 | if e['name'] == a['name']: | ||
939 | 127 | found = True | ||
940 | 128 | ret = self._validate_dict_data(e, a) | ||
941 | 129 | if ret: | ||
942 | 130 | return "unexpected user data - {}".format(ret) | ||
943 | 131 | if not found: | ||
944 | 132 | return "user {} does not exist".format(e['name']) | ||
945 | 133 | return ret | ||
946 | 134 | |||
947 | 135 | def validate_flavor_data(self, expected, actual): | ||
948 | 136 | """Validate flavor data. | ||
949 | 137 | |||
950 | 138 | Validate a list of actual flavors vs a list of expected flavors. | ||
951 | 139 | """ | ||
952 | 140 | self.log.debug('actual: {}'.format(repr(actual))) | ||
953 | 141 | act = [a.name for a in actual] | ||
954 | 142 | return self._validate_list_data(expected, act) | ||
955 | 143 | |||
956 | 144 | def tenant_exists(self, keystone, tenant): | ||
957 | 145 | """Return True if tenant exists.""" | ||
958 | 146 | return tenant in [t.name for t in keystone.tenants.list()] | ||
959 | 147 | |||
960 | 148 | def authenticate_keystone_admin(self, keystone_sentry, user, password, | ||
961 | 149 | tenant): | ||
962 | 150 | """Authenticates admin user with the keystone admin endpoint.""" | ||
963 | 151 | unit = keystone_sentry | ||
964 | 152 | service_ip = unit.relation('shared-db', | ||
965 | 153 | 'mysql:shared-db')['private-address'] | ||
966 | 154 | ep = "http://{}:35357/v2.0".format(service_ip.strip().decode('utf-8')) | ||
967 | 155 | return keystone_client.Client(username=user, password=password, | ||
968 | 156 | tenant_name=tenant, auth_url=ep) | ||
969 | 157 | |||
970 | 158 | def authenticate_keystone_user(self, keystone, user, password, tenant): | ||
971 | 159 | """Authenticates a regular user with the keystone public endpoint.""" | ||
972 | 160 | ep = keystone.service_catalog.url_for(service_type='identity', | ||
973 | 161 | endpoint_type='publicURL') | ||
974 | 162 | return keystone_client.Client(username=user, password=password, | ||
975 | 163 | tenant_name=tenant, auth_url=ep) | ||
976 | 164 | |||
977 | 165 | def authenticate_glance_admin(self, keystone): | ||
978 | 166 | """Authenticates admin user with glance.""" | ||
979 | 167 | ep = keystone.service_catalog.url_for(service_type='image', | ||
980 | 168 | endpoint_type='adminURL') | ||
981 | 169 | return glance_client.Client(ep, token=keystone.auth_token) | ||
982 | 170 | |||
983 | 171 | def authenticate_nova_user(self, keystone, user, password, tenant): | ||
984 | 172 | """Authenticates a regular user with nova-api.""" | ||
985 | 173 | ep = keystone.service_catalog.url_for(service_type='identity', | ||
986 | 174 | endpoint_type='publicURL') | ||
987 | 175 | return nova_client.Client(username=user, api_key=password, | ||
988 | 176 | project_id=tenant, auth_url=ep) | ||
989 | 177 | |||
990 | 178 | def create_cirros_image(self, glance, image_name): | ||
991 | 179 | """Download the latest cirros image and upload it to glance.""" | ||
992 | 180 | http_proxy = os.getenv('AMULET_HTTP_PROXY') | ||
993 | 181 | self.log.debug('AMULET_HTTP_PROXY: {}'.format(http_proxy)) | ||
994 | 182 | if http_proxy: | ||
995 | 183 | proxies = {'http': http_proxy} | ||
996 | 184 | opener = urllib.FancyURLopener(proxies) | ||
997 | 185 | else: | ||
998 | 186 | opener = urllib.FancyURLopener() | ||
999 | 187 | |||
1000 | 188 | f = opener.open("http://download.cirros-cloud.net/version/released") | ||
1001 | 189 | version = f.read().strip() | ||
1002 | 190 | cirros_img = "cirros-{}-x86_64-disk.img".format(version) | ||
1003 | 191 | local_path = os.path.join('tests', cirros_img) | ||
1004 | 192 | |||
1005 | 193 | if not os.path.exists(local_path): | ||
1006 | 194 | cirros_url = "http://{}/{}/{}".format("download.cirros-cloud.net", | ||
1007 | 195 | version, cirros_img) | ||
1008 | 196 | opener.retrieve(cirros_url, local_path) | ||
1009 | 197 | f.close() | ||
1010 | 198 | |||
1011 | 199 | with open(local_path) as f: | ||
1012 | 200 | image = glance.images.create(name=image_name, is_public=True, | ||
1013 | 201 | disk_format='qcow2', | ||
1014 | 202 | container_format='bare', data=f) | ||
1015 | 203 | count = 1 | ||
1016 | 204 | status = image.status | ||
1017 | 205 | while status != 'active' and count < 10: | ||
1018 | 206 | time.sleep(3) | ||
1019 | 207 | image = glance.images.get(image.id) | ||
1020 | 208 | status = image.status | ||
1021 | 209 | self.log.debug('image status: {}'.format(status)) | ||
1022 | 210 | count += 1 | ||
1023 | 211 | |||
1024 | 212 | if status != 'active': | ||
1025 | 213 | self.log.error('image creation timed out') | ||
1026 | 214 | return None | ||
1027 | 215 | |||
1028 | 216 | return image | ||
1029 | 217 | |||
1030 | 218 | def delete_image(self, glance, image): | ||
1031 | 219 | """Delete the specified image.""" | ||
1032 | 220 | num_before = len(list(glance.images.list())) | ||
1033 | 221 | glance.images.delete(image) | ||
1034 | 222 | |||
1035 | 223 | count = 1 | ||
1036 | 224 | num_after = len(list(glance.images.list())) | ||
1037 | 225 | while num_after != (num_before - 1) and count < 10: | ||
1038 | 226 | time.sleep(3) | ||
1039 | 227 | num_after = len(list(glance.images.list())) | ||
1040 | 228 | self.log.debug('number of images: {}'.format(num_after)) | ||
1041 | 229 | count += 1 | ||
1042 | 230 | |||
1043 | 231 | if num_after != (num_before - 1): | ||
1044 | 232 | self.log.error('image deletion timed out') | ||
1045 | 233 | return False | ||
1046 | 234 | |||
1047 | 235 | return True | ||
1048 | 236 | |||
1049 | 237 | def create_instance(self, nova, image_name, instance_name, flavor): | ||
1050 | 238 | """Create the specified instance.""" | ||
1051 | 239 | image = nova.images.find(name=image_name) | ||
1052 | 240 | flavor = nova.flavors.find(name=flavor) | ||
1053 | 241 | instance = nova.servers.create(name=instance_name, image=image, | ||
1054 | 242 | flavor=flavor) | ||
1055 | 243 | |||
1056 | 244 | count = 1 | ||
1057 | 245 | status = instance.status | ||
1058 | 246 | while status != 'ACTIVE' and count < 60: | ||
1059 | 247 | time.sleep(3) | ||
1060 | 248 | instance = nova.servers.get(instance.id) | ||
1061 | 249 | status = instance.status | ||
1062 | 250 | self.log.debug('instance status: {}'.format(status)) | ||
1063 | 251 | count += 1 | ||
1064 | 252 | |||
1065 | 253 | if status != 'ACTIVE': | ||
1066 | 254 | self.log.error('instance creation timed out') | ||
1067 | 255 | return None | ||
1068 | 256 | |||
1069 | 257 | return instance | ||
1070 | 258 | |||
1071 | 259 | def delete_instance(self, nova, instance): | ||
1072 | 260 | """Delete the specified instance.""" | ||
1073 | 261 | num_before = len(list(nova.servers.list())) | ||
1074 | 262 | nova.servers.delete(instance) | ||
1075 | 263 | |||
1076 | 264 | count = 1 | ||
1077 | 265 | num_after = len(list(nova.servers.list())) | ||
1078 | 266 | while num_after != (num_before - 1) and count < 10: | ||
1079 | 267 | time.sleep(3) | ||
1080 | 268 | num_after = len(list(nova.servers.list())) | ||
1081 | 269 | self.log.debug('number of instances: {}'.format(num_after)) | ||
1082 | 270 | count += 1 | ||
1083 | 271 | |||
1084 | 272 | if num_after != (num_before - 1): | ||
1085 | 273 | self.log.error('instance deletion timed out') | ||
1086 | 274 | return False | ||
1087 | 275 | |||
1088 | 276 | return True | ||
1089 | 0 | 277 | ||
1090 | === modified file 'hooks/charmhelpers/contrib/openstack/context.py' | |||
1091 | --- hooks/charmhelpers/contrib/openstack/context.py 2014-08-13 15:57:07 +0000 | |||
1092 | +++ hooks/charmhelpers/contrib/openstack/context.py 2014-10-06 15:38:41 +0000 | |||
1093 | @@ -8,7 +8,6 @@ | |||
1094 | 8 | check_call | 8 | check_call |
1095 | 9 | ) | 9 | ) |
1096 | 10 | 10 | ||
1097 | 11 | |||
1098 | 12 | from charmhelpers.fetch import ( | 11 | from charmhelpers.fetch import ( |
1099 | 13 | apt_install, | 12 | apt_install, |
1100 | 14 | filter_installed_packages, | 13 | filter_installed_packages, |
1101 | @@ -21,10 +20,20 @@ | |||
1102 | 21 | relation_get, | 20 | relation_get, |
1103 | 22 | relation_ids, | 21 | relation_ids, |
1104 | 23 | related_units, | 22 | related_units, |
1105 | 23 | relation_set, | ||
1106 | 24 | unit_get, | 24 | unit_get, |
1107 | 25 | unit_private_ip, | 25 | unit_private_ip, |
1108 | 26 | ERROR, | 26 | ERROR, |
1110 | 27 | INFO | 27 | <<<<<<< TREE |
1111 | 28 | INFO | ||
1112 | 29 | ======= | ||
1113 | 30 | INFO | ||
1114 | 31 | ) | ||
1115 | 32 | |||
1116 | 33 | from charmhelpers.core.host import ( | ||
1117 | 34 | mkdir, | ||
1118 | 35 | write_file | ||
1119 | 36 | >>>>>>> MERGE-SOURCE | ||
1120 | 28 | ) | 37 | ) |
1121 | 29 | 38 | ||
1122 | 30 | from charmhelpers.contrib.hahelpers.cluster import ( | 39 | from charmhelpers.contrib.hahelpers.cluster import ( |
1123 | @@ -37,12 +46,20 @@ | |||
1124 | 37 | from charmhelpers.contrib.hahelpers.apache import ( | 46 | from charmhelpers.contrib.hahelpers.apache import ( |
1125 | 38 | get_cert, | 47 | get_cert, |
1126 | 39 | get_ca_cert, | 48 | get_ca_cert, |
1127 | 49 | install_ca_cert, | ||
1128 | 40 | ) | 50 | ) |
1129 | 41 | 51 | ||
1130 | 42 | from charmhelpers.contrib.openstack.neutron import ( | 52 | from charmhelpers.contrib.openstack.neutron import ( |
1131 | 43 | neutron_plugin_attribute, | 53 | neutron_plugin_attribute, |
1132 | 44 | ) | 54 | ) |
1133 | 45 | 55 | ||
1134 | 56 | from charmhelpers.contrib.network.ip import ( | ||
1135 | 57 | get_address_in_network, | ||
1136 | 58 | get_ipv6_addr, | ||
1137 | 59 | format_ipv6_addr, | ||
1138 | 60 | is_address_in_network | ||
1139 | 61 | ) | ||
1140 | 62 | |||
1141 | 46 | CA_CERT_PATH = '/usr/local/share/ca-certificates/keystone_juju_ca_cert.crt' | 63 | CA_CERT_PATH = '/usr/local/share/ca-certificates/keystone_juju_ca_cert.crt' |
1142 | 47 | 64 | ||
1143 | 48 | 65 | ||
1144 | @@ -135,8 +152,26 @@ | |||
1145 | 135 | 'Missing required charm config options. ' | 152 | 'Missing required charm config options. ' |
1146 | 136 | '(database name and user)') | 153 | '(database name and user)') |
1147 | 137 | raise OSContextError | 154 | raise OSContextError |
1148 | 155 | |||
1149 | 138 | ctxt = {} | 156 | ctxt = {} |
1150 | 139 | 157 | ||
1151 | 158 | # NOTE(jamespage) if mysql charm provides a network upon which | ||
1152 | 159 | # access to the database should be made, reconfigure relation | ||
1153 | 160 | # with the service units local address and defer execution | ||
1154 | 161 | access_network = relation_get('access-network') | ||
1155 | 162 | if access_network is not None: | ||
1156 | 163 | if self.relation_prefix is not None: | ||
1157 | 164 | hostname_key = "{}_hostname".format(self.relation_prefix) | ||
1158 | 165 | else: | ||
1159 | 166 | hostname_key = "hostname" | ||
1160 | 167 | access_hostname = get_address_in_network(access_network, | ||
1161 | 168 | unit_get('private-address')) | ||
1162 | 169 | set_hostname = relation_get(attribute=hostname_key, | ||
1163 | 170 | unit=local_unit()) | ||
1164 | 171 | if set_hostname != access_hostname: | ||
1165 | 172 | relation_set(relation_settings={hostname_key: access_hostname}) | ||
1166 | 173 | return ctxt # Defer any further hook execution for now.... | ||
1167 | 174 | |||
1168 | 140 | password_setting = 'password' | 175 | password_setting = 'password' |
1169 | 141 | if self.relation_prefix: | 176 | if self.relation_prefix: |
1170 | 142 | password_setting = self.relation_prefix + '_password' | 177 | password_setting = self.relation_prefix + '_password' |
1171 | @@ -144,8 +179,10 @@ | |||
1172 | 144 | for rid in relation_ids('shared-db'): | 179 | for rid in relation_ids('shared-db'): |
1173 | 145 | for unit in related_units(rid): | 180 | for unit in related_units(rid): |
1174 | 146 | rdata = relation_get(rid=rid, unit=unit) | 181 | rdata = relation_get(rid=rid, unit=unit) |
1175 | 182 | host = rdata.get('db_host') | ||
1176 | 183 | host = format_ipv6_addr(host) or host | ||
1177 | 147 | ctxt = { | 184 | ctxt = { |
1179 | 148 | 'database_host': rdata.get('db_host'), | 185 | 'database_host': host, |
1180 | 149 | 'database': self.database, | 186 | 'database': self.database, |
1181 | 150 | 'database_user': self.user, | 187 | 'database_user': self.user, |
1182 | 151 | 'database_password': rdata.get(password_setting), | 188 | 'database_password': rdata.get(password_setting), |
1183 | @@ -221,10 +258,15 @@ | |||
1184 | 221 | for rid in relation_ids('identity-service'): | 258 | for rid in relation_ids('identity-service'): |
1185 | 222 | for unit in related_units(rid): | 259 | for unit in related_units(rid): |
1186 | 223 | rdata = relation_get(rid=rid, unit=unit) | 260 | rdata = relation_get(rid=rid, unit=unit) |
1187 | 261 | serv_host = rdata.get('service_host') | ||
1188 | 262 | serv_host = format_ipv6_addr(serv_host) or serv_host | ||
1189 | 263 | auth_host = rdata.get('auth_host') | ||
1190 | 264 | auth_host = format_ipv6_addr(auth_host) or auth_host | ||
1191 | 265 | |||
1192 | 224 | ctxt = { | 266 | ctxt = { |
1193 | 225 | 'service_port': rdata.get('service_port'), | 267 | 'service_port': rdata.get('service_port'), |
1196 | 226 | 'service_host': rdata.get('service_host'), | 268 | 'service_host': serv_host, |
1197 | 227 | 'auth_host': rdata.get('auth_host'), | 269 | 'auth_host': auth_host, |
1198 | 228 | 'auth_port': rdata.get('auth_port'), | 270 | 'auth_port': rdata.get('auth_port'), |
1199 | 229 | 'admin_tenant_name': rdata.get('service_tenant'), | 271 | 'admin_tenant_name': rdata.get('service_tenant'), |
1200 | 230 | 'admin_user': rdata.get('service_username'), | 272 | 'admin_user': rdata.get('service_username'), |
1201 | @@ -244,32 +286,42 @@ | |||
1202 | 244 | 286 | ||
1203 | 245 | 287 | ||
1204 | 246 | class AMQPContext(OSContextGenerator): | 288 | class AMQPContext(OSContextGenerator): |
1205 | 247 | interfaces = ['amqp'] | ||
1206 | 248 | 289 | ||
1208 | 249 | def __init__(self, ssl_dir=None): | 290 | def __init__(self, ssl_dir=None, rel_name='amqp', relation_prefix=None): |
1209 | 250 | self.ssl_dir = ssl_dir | 291 | self.ssl_dir = ssl_dir |
1210 | 292 | self.rel_name = rel_name | ||
1211 | 293 | self.relation_prefix = relation_prefix | ||
1212 | 294 | self.interfaces = [rel_name] | ||
1213 | 251 | 295 | ||
1214 | 252 | def __call__(self): | 296 | def __call__(self): |
1215 | 253 | log('Generating template context for amqp') | 297 | log('Generating template context for amqp') |
1216 | 254 | conf = config() | 298 | conf = config() |
1217 | 299 | user_setting = 'rabbit-user' | ||
1218 | 300 | vhost_setting = 'rabbit-vhost' | ||
1219 | 301 | if self.relation_prefix: | ||
1220 | 302 | user_setting = self.relation_prefix + '-rabbit-user' | ||
1221 | 303 | vhost_setting = self.relation_prefix + '-rabbit-vhost' | ||
1222 | 304 | |||
1223 | 255 | try: | 305 | try: |
1226 | 256 | username = conf['rabbit-user'] | 306 | username = conf[user_setting] |
1227 | 257 | vhost = conf['rabbit-vhost'] | 307 | vhost = conf[vhost_setting] |
1228 | 258 | except KeyError as e: | 308 | except KeyError as e: |
1229 | 259 | log('Could not generate shared_db context. ' | 309 | log('Could not generate shared_db context. ' |
1230 | 260 | 'Missing required charm config options: %s.' % e) | 310 | 'Missing required charm config options: %s.' % e) |
1231 | 261 | raise OSContextError | 311 | raise OSContextError |
1232 | 262 | ctxt = {} | 312 | ctxt = {} |
1234 | 263 | for rid in relation_ids('amqp'): | 313 | for rid in relation_ids(self.rel_name): |
1235 | 264 | ha_vip_only = False | 314 | ha_vip_only = False |
1236 | 265 | for unit in related_units(rid): | 315 | for unit in related_units(rid): |
1237 | 266 | if relation_get('clustered', rid=rid, unit=unit): | 316 | if relation_get('clustered', rid=rid, unit=unit): |
1238 | 267 | ctxt['clustered'] = True | 317 | ctxt['clustered'] = True |
1241 | 268 | ctxt['rabbitmq_host'] = relation_get('vip', rid=rid, | 318 | vip = relation_get('vip', rid=rid, unit=unit) |
1242 | 269 | unit=unit) | 319 | vip = format_ipv6_addr(vip) or vip |
1243 | 320 | ctxt['rabbitmq_host'] = vip | ||
1244 | 270 | else: | 321 | else: |
1247 | 271 | ctxt['rabbitmq_host'] = relation_get('private-address', | 322 | host = relation_get('private-address', rid=rid, unit=unit) |
1248 | 272 | rid=rid, unit=unit) | 323 | host = format_ipv6_addr(host) or host |
1249 | 324 | ctxt['rabbitmq_host'] = host | ||
1250 | 273 | ctxt.update({ | 325 | ctxt.update({ |
1251 | 274 | 'rabbitmq_user': username, | 326 | 'rabbitmq_user': username, |
1252 | 275 | 'rabbitmq_password': relation_get('password', rid=rid, | 327 | 'rabbitmq_password': relation_get('password', rid=rid, |
1253 | @@ -308,8 +360,9 @@ | |||
1254 | 308 | and len(related_units(rid)) > 1: | 360 | and len(related_units(rid)) > 1: |
1255 | 309 | rabbitmq_hosts = [] | 361 | rabbitmq_hosts = [] |
1256 | 310 | for unit in related_units(rid): | 362 | for unit in related_units(rid): |
1259 | 311 | rabbitmq_hosts.append(relation_get('private-address', | 363 | host = relation_get('private-address', rid=rid, unit=unit) |
1260 | 312 | rid=rid, unit=unit)) | 364 | host = format_ipv6_addr(host) or host |
1261 | 365 | rabbitmq_hosts.append(host) | ||
1262 | 313 | ctxt['rabbitmq_hosts'] = ','.join(rabbitmq_hosts) | 366 | ctxt['rabbitmq_hosts'] = ','.join(rabbitmq_hosts) |
1263 | 314 | if not context_complete(ctxt): | 367 | if not context_complete(ctxt): |
1264 | 315 | return {} | 368 | return {} |
1265 | @@ -333,10 +386,13 @@ | |||
1266 | 333 | use_syslog = str(config('use-syslog')).lower() | 386 | use_syslog = str(config('use-syslog')).lower() |
1267 | 334 | for rid in relation_ids('ceph'): | 387 | for rid in relation_ids('ceph'): |
1268 | 335 | for unit in related_units(rid): | 388 | for unit in related_units(rid): |
1269 | 336 | mon_hosts.append(relation_get('private-address', rid=rid, | ||
1270 | 337 | unit=unit)) | ||
1271 | 338 | auth = relation_get('auth', rid=rid, unit=unit) | 389 | auth = relation_get('auth', rid=rid, unit=unit) |
1272 | 339 | key = relation_get('key', rid=rid, unit=unit) | 390 | key = relation_get('key', rid=rid, unit=unit) |
1273 | 391 | ceph_addr = \ | ||
1274 | 392 | relation_get('ceph-public-address', rid=rid, unit=unit) or \ | ||
1275 | 393 | relation_get('private-address', rid=rid, unit=unit) | ||
1276 | 394 | ceph_addr = format_ipv6_addr(ceph_addr) or ceph_addr | ||
1277 | 395 | mon_hosts.append(ceph_addr) | ||
1278 | 340 | 396 | ||
1279 | 341 | ctxt = { | 397 | ctxt = { |
1280 | 342 | 'mon_hosts': ' '.join(mon_hosts), | 398 | 'mon_hosts': ' '.join(mon_hosts), |
1281 | @@ -370,7 +426,14 @@ | |||
1282 | 370 | 426 | ||
1283 | 371 | cluster_hosts = {} | 427 | cluster_hosts = {} |
1284 | 372 | l_unit = local_unit().replace('/', '-') | 428 | l_unit = local_unit().replace('/', '-') |
1286 | 373 | cluster_hosts[l_unit] = unit_get('private-address') | 429 | |
1287 | 430 | if config('prefer-ipv6'): | ||
1288 | 431 | addr = get_ipv6_addr(exc_list=[config('vip')])[0] | ||
1289 | 432 | else: | ||
1290 | 433 | addr = unit_get('private-address') | ||
1291 | 434 | |||
1292 | 435 | cluster_hosts[l_unit] = get_address_in_network(config('os-internal-network'), | ||
1293 | 436 | addr) | ||
1294 | 374 | 437 | ||
1295 | 375 | for rid in relation_ids('cluster'): | 438 | for rid in relation_ids('cluster'): |
1296 | 376 | for unit in related_units(rid): | 439 | for unit in related_units(rid): |
1297 | @@ -381,6 +444,21 @@ | |||
1298 | 381 | ctxt = { | 444 | ctxt = { |
1299 | 382 | 'units': cluster_hosts, | 445 | 'units': cluster_hosts, |
1300 | 383 | } | 446 | } |
1301 | 447 | |||
1302 | 448 | if config('haproxy-server-timeout'): | ||
1303 | 449 | ctxt['haproxy_server_timeout'] = config('haproxy-server-timeout') | ||
1304 | 450 | if config('haproxy-client-timeout'): | ||
1305 | 451 | ctxt['haproxy_client_timeout'] = config('haproxy-client-timeout') | ||
1306 | 452 | |||
1307 | 453 | if config('prefer-ipv6'): | ||
1308 | 454 | ctxt['local_host'] = 'ip6-localhost' | ||
1309 | 455 | ctxt['haproxy_host'] = '::' | ||
1310 | 456 | ctxt['stat_port'] = ':::8888' | ||
1311 | 457 | else: | ||
1312 | 458 | ctxt['local_host'] = '127.0.0.1' | ||
1313 | 459 | ctxt['haproxy_host'] = '0.0.0.0' | ||
1314 | 460 | ctxt['stat_port'] = ':8888' | ||
1315 | 461 | |||
1316 | 384 | if len(cluster_hosts.keys()) > 1: | 462 | if len(cluster_hosts.keys()) > 1: |
1317 | 385 | # Enable haproxy when we have enough peers. | 463 | # Enable haproxy when we have enough peers. |
1318 | 386 | log('Ensuring haproxy enabled in /etc/default/haproxy.') | 464 | log('Ensuring haproxy enabled in /etc/default/haproxy.') |
1319 | @@ -419,12 +497,13 @@ | |||
1320 | 419 | """ | 497 | """ |
1321 | 420 | Generates a context for an apache vhost configuration that configures | 498 | Generates a context for an apache vhost configuration that configures |
1322 | 421 | HTTPS reverse proxying for one or many endpoints. Generated context | 499 | HTTPS reverse proxying for one or many endpoints. Generated context |
1329 | 422 | looks something like: | 500 | looks something like:: |
1330 | 423 | { | 501 | |
1331 | 424 | 'namespace': 'cinder', | 502 | { |
1332 | 425 | 'private_address': 'iscsi.mycinderhost.com', | 503 | 'namespace': 'cinder', |
1333 | 426 | 'endpoints': [(8776, 8766), (8777, 8767)] | 504 | 'private_address': 'iscsi.mycinderhost.com', |
1334 | 427 | } | 505 | 'endpoints': [(8776, 8766), (8777, 8767)] |
1335 | 506 | } | ||
1336 | 428 | 507 | ||
1337 | 429 | The endpoints list consists of a tuples mapping external ports | 508 | The endpoints list consists of a tuples mapping external ports |
1338 | 430 | to internal ports. | 509 | to internal ports. |
1339 | @@ -440,22 +519,36 @@ | |||
1340 | 440 | cmd = ['a2enmod', 'ssl', 'proxy', 'proxy_http'] | 519 | cmd = ['a2enmod', 'ssl', 'proxy', 'proxy_http'] |
1341 | 441 | check_call(cmd) | 520 | check_call(cmd) |
1342 | 442 | 521 | ||
1346 | 443 | def configure_cert(self): | 522 | def configure_cert(self, cn=None): |
1344 | 444 | if not os.path.isdir('/etc/apache2/ssl'): | ||
1345 | 445 | os.mkdir('/etc/apache2/ssl') | ||
1347 | 446 | ssl_dir = os.path.join('/etc/apache2/ssl/', self.service_namespace) | 523 | ssl_dir = os.path.join('/etc/apache2/ssl/', self.service_namespace) |
1355 | 447 | if not os.path.isdir(ssl_dir): | 524 | mkdir(path=ssl_dir) |
1356 | 448 | os.mkdir(ssl_dir) | 525 | cert, key = get_cert(cn) |
1357 | 449 | cert, key = get_cert() | 526 | if cn: |
1358 | 450 | with open(os.path.join(ssl_dir, 'cert'), 'w') as cert_out: | 527 | cert_filename = 'cert_{}'.format(cn) |
1359 | 451 | cert_out.write(b64decode(cert)) | 528 | key_filename = 'key_{}'.format(cn) |
1360 | 452 | with open(os.path.join(ssl_dir, 'key'), 'w') as key_out: | 529 | else: |
1361 | 453 | key_out.write(b64decode(key)) | 530 | cert_filename = 'cert' |
1362 | 531 | key_filename = 'key' | ||
1363 | 532 | write_file(path=os.path.join(ssl_dir, cert_filename), | ||
1364 | 533 | content=b64decode(cert)) | ||
1365 | 534 | write_file(path=os.path.join(ssl_dir, key_filename), | ||
1366 | 535 | content=b64decode(key)) | ||
1367 | 536 | |||
1368 | 537 | def configure_ca(self): | ||
1369 | 454 | ca_cert = get_ca_cert() | 538 | ca_cert = get_ca_cert() |
1370 | 455 | if ca_cert: | 539 | if ca_cert: |
1374 | 456 | with open(CA_CERT_PATH, 'w') as ca_out: | 540 | install_ca_cert(b64decode(ca_cert)) |
1375 | 457 | ca_out.write(b64decode(ca_cert)) | 541 | |
1376 | 458 | check_call(['update-ca-certificates']) | 542 | def canonical_names(self): |
1377 | 543 | '''Figure out which canonical names clients will access this service''' | ||
1378 | 544 | cns = [] | ||
1379 | 545 | for r_id in relation_ids('identity-service'): | ||
1380 | 546 | for unit in related_units(r_id): | ||
1381 | 547 | rdata = relation_get(rid=r_id, unit=unit) | ||
1382 | 548 | for k in rdata: | ||
1383 | 549 | if k.startswith('ssl_key_'): | ||
1384 | 550 | cns.append(k.lstrip('ssl_key_')) | ||
1385 | 551 | return list(set(cns)) | ||
1386 | 459 | 552 | ||
1387 | 460 | def __call__(self): | 553 | def __call__(self): |
1388 | 461 | if isinstance(self.external_ports, basestring): | 554 | if isinstance(self.external_ports, basestring): |
1389 | @@ -463,21 +556,47 @@ | |||
1390 | 463 | if (not self.external_ports or not https()): | 556 | if (not self.external_ports or not https()): |
1391 | 464 | return {} | 557 | return {} |
1392 | 465 | 558 | ||
1394 | 466 | self.configure_cert() | 559 | self.configure_ca() |
1395 | 467 | self.enable_modules() | 560 | self.enable_modules() |
1396 | 468 | 561 | ||
1397 | 469 | ctxt = { | 562 | ctxt = { |
1398 | 470 | 'namespace': self.service_namespace, | 563 | 'namespace': self.service_namespace, |
1401 | 471 | 'private_address': unit_get('private-address'), | 564 | 'endpoints': [], |
1402 | 472 | 'endpoints': [] | 565 | 'ext_ports': [] |
1403 | 473 | } | 566 | } |
1411 | 474 | if is_clustered(): | 567 | |
1412 | 475 | ctxt['private_address'] = config('vip') | 568 | for cn in self.canonical_names(): |
1413 | 476 | for api_port in self.external_ports: | 569 | self.configure_cert(cn) |
1414 | 477 | ext_port = determine_apache_port(api_port) | 570 | |
1415 | 478 | int_port = determine_api_port(api_port) | 571 | addresses = [] |
1416 | 479 | portmap = (int(ext_port), int(int_port)) | 572 | vips = [] |
1417 | 480 | ctxt['endpoints'].append(portmap) | 573 | if config('vip'): |
1418 | 574 | vips = config('vip').split() | ||
1419 | 575 | |||
1420 | 576 | for network_type in ['os-internal-network', | ||
1421 | 577 | 'os-admin-network', | ||
1422 | 578 | 'os-public-network']: | ||
1423 | 579 | address = get_address_in_network(config(network_type), | ||
1424 | 580 | unit_get('private-address')) | ||
1425 | 581 | if len(vips) > 0 and is_clustered(): | ||
1426 | 582 | for vip in vips: | ||
1427 | 583 | if is_address_in_network(config(network_type), | ||
1428 | 584 | vip): | ||
1429 | 585 | addresses.append((address, vip)) | ||
1430 | 586 | break | ||
1431 | 587 | elif is_clustered(): | ||
1432 | 588 | addresses.append((address, config('vip'))) | ||
1433 | 589 | else: | ||
1434 | 590 | addresses.append((address, address)) | ||
1435 | 591 | |||
1436 | 592 | for address, endpoint in set(addresses): | ||
1437 | 593 | for api_port in self.external_ports: | ||
1438 | 594 | ext_port = determine_apache_port(api_port) | ||
1439 | 595 | int_port = determine_api_port(api_port) | ||
1440 | 596 | portmap = (address, endpoint, int(ext_port), int(int_port)) | ||
1441 | 597 | ctxt['endpoints'].append(portmap) | ||
1442 | 598 | ctxt['ext_ports'].append(int(ext_port)) | ||
1443 | 599 | ctxt['ext_ports'] = list(set(ctxt['ext_ports'])) | ||
1444 | 481 | return ctxt | 600 | return ctxt |
1445 | 482 | 601 | ||
1446 | 483 | 602 | ||
1447 | @@ -542,6 +661,26 @@ | |||
1448 | 542 | 661 | ||
1449 | 543 | return nvp_ctxt | 662 | return nvp_ctxt |
1450 | 544 | 663 | ||
1451 | 664 | def n1kv_ctxt(self): | ||
1452 | 665 | driver = neutron_plugin_attribute(self.plugin, 'driver', | ||
1453 | 666 | self.network_manager) | ||
1454 | 667 | n1kv_config = neutron_plugin_attribute(self.plugin, 'config', | ||
1455 | 668 | self.network_manager) | ||
1456 | 669 | n1kv_ctxt = { | ||
1457 | 670 | 'core_plugin': driver, | ||
1458 | 671 | 'neutron_plugin': 'n1kv', | ||
1459 | 672 | 'neutron_security_groups': self.neutron_security_groups, | ||
1460 | 673 | 'local_ip': unit_private_ip(), | ||
1461 | 674 | 'config': n1kv_config, | ||
1462 | 675 | 'vsm_ip': config('n1kv-vsm-ip'), | ||
1463 | 676 | 'vsm_username': config('n1kv-vsm-username'), | ||
1464 | 677 | 'vsm_password': config('n1kv-vsm-password'), | ||
1465 | 678 | 'restrict_policy_profiles': config( | ||
1466 | 679 | 'n1kv_restrict_policy_profiles'), | ||
1467 | 680 | } | ||
1468 | 681 | |||
1469 | 682 | return n1kv_ctxt | ||
1470 | 683 | |||
1471 | 545 | def neutron_ctxt(self): | 684 | def neutron_ctxt(self): |
1472 | 546 | if https(): | 685 | if https(): |
1473 | 547 | proto = 'https' | 686 | proto = 'https' |
1474 | @@ -573,6 +712,8 @@ | |||
1475 | 573 | ctxt.update(self.ovs_ctxt()) | 712 | ctxt.update(self.ovs_ctxt()) |
1476 | 574 | elif self.plugin in ['nvp', 'nsx']: | 713 | elif self.plugin in ['nvp', 'nsx']: |
1477 | 575 | ctxt.update(self.nvp_ctxt()) | 714 | ctxt.update(self.nvp_ctxt()) |
1478 | 715 | elif self.plugin == 'n1kv': | ||
1479 | 716 | ctxt.update(self.n1kv_ctxt()) | ||
1480 | 576 | 717 | ||
1481 | 577 | alchemy_flags = config('neutron-alchemy-flags') | 718 | alchemy_flags = config('neutron-alchemy-flags') |
1482 | 578 | if alchemy_flags: | 719 | if alchemy_flags: |
1483 | @@ -612,7 +753,7 @@ | |||
1484 | 612 | The subordinate interface allows subordinates to export their | 753 | The subordinate interface allows subordinates to export their |
1485 | 613 | configuration requirements to the principle for multiple config | 754 | configuration requirements to the principle for multiple config |
1486 | 614 | files and multiple serivces. Ie, a subordinate that has interfaces | 755 | files and multiple serivces. Ie, a subordinate that has interfaces |
1488 | 615 | to both glance and nova may export to following yaml blob as json: | 756 | to both glance and nova may export to following yaml blob as json:: |
1489 | 616 | 757 | ||
1490 | 617 | glance: | 758 | glance: |
1491 | 618 | /etc/glance/glance-api.conf: | 759 | /etc/glance/glance-api.conf: |
1492 | @@ -631,7 +772,8 @@ | |||
1493 | 631 | 772 | ||
1494 | 632 | It is then up to the principle charms to subscribe this context to | 773 | It is then up to the principle charms to subscribe this context to |
1495 | 633 | the service+config file it is interestd in. Configuration data will | 774 | the service+config file it is interestd in. Configuration data will |
1497 | 634 | be available in the template context, in glance's case, as: | 775 | be available in the template context, in glance's case, as:: |
1498 | 776 | |||
1499 | 635 | ctxt = { | 777 | ctxt = { |
1500 | 636 | ... other context ... | 778 | ... other context ... |
1501 | 637 | 'subordinate_config': { | 779 | 'subordinate_config': { |
1502 | @@ -684,15 +826,38 @@ | |||
1503 | 684 | 826 | ||
1504 | 685 | sub_config = sub_config[self.config_file] | 827 | sub_config = sub_config[self.config_file] |
1505 | 686 | for k, v in sub_config.iteritems(): | 828 | for k, v in sub_config.iteritems(): |
1515 | 687 | if k == 'sections': | 829 | <<<<<<< TREE |
1516 | 688 | for section, config_dict in v.iteritems(): | 830 | if k == 'sections': |
1517 | 689 | log("adding section '%s'" % (section)) | 831 | for section, config_dict in v.iteritems(): |
1518 | 690 | ctxt[k][section] = config_dict | 832 | log("adding section '%s'" % (section)) |
1519 | 691 | else: | 833 | ctxt[k][section] = config_dict |
1520 | 692 | ctxt[k] = v | 834 | else: |
1521 | 693 | 835 | ctxt[k] = v | |
1522 | 694 | log("%d section(s) found" % (len(ctxt['sections'])), level=INFO) | 836 | |
1523 | 695 | 837 | log("%d section(s) found" % (len(ctxt['sections'])), level=INFO) | |
1524 | 838 | |||
1525 | 839 | ======= | ||
1526 | 840 | if k == 'sections': | ||
1527 | 841 | for section, config_dict in v.iteritems(): | ||
1528 | 842 | log("adding section '%s'" % (section)) | ||
1529 | 843 | ctxt[k][section] = config_dict | ||
1530 | 844 | else: | ||
1531 | 845 | ctxt[k] = v | ||
1532 | 846 | |||
1533 | 847 | log("%d section(s) found" % (len(ctxt['sections'])), level=INFO) | ||
1534 | 848 | |||
1535 | 849 | return ctxt | ||
1536 | 850 | |||
1537 | 851 | |||
1538 | 852 | class LogLevelContext(OSContextGenerator): | ||
1539 | 853 | |||
1540 | 854 | def __call__(self): | ||
1541 | 855 | ctxt = {} | ||
1542 | 856 | ctxt['debug'] = \ | ||
1543 | 857 | False if config('debug') is None else config('debug') | ||
1544 | 858 | ctxt['verbose'] = \ | ||
1545 | 859 | False if config('verbose') is None else config('verbose') | ||
1546 | 860 | >>>>>>> MERGE-SOURCE | ||
1547 | 696 | return ctxt | 861 | return ctxt |
1548 | 697 | 862 | ||
1549 | 698 | 863 | ||
1550 | @@ -703,3 +868,16 @@ | |||
1551 | 703 | 'use_syslog': config('use-syslog') | 868 | 'use_syslog': config('use-syslog') |
1552 | 704 | } | 869 | } |
1553 | 705 | return ctxt | 870 | return ctxt |
1554 | 871 | |||
1555 | 872 | |||
1556 | 873 | class BindHostContext(OSContextGenerator): | ||
1557 | 874 | |||
1558 | 875 | def __call__(self): | ||
1559 | 876 | if config('prefer-ipv6'): | ||
1560 | 877 | return { | ||
1561 | 878 | 'bind_host': '::' | ||
1562 | 879 | } | ||
1563 | 880 | else: | ||
1564 | 881 | return { | ||
1565 | 882 | 'bind_host': '0.0.0.0' | ||
1566 | 883 | } | ||
1567 | 706 | 884 | ||
1568 | === added file 'hooks/charmhelpers/contrib/openstack/ip.py' | |||
1569 | --- hooks/charmhelpers/contrib/openstack/ip.py 1970-01-01 00:00:00 +0000 | |||
1570 | +++ hooks/charmhelpers/contrib/openstack/ip.py 2014-10-06 15:38:41 +0000 | |||
1571 | @@ -0,0 +1,79 @@ | |||
1572 | 1 | from charmhelpers.core.hookenv import ( | ||
1573 | 2 | config, | ||
1574 | 3 | unit_get, | ||
1575 | 4 | ) | ||
1576 | 5 | |||
1577 | 6 | from charmhelpers.contrib.network.ip import ( | ||
1578 | 7 | get_address_in_network, | ||
1579 | 8 | is_address_in_network, | ||
1580 | 9 | is_ipv6, | ||
1581 | 10 | get_ipv6_addr, | ||
1582 | 11 | ) | ||
1583 | 12 | |||
1584 | 13 | from charmhelpers.contrib.hahelpers.cluster import is_clustered | ||
1585 | 14 | |||
1586 | 15 | PUBLIC = 'public' | ||
1587 | 16 | INTERNAL = 'int' | ||
1588 | 17 | ADMIN = 'admin' | ||
1589 | 18 | |||
1590 | 19 | _address_map = { | ||
1591 | 20 | PUBLIC: { | ||
1592 | 21 | 'config': 'os-public-network', | ||
1593 | 22 | 'fallback': 'public-address' | ||
1594 | 23 | }, | ||
1595 | 24 | INTERNAL: { | ||
1596 | 25 | 'config': 'os-internal-network', | ||
1597 | 26 | 'fallback': 'private-address' | ||
1598 | 27 | }, | ||
1599 | 28 | ADMIN: { | ||
1600 | 29 | 'config': 'os-admin-network', | ||
1601 | 30 | 'fallback': 'private-address' | ||
1602 | 31 | } | ||
1603 | 32 | } | ||
1604 | 33 | |||
1605 | 34 | |||
1606 | 35 | def canonical_url(configs, endpoint_type=PUBLIC): | ||
1607 | 36 | ''' | ||
1608 | 37 | Returns the correct HTTP URL to this host given the state of HTTPS | ||
1609 | 38 | configuration, hacluster and charm configuration. | ||
1610 | 39 | |||
1611 | 40 | :configs OSTemplateRenderer: A config tempating object to inspect for | ||
1612 | 41 | a complete https context. | ||
1613 | 42 | :endpoint_type str: The endpoint type to resolve. | ||
1614 | 43 | |||
1615 | 44 | :returns str: Base URL for services on the current service unit. | ||
1616 | 45 | ''' | ||
1617 | 46 | scheme = 'http' | ||
1618 | 47 | if 'https' in configs.complete_contexts(): | ||
1619 | 48 | scheme = 'https' | ||
1620 | 49 | address = resolve_address(endpoint_type) | ||
1621 | 50 | if is_ipv6(address): | ||
1622 | 51 | address = "[{}]".format(address) | ||
1623 | 52 | return '%s://%s' % (scheme, address) | ||
1624 | 53 | |||
1625 | 54 | |||
1626 | 55 | def resolve_address(endpoint_type=PUBLIC): | ||
1627 | 56 | resolved_address = None | ||
1628 | 57 | if is_clustered(): | ||
1629 | 58 | if config(_address_map[endpoint_type]['config']) is None: | ||
1630 | 59 | # Assume vip is simple and pass back directly | ||
1631 | 60 | resolved_address = config('vip') | ||
1632 | 61 | else: | ||
1633 | 62 | for vip in config('vip').split(): | ||
1634 | 63 | if is_address_in_network( | ||
1635 | 64 | config(_address_map[endpoint_type]['config']), | ||
1636 | 65 | vip): | ||
1637 | 66 | resolved_address = vip | ||
1638 | 67 | else: | ||
1639 | 68 | if config('prefer-ipv6'): | ||
1640 | 69 | fallback_addr = get_ipv6_addr(exc_list=[config('vip')])[0] | ||
1641 | 70 | else: | ||
1642 | 71 | fallback_addr = unit_get(_address_map[endpoint_type]['fallback']) | ||
1643 | 72 | resolved_address = get_address_in_network( | ||
1644 | 73 | config(_address_map[endpoint_type]['config']), fallback_addr) | ||
1645 | 74 | |||
1646 | 75 | if resolved_address is None: | ||
1647 | 76 | raise ValueError('Unable to resolve a suitable IP address' | ||
1648 | 77 | ' based on charm state and configuration') | ||
1649 | 78 | else: | ||
1650 | 79 | return resolved_address | ||
1651 | 0 | 80 | ||
1652 | === modified file 'hooks/charmhelpers/contrib/openstack/neutron.py' | |||
1653 | --- hooks/charmhelpers/contrib/openstack/neutron.py 2014-05-19 11:39:11 +0000 | |||
1654 | +++ hooks/charmhelpers/contrib/openstack/neutron.py 2014-10-06 15:38:41 +0000 | |||
1655 | @@ -128,6 +128,20 @@ | |||
1656 | 128 | 'server_packages': ['neutron-server', | 128 | 'server_packages': ['neutron-server', |
1657 | 129 | 'neutron-plugin-vmware'], | 129 | 'neutron-plugin-vmware'], |
1658 | 130 | 'server_services': ['neutron-server'] | 130 | 'server_services': ['neutron-server'] |
1659 | 131 | }, | ||
1660 | 132 | 'n1kv': { | ||
1661 | 133 | 'config': '/etc/neutron/plugins/cisco/cisco_plugins.ini', | ||
1662 | 134 | 'driver': 'neutron.plugins.cisco.network_plugin.PluginV2', | ||
1663 | 135 | 'contexts': [ | ||
1664 | 136 | context.SharedDBContext(user=config('neutron-database-user'), | ||
1665 | 137 | database=config('neutron-database'), | ||
1666 | 138 | relation_prefix='neutron', | ||
1667 | 139 | ssl_dir=NEUTRON_CONF_DIR)], | ||
1668 | 140 | 'services': [], | ||
1669 | 141 | 'packages': [['neutron-plugin-cisco']], | ||
1670 | 142 | 'server_packages': ['neutron-server', | ||
1671 | 143 | 'neutron-plugin-cisco'], | ||
1672 | 144 | 'server_services': ['neutron-server'] | ||
1673 | 131 | } | 145 | } |
1674 | 132 | } | 146 | } |
1675 | 133 | if release >= 'icehouse': | 147 | if release >= 'icehouse': |
1676 | 134 | 148 | ||
1677 | === modified file 'hooks/charmhelpers/contrib/openstack/templates/haproxy.cfg' | |||
1678 | --- hooks/charmhelpers/contrib/openstack/templates/haproxy.cfg 2014-03-27 11:23:24 +0000 | |||
1679 | +++ hooks/charmhelpers/contrib/openstack/templates/haproxy.cfg 2014-10-06 15:38:41 +0000 | |||
1680 | @@ -1,6 +1,6 @@ | |||
1681 | 1 | global | 1 | global |
1684 | 2 | log 127.0.0.1 local0 | 2 | log {{ local_host }} local0 |
1685 | 3 | log 127.0.0.1 local1 notice | 3 | log {{ local_host }} local1 notice |
1686 | 4 | maxconn 20000 | 4 | maxconn 20000 |
1687 | 5 | user haproxy | 5 | user haproxy |
1688 | 6 | group haproxy | 6 | group haproxy |
1689 | @@ -14,10 +14,19 @@ | |||
1690 | 14 | retries 3 | 14 | retries 3 |
1691 | 15 | timeout queue 1000 | 15 | timeout queue 1000 |
1692 | 16 | timeout connect 1000 | 16 | timeout connect 1000 |
1693 | 17 | {% if haproxy_client_timeout -%} | ||
1694 | 18 | timeout client {{ haproxy_client_timeout }} | ||
1695 | 19 | {% else -%} | ||
1696 | 17 | timeout client 30000 | 20 | timeout client 30000 |
1697 | 21 | {% endif -%} | ||
1698 | 22 | |||
1699 | 23 | {% if haproxy_server_timeout -%} | ||
1700 | 24 | timeout server {{ haproxy_server_timeout }} | ||
1701 | 25 | {% else -%} | ||
1702 | 18 | timeout server 30000 | 26 | timeout server 30000 |
1703 | 27 | {% endif -%} | ||
1704 | 19 | 28 | ||
1706 | 20 | listen stats :8888 | 29 | listen stats {{ stat_port }} |
1707 | 21 | mode http | 30 | mode http |
1708 | 22 | stats enable | 31 | stats enable |
1709 | 23 | stats hide-version | 32 | stats hide-version |
1710 | @@ -27,7 +36,12 @@ | |||
1711 | 27 | 36 | ||
1712 | 28 | {% if units -%} | 37 | {% if units -%} |
1713 | 29 | {% for service, ports in service_ports.iteritems() -%} | 38 | {% for service, ports in service_ports.iteritems() -%} |
1715 | 30 | listen {{ service }} 0.0.0.0:{{ ports[0] }} | 39 | listen {{ service }}_ipv4 0.0.0.0:{{ ports[0] }} |
1716 | 40 | balance roundrobin | ||
1717 | 41 | {% for unit, address in units.iteritems() -%} | ||
1718 | 42 | server {{ unit }} {{ address }}:{{ ports[1] }} check | ||
1719 | 43 | {% endfor %} | ||
1720 | 44 | listen {{ service }}_ipv6 :::{{ ports[0] }} | ||
1721 | 31 | balance roundrobin | 45 | balance roundrobin |
1722 | 32 | {% for unit, address in units.iteritems() -%} | 46 | {% for unit, address in units.iteritems() -%} |
1723 | 33 | server {{ unit }} {{ address }}:{{ ports[1] }} check | 47 | server {{ unit }} {{ address }}:{{ ports[1] }} check |
1724 | 34 | 48 | ||
1725 | === modified file 'hooks/charmhelpers/contrib/openstack/templates/openstack_https_frontend' | |||
1726 | --- hooks/charmhelpers/contrib/openstack/templates/openstack_https_frontend 2013-09-27 12:02:37 +0000 | |||
1727 | +++ hooks/charmhelpers/contrib/openstack/templates/openstack_https_frontend 2014-10-06 15:38:41 +0000 | |||
1728 | @@ -1,16 +1,18 @@ | |||
1729 | 1 | {% if endpoints -%} | 1 | {% if endpoints -%} |
1735 | 2 | {% for ext, int in endpoints -%} | 2 | {% for ext_port in ext_ports -%} |
1736 | 3 | Listen {{ ext }} | 3 | Listen {{ ext_port }} |
1737 | 4 | NameVirtualHost *:{{ ext }} | 4 | {% endfor -%} |
1738 | 5 | <VirtualHost *:{{ ext }}> | 5 | {% for address, endpoint, ext, int in endpoints -%} |
1739 | 6 | ServerName {{ private_address }} | 6 | <VirtualHost {{ address }}:{{ ext }}> |
1740 | 7 | ServerName {{ endpoint }} | ||
1741 | 7 | SSLEngine on | 8 | SSLEngine on |
1744 | 8 | SSLCertificateFile /etc/apache2/ssl/{{ namespace }}/cert | 9 | SSLCertificateFile /etc/apache2/ssl/{{ namespace }}/cert_{{ endpoint }} |
1745 | 9 | SSLCertificateKeyFile /etc/apache2/ssl/{{ namespace }}/key | 10 | SSLCertificateKeyFile /etc/apache2/ssl/{{ namespace }}/key_{{ endpoint }} |
1746 | 10 | ProxyPass / http://localhost:{{ int }}/ | 11 | ProxyPass / http://localhost:{{ int }}/ |
1747 | 11 | ProxyPassReverse / http://localhost:{{ int }}/ | 12 | ProxyPassReverse / http://localhost:{{ int }}/ |
1748 | 12 | ProxyPreserveHost on | 13 | ProxyPreserveHost on |
1749 | 13 | </VirtualHost> | 14 | </VirtualHost> |
1750 | 15 | {% endfor -%} | ||
1751 | 14 | <Proxy *> | 16 | <Proxy *> |
1752 | 15 | Order deny,allow | 17 | Order deny,allow |
1753 | 16 | Allow from all | 18 | Allow from all |
1754 | @@ -19,5 +21,4 @@ | |||
1755 | 19 | Order allow,deny | 21 | Order allow,deny |
1756 | 20 | Allow from all | 22 | Allow from all |
1757 | 21 | </Location> | 23 | </Location> |
1758 | 22 | {% endfor -%} | ||
1759 | 23 | {% endif -%} | 24 | {% endif -%} |
1760 | 24 | 25 | ||
1761 | === modified file 'hooks/charmhelpers/contrib/openstack/templates/openstack_https_frontend.conf' | |||
1762 | --- hooks/charmhelpers/contrib/openstack/templates/openstack_https_frontend.conf 2013-09-27 12:02:37 +0000 | |||
1763 | +++ hooks/charmhelpers/contrib/openstack/templates/openstack_https_frontend.conf 2014-10-06 15:38:41 +0000 | |||
1764 | @@ -1,16 +1,18 @@ | |||
1765 | 1 | {% if endpoints -%} | 1 | {% if endpoints -%} |
1771 | 2 | {% for ext, int in endpoints -%} | 2 | {% for ext_port in ext_ports -%} |
1772 | 3 | Listen {{ ext }} | 3 | Listen {{ ext_port }} |
1773 | 4 | NameVirtualHost *:{{ ext }} | 4 | {% endfor -%} |
1774 | 5 | <VirtualHost *:{{ ext }}> | 5 | {% for address, endpoint, ext, int in endpoints -%} |
1775 | 6 | ServerName {{ private_address }} | 6 | <VirtualHost {{ address }}:{{ ext }}> |
1776 | 7 | ServerName {{ endpoint }} | ||
1777 | 7 | SSLEngine on | 8 | SSLEngine on |
1780 | 8 | SSLCertificateFile /etc/apache2/ssl/{{ namespace }}/cert | 9 | SSLCertificateFile /etc/apache2/ssl/{{ namespace }}/cert_{{ endpoint }} |
1781 | 9 | SSLCertificateKeyFile /etc/apache2/ssl/{{ namespace }}/key | 10 | SSLCertificateKeyFile /etc/apache2/ssl/{{ namespace }}/key_{{ endpoint }} |
1782 | 10 | ProxyPass / http://localhost:{{ int }}/ | 11 | ProxyPass / http://localhost:{{ int }}/ |
1783 | 11 | ProxyPassReverse / http://localhost:{{ int }}/ | 12 | ProxyPassReverse / http://localhost:{{ int }}/ |
1784 | 12 | ProxyPreserveHost on | 13 | ProxyPreserveHost on |
1785 | 13 | </VirtualHost> | 14 | </VirtualHost> |
1786 | 15 | {% endfor -%} | ||
1787 | 14 | <Proxy *> | 16 | <Proxy *> |
1788 | 15 | Order deny,allow | 17 | Order deny,allow |
1789 | 16 | Allow from all | 18 | Allow from all |
1790 | @@ -19,5 +21,4 @@ | |||
1791 | 19 | Order allow,deny | 21 | Order allow,deny |
1792 | 20 | Allow from all | 22 | Allow from all |
1793 | 21 | </Location> | 23 | </Location> |
1794 | 22 | {% endfor -%} | ||
1795 | 23 | {% endif -%} | 24 | {% endif -%} |
1796 | 24 | 25 | ||
1797 | === modified file 'hooks/charmhelpers/contrib/openstack/templating.py' | |||
1798 | --- hooks/charmhelpers/contrib/openstack/templating.py 2013-09-27 12:02:37 +0000 | |||
1799 | +++ hooks/charmhelpers/contrib/openstack/templating.py 2014-10-06 15:38:41 +0000 | |||
1800 | @@ -30,17 +30,17 @@ | |||
1801 | 30 | loading dir. | 30 | loading dir. |
1802 | 31 | 31 | ||
1803 | 32 | A charm may also ship a templates dir with this module | 32 | A charm may also ship a templates dir with this module |
1815 | 33 | and it will be appended to the bottom of the search list, eg: | 33 | and it will be appended to the bottom of the search list, eg:: |
1816 | 34 | hooks/charmhelpers/contrib/openstack/templates. | 34 | |
1817 | 35 | 35 | hooks/charmhelpers/contrib/openstack/templates | |
1818 | 36 | :param templates_dir: str: Base template directory containing release | 36 | |
1819 | 37 | sub-directories. | 37 | :param templates_dir (str): Base template directory containing release |
1820 | 38 | :param os_release : str: OpenStack release codename to construct template | 38 | sub-directories. |
1821 | 39 | loader. | 39 | :param os_release (str): OpenStack release codename to construct template |
1822 | 40 | 40 | loader. | |
1823 | 41 | :returns : jinja2.ChoiceLoader constructed with a list of | 41 | :returns: jinja2.ChoiceLoader constructed with a list of |
1824 | 42 | jinja2.FilesystemLoaders, ordered in descending | 42 | jinja2.FilesystemLoaders, ordered in descending |
1825 | 43 | order by OpenStack release. | 43 | order by OpenStack release. |
1826 | 44 | """ | 44 | """ |
1827 | 45 | tmpl_dirs = [(rel, os.path.join(templates_dir, rel)) | 45 | tmpl_dirs = [(rel, os.path.join(templates_dir, rel)) |
1828 | 46 | for rel in OPENSTACK_CODENAMES.itervalues()] | 46 | for rel in OPENSTACK_CODENAMES.itervalues()] |
1829 | @@ -111,7 +111,8 @@ | |||
1830 | 111 | and ease the burden of managing config templates across multiple OpenStack | 111 | and ease the burden of managing config templates across multiple OpenStack |
1831 | 112 | releases. | 112 | releases. |
1832 | 113 | 113 | ||
1834 | 114 | Basic usage: | 114 | Basic usage:: |
1835 | 115 | |||
1836 | 115 | # import some common context generates from charmhelpers | 116 | # import some common context generates from charmhelpers |
1837 | 116 | from charmhelpers.contrib.openstack import context | 117 | from charmhelpers.contrib.openstack import context |
1838 | 117 | 118 | ||
1839 | @@ -131,21 +132,19 @@ | |||
1840 | 131 | # write out all registered configs | 132 | # write out all registered configs |
1841 | 132 | configs.write_all() | 133 | configs.write_all() |
1842 | 133 | 134 | ||
1844 | 134 | Details: | 135 | **OpenStack Releases and template loading** |
1845 | 135 | 136 | ||
1846 | 136 | OpenStack Releases and template loading | ||
1847 | 137 | --------------------------------------- | ||
1848 | 138 | When the object is instantiated, it is associated with a specific OS | 137 | When the object is instantiated, it is associated with a specific OS |
1849 | 139 | release. This dictates how the template loader will be constructed. | 138 | release. This dictates how the template loader will be constructed. |
1850 | 140 | 139 | ||
1851 | 141 | The constructed loader attempts to load the template from several places | 140 | The constructed loader attempts to load the template from several places |
1852 | 142 | in the following order: | 141 | in the following order: |
1859 | 143 | - from the most recent OS release-specific template dir (if one exists) | 142 | - from the most recent OS release-specific template dir (if one exists) |
1860 | 144 | - the base templates_dir | 143 | - the base templates_dir |
1861 | 145 | - a template directory shipped in the charm with this helper file. | 144 | - a template directory shipped in the charm with this helper file. |
1862 | 146 | 145 | ||
1863 | 147 | 146 | For the example above, '/tmp/templates' contains the following structure:: | |
1864 | 148 | For the example above, '/tmp/templates' contains the following structure: | 147 | |
1865 | 149 | /tmp/templates/nova.conf | 148 | /tmp/templates/nova.conf |
1866 | 150 | /tmp/templates/api-paste.ini | 149 | /tmp/templates/api-paste.ini |
1867 | 151 | /tmp/templates/grizzly/api-paste.ini | 150 | /tmp/templates/grizzly/api-paste.ini |
1868 | @@ -169,8 +168,8 @@ | |||
1869 | 169 | $CHARM/hooks/charmhelpers/contrib/openstack/templates. This allows | 168 | $CHARM/hooks/charmhelpers/contrib/openstack/templates. This allows |
1870 | 170 | us to ship common templates (haproxy, apache) with the helpers. | 169 | us to ship common templates (haproxy, apache) with the helpers. |
1871 | 171 | 170 | ||
1874 | 172 | Context generators | 171 | **Context generators** |
1875 | 173 | --------------------------------------- | 172 | |
1876 | 174 | Context generators are used to generate template contexts during hook | 173 | Context generators are used to generate template contexts during hook |
1877 | 175 | execution. Doing so may require inspecting service relations, charm | 174 | execution. Doing so may require inspecting service relations, charm |
1878 | 176 | config, etc. When registered, a config file is associated with a list | 175 | config, etc. When registered, a config file is associated with a list |
1879 | 177 | 176 | ||
1880 | === modified file 'hooks/charmhelpers/contrib/openstack/utils.py' | |||
1881 | --- hooks/charmhelpers/contrib/openstack/utils.py 2014-08-27 07:17:33 +0000 | |||
1882 | +++ hooks/charmhelpers/contrib/openstack/utils.py 2014-10-06 15:38:41 +0000 | |||
1883 | @@ -3,8 +3,8 @@ | |||
1884 | 3 | # Common python helper functions used for OpenStack charms. | 3 | # Common python helper functions used for OpenStack charms. |
1885 | 4 | from collections import OrderedDict | 4 | from collections import OrderedDict |
1886 | 5 | 5 | ||
1887 | 6 | import apt_pkg as apt | ||
1888 | 7 | import subprocess | 6 | import subprocess |
1889 | 7 | import json | ||
1890 | 8 | import os | 8 | import os |
1891 | 9 | import socket | 9 | import socket |
1892 | 10 | import sys | 10 | import sys |
1893 | @@ -14,7 +14,9 @@ | |||
1894 | 14 | log as juju_log, | 14 | log as juju_log, |
1895 | 15 | charm_dir, | 15 | charm_dir, |
1896 | 16 | ERROR, | 16 | ERROR, |
1898 | 17 | INFO | 17 | INFO, |
1899 | 18 | relation_ids, | ||
1900 | 19 | relation_set | ||
1901 | 18 | ) | 20 | ) |
1902 | 19 | 21 | ||
1903 | 20 | from charmhelpers.contrib.storage.linux.lvm import ( | 22 | from charmhelpers.contrib.storage.linux.lvm import ( |
1904 | @@ -23,6 +25,10 @@ | |||
1905 | 23 | remove_lvm_physical_volume, | 25 | remove_lvm_physical_volume, |
1906 | 24 | ) | 26 | ) |
1907 | 25 | 27 | ||
1908 | 28 | from charmhelpers.contrib.network.ip import ( | ||
1909 | 29 | get_ipv6_addr | ||
1910 | 30 | ) | ||
1911 | 31 | |||
1912 | 26 | from charmhelpers.core.host import lsb_release, mounts, umount | 32 | from charmhelpers.core.host import lsb_release, mounts, umount |
1913 | 27 | from charmhelpers.fetch import apt_install, apt_cache | 33 | from charmhelpers.fetch import apt_install, apt_cache |
1914 | 28 | from charmhelpers.contrib.storage.linux.utils import is_block_device, zap_disk | 34 | from charmhelpers.contrib.storage.linux.utils import is_block_device, zap_disk |
1915 | @@ -41,7 +47,8 @@ | |||
1916 | 41 | ('quantal', 'folsom'), | 47 | ('quantal', 'folsom'), |
1917 | 42 | ('raring', 'grizzly'), | 48 | ('raring', 'grizzly'), |
1918 | 43 | ('saucy', 'havana'), | 49 | ('saucy', 'havana'), |
1920 | 44 | ('trusty', 'icehouse') | 50 | ('trusty', 'icehouse'), |
1921 | 51 | ('utopic', 'juno'), | ||
1922 | 45 | ]) | 52 | ]) |
1923 | 46 | 53 | ||
1924 | 47 | 54 | ||
1925 | @@ -52,6 +59,7 @@ | |||
1926 | 52 | ('2013.1', 'grizzly'), | 59 | ('2013.1', 'grizzly'), |
1927 | 53 | ('2013.2', 'havana'), | 60 | ('2013.2', 'havana'), |
1928 | 54 | ('2014.1', 'icehouse'), | 61 | ('2014.1', 'icehouse'), |
1929 | 62 | ('2014.2', 'juno'), | ||
1930 | 55 | ]) | 63 | ]) |
1931 | 56 | 64 | ||
1932 | 57 | # The ugly duckling | 65 | # The ugly duckling |
1933 | @@ -69,6 +77,7 @@ | |||
1934 | 69 | ('1.13.0', 'icehouse'), | 77 | ('1.13.0', 'icehouse'), |
1935 | 70 | ('1.12.0', 'icehouse'), | 78 | ('1.12.0', 'icehouse'), |
1936 | 71 | ('1.11.0', 'icehouse'), | 79 | ('1.11.0', 'icehouse'), |
1937 | 80 | ('2.0.0', 'juno'), | ||
1938 | 72 | ]) | 81 | ]) |
1939 | 73 | 82 | ||
1940 | 74 | DEFAULT_LOOPBACK_SIZE = '5G' | 83 | DEFAULT_LOOPBACK_SIZE = '5G' |
1941 | @@ -83,6 +92,8 @@ | |||
1942 | 83 | '''Derive OpenStack release codename from a given installation source.''' | 92 | '''Derive OpenStack release codename from a given installation source.''' |
1943 | 84 | ubuntu_rel = lsb_release()['DISTRIB_CODENAME'] | 93 | ubuntu_rel = lsb_release()['DISTRIB_CODENAME'] |
1944 | 85 | rel = '' | 94 | rel = '' |
1945 | 95 | if src is None: | ||
1946 | 96 | return rel | ||
1947 | 86 | if src in ['distro', 'distro-proposed']: | 97 | if src in ['distro', 'distro-proposed']: |
1948 | 87 | try: | 98 | try: |
1949 | 88 | rel = UBUNTU_OPENSTACK_RELEASE[ubuntu_rel] | 99 | rel = UBUNTU_OPENSTACK_RELEASE[ubuntu_rel] |
1950 | @@ -130,8 +141,14 @@ | |||
1951 | 130 | 141 | ||
1952 | 131 | def get_os_codename_package(package, fatal=True): | 142 | def get_os_codename_package(package, fatal=True): |
1953 | 132 | '''Derive OpenStack release codename from an installed package.''' | 143 | '''Derive OpenStack release codename from an installed package.''' |
1956 | 133 | 144 | <<<<<<< TREE | |
1957 | 134 | cache = apt_cache() | 145 | |
1958 | 146 | cache = apt_cache() | ||
1959 | 147 | ======= | ||
1960 | 148 | import apt_pkg as apt | ||
1961 | 149 | |||
1962 | 150 | cache = apt_cache() | ||
1963 | 151 | >>>>>>> MERGE-SOURCE | ||
1964 | 135 | 152 | ||
1965 | 136 | try: | 153 | try: |
1966 | 137 | pkg = cache[package] | 154 | pkg = cache[package] |
1967 | @@ -182,7 +199,7 @@ | |||
1968 | 182 | for version, cname in vers_map.iteritems(): | 199 | for version, cname in vers_map.iteritems(): |
1969 | 183 | if cname == codename: | 200 | if cname == codename: |
1970 | 184 | return version | 201 | return version |
1972 | 185 | #e = "Could not determine OpenStack version for package: %s" % pkg | 202 | # e = "Could not determine OpenStack version for package: %s" % pkg |
1973 | 186 | # error_out(e) | 203 | # error_out(e) |
1974 | 187 | 204 | ||
1975 | 188 | 205 | ||
1976 | @@ -268,6 +285,9 @@ | |||
1977 | 268 | 'icehouse': 'precise-updates/icehouse', | 285 | 'icehouse': 'precise-updates/icehouse', |
1978 | 269 | 'icehouse/updates': 'precise-updates/icehouse', | 286 | 'icehouse/updates': 'precise-updates/icehouse', |
1979 | 270 | 'icehouse/proposed': 'precise-proposed/icehouse', | 287 | 'icehouse/proposed': 'precise-proposed/icehouse', |
1980 | 288 | 'juno': 'trusty-updates/juno', | ||
1981 | 289 | 'juno/updates': 'trusty-updates/juno', | ||
1982 | 290 | 'juno/proposed': 'trusty-proposed/juno', | ||
1983 | 271 | } | 291 | } |
1984 | 272 | 292 | ||
1985 | 273 | try: | 293 | try: |
1986 | @@ -315,6 +335,7 @@ | |||
1987 | 315 | 335 | ||
1988 | 316 | """ | 336 | """ |
1989 | 317 | 337 | ||
1990 | 338 | import apt_pkg as apt | ||
1991 | 318 | src = config('openstack-origin') | 339 | src = config('openstack-origin') |
1992 | 319 | cur_vers = get_os_version_package(package) | 340 | cur_vers = get_os_version_package(package) |
1993 | 320 | available_vers = get_os_version_install_source(src) | 341 | available_vers = get_os_version_install_source(src) |
1994 | @@ -448,3 +469,21 @@ | |||
1995 | 448 | return result | 469 | return result |
1996 | 449 | else: | 470 | else: |
1997 | 450 | return result.split('.')[0] | 471 | return result.split('.')[0] |
1998 | 472 | |||
1999 | 473 | |||
2000 | 474 | def sync_db_with_multi_ipv6_addresses(database, database_user, | ||
2001 | 475 | relation_prefix=None): | ||
2002 | 476 | hosts = get_ipv6_addr(dynamic_only=False) | ||
2003 | 477 | |||
2004 | 478 | kwargs = {'database': database, | ||
2005 | 479 | 'username': database_user, | ||
2006 | 480 | 'hostname': json.dumps(hosts)} | ||
2007 | 481 | |||
2008 | 482 | if relation_prefix: | ||
2009 | 483 | keys = kwargs.keys() | ||
2010 | 484 | for key in keys: | ||
2011 | 485 | kwargs["%s_%s" % (relation_prefix, key)] = kwargs[key] | ||
2012 | 486 | del kwargs[key] | ||
2013 | 487 | |||
2014 | 488 | for rid in relation_ids('shared-db'): | ||
2015 | 489 | relation_set(relation_id=rid, **kwargs) | ||
2016 | 451 | 490 | ||
2017 | === added directory 'hooks/charmhelpers/contrib/peerstorage' | |||
2018 | === added file 'hooks/charmhelpers/contrib/peerstorage/__init__.py' | |||
2019 | --- hooks/charmhelpers/contrib/peerstorage/__init__.py 1970-01-01 00:00:00 +0000 | |||
2020 | +++ hooks/charmhelpers/contrib/peerstorage/__init__.py 2014-10-06 15:38:41 +0000 | |||
2021 | @@ -0,0 +1,131 @@ | |||
2022 | 1 | from charmhelpers.core.hookenv import relation_id as current_relation_id | ||
2023 | 2 | from charmhelpers.core.hookenv import ( | ||
2024 | 3 | is_relation_made, | ||
2025 | 4 | relation_ids, | ||
2026 | 5 | relation_get, | ||
2027 | 6 | local_unit, | ||
2028 | 7 | relation_set, | ||
2029 | 8 | ) | ||
2030 | 9 | |||
2031 | 10 | |||
2032 | 11 | """ | ||
2033 | 12 | This helper provides functions to support use of a peer relation | ||
2034 | 13 | for basic key/value storage, with the added benefit that all storage | ||
2035 | 14 | can be replicated across peer units. | ||
2036 | 15 | |||
2037 | 16 | Requirement to use: | ||
2038 | 17 | |||
2039 | 18 | To use this, the "peer_echo()" method has to be called form the peer | ||
2040 | 19 | relation's relation-changed hook: | ||
2041 | 20 | |||
2042 | 21 | @hooks.hook("cluster-relation-changed") # Adapt the to your peer relation name | ||
2043 | 22 | def cluster_relation_changed(): | ||
2044 | 23 | peer_echo() | ||
2045 | 24 | |||
2046 | 25 | Once this is done, you can use peer storage from anywhere: | ||
2047 | 26 | |||
2048 | 27 | @hooks.hook("some-hook") | ||
2049 | 28 | def some_hook(): | ||
2050 | 29 | # You can store and retrieve key/values this way: | ||
2051 | 30 | if is_relation_made("cluster"): # from charmhelpers.core.hookenv | ||
2052 | 31 | # There are peers available so we can work with peer storage | ||
2053 | 32 | peer_store("mykey", "myvalue") | ||
2054 | 33 | value = peer_retrieve("mykey") | ||
2055 | 34 | print value | ||
2056 | 35 | else: | ||
2057 | 36 | print "No peers joind the relation, cannot share key/values :(" | ||
2058 | 37 | """ | ||
2059 | 38 | |||
2060 | 39 | |||
2061 | 40 | def peer_retrieve(key, relation_name='cluster'): | ||
2062 | 41 | """Retrieve a named key from peer relation `relation_name`.""" | ||
2063 | 42 | cluster_rels = relation_ids(relation_name) | ||
2064 | 43 | if len(cluster_rels) > 0: | ||
2065 | 44 | cluster_rid = cluster_rels[0] | ||
2066 | 45 | return relation_get(attribute=key, rid=cluster_rid, | ||
2067 | 46 | unit=local_unit()) | ||
2068 | 47 | else: | ||
2069 | 48 | raise ValueError('Unable to detect' | ||
2070 | 49 | 'peer relation {}'.format(relation_name)) | ||
2071 | 50 | |||
2072 | 51 | |||
2073 | 52 | def peer_retrieve_by_prefix(prefix, relation_name='cluster', delimiter='_', | ||
2074 | 53 | inc_list=None, exc_list=None): | ||
2075 | 54 | """ Retrieve k/v pairs given a prefix and filter using {inc,exc}_list """ | ||
2076 | 55 | inc_list = inc_list if inc_list else [] | ||
2077 | 56 | exc_list = exc_list if exc_list else [] | ||
2078 | 57 | peerdb_settings = peer_retrieve('-', relation_name=relation_name) | ||
2079 | 58 | matched = {} | ||
2080 | 59 | for k, v in peerdb_settings.items(): | ||
2081 | 60 | full_prefix = prefix + delimiter | ||
2082 | 61 | if k.startswith(full_prefix): | ||
2083 | 62 | new_key = k.replace(full_prefix, '') | ||
2084 | 63 | if new_key in exc_list: | ||
2085 | 64 | continue | ||
2086 | 65 | if new_key in inc_list or len(inc_list) == 0: | ||
2087 | 66 | matched[new_key] = v | ||
2088 | 67 | return matched | ||
2089 | 68 | |||
2090 | 69 | |||
2091 | 70 | def peer_store(key, value, relation_name='cluster'): | ||
2092 | 71 | """Store the key/value pair on the named peer relation `relation_name`.""" | ||
2093 | 72 | cluster_rels = relation_ids(relation_name) | ||
2094 | 73 | if len(cluster_rels) > 0: | ||
2095 | 74 | cluster_rid = cluster_rels[0] | ||
2096 | 75 | relation_set(relation_id=cluster_rid, | ||
2097 | 76 | relation_settings={key: value}) | ||
2098 | 77 | else: | ||
2099 | 78 | raise ValueError('Unable to detect ' | ||
2100 | 79 | 'peer relation {}'.format(relation_name)) | ||
2101 | 80 | |||
2102 | 81 | |||
2103 | 82 | def peer_echo(includes=None): | ||
2104 | 83 | """Echo filtered attributes back onto the same relation for storage. | ||
2105 | 84 | |||
2106 | 85 | This is a requirement to use the peerstorage module - it needs to be called | ||
2107 | 86 | from the peer relation's changed hook. | ||
2108 | 87 | """ | ||
2109 | 88 | rdata = relation_get() | ||
2110 | 89 | echo_data = {} | ||
2111 | 90 | if includes is None: | ||
2112 | 91 | echo_data = rdata.copy() | ||
2113 | 92 | for ex in ['private-address', 'public-address']: | ||
2114 | 93 | if ex in echo_data: | ||
2115 | 94 | echo_data.pop(ex) | ||
2116 | 95 | else: | ||
2117 | 96 | for attribute, value in rdata.iteritems(): | ||
2118 | 97 | for include in includes: | ||
2119 | 98 | if include in attribute: | ||
2120 | 99 | echo_data[attribute] = value | ||
2121 | 100 | if len(echo_data) > 0: | ||
2122 | 101 | relation_set(relation_settings=echo_data) | ||
2123 | 102 | |||
2124 | 103 | |||
2125 | 104 | def peer_store_and_set(relation_id=None, peer_relation_name='cluster', | ||
2126 | 105 | peer_store_fatal=False, relation_settings=None, | ||
2127 | 106 | delimiter='_', **kwargs): | ||
2128 | 107 | """Store passed-in arguments both in argument relation and in peer storage. | ||
2129 | 108 | |||
2130 | 109 | It functions like doing relation_set() and peer_store() at the same time, | ||
2131 | 110 | with the same data. | ||
2132 | 111 | |||
2133 | 112 | @param relation_id: the id of the relation to store the data on. Defaults | ||
2134 | 113 | to the current relation. | ||
2135 | 114 | @param peer_store_fatal: Set to True, the function will raise an exception | ||
2136 | 115 | should the peer sotrage not be avialable.""" | ||
2137 | 116 | |||
2138 | 117 | relation_settings = relation_settings if relation_settings else {} | ||
2139 | 118 | relation_set(relation_id=relation_id, | ||
2140 | 119 | relation_settings=relation_settings, | ||
2141 | 120 | **kwargs) | ||
2142 | 121 | if is_relation_made(peer_relation_name): | ||
2143 | 122 | for key, value in dict(kwargs.items() + | ||
2144 | 123 | relation_settings.items()).iteritems(): | ||
2145 | 124 | key_prefix = relation_id or current_relation_id() | ||
2146 | 125 | peer_store(key_prefix + delimiter + key, | ||
2147 | 126 | value, | ||
2148 | 127 | relation_name=peer_relation_name) | ||
2149 | 128 | else: | ||
2150 | 129 | if peer_store_fatal: | ||
2151 | 130 | raise ValueError('Unable to detect ' | ||
2152 | 131 | 'peer relation {}'.format(peer_relation_name)) | ||
2153 | 0 | 132 | ||
2154 | === modified file 'hooks/charmhelpers/contrib/storage/linux/ceph.py' | |||
2155 | --- hooks/charmhelpers/contrib/storage/linux/ceph.py 2014-02-24 17:51:34 +0000 | |||
2156 | +++ hooks/charmhelpers/contrib/storage/linux/ceph.py 2014-10-06 15:38:41 +0000 | |||
2157 | @@ -303,7 +303,7 @@ | |||
2158 | 303 | blk_device, fstype, system_services=[]): | 303 | blk_device, fstype, system_services=[]): |
2159 | 304 | """ | 304 | """ |
2160 | 305 | NOTE: This function must only be called from a single service unit for | 305 | NOTE: This function must only be called from a single service unit for |
2162 | 306 | the same rbd_img otherwise data loss will occur. | 306 | the same rbd_img otherwise data loss will occur. |
2163 | 307 | 307 | ||
2164 | 308 | Ensures given pool and RBD image exists, is mapped to a block device, | 308 | Ensures given pool and RBD image exists, is mapped to a block device, |
2165 | 309 | and the device is formatted and mounted at the given mount_point. | 309 | and the device is formatted and mounted at the given mount_point. |
2166 | 310 | 310 | ||
2167 | === added file 'hooks/charmhelpers/core/fstab.py' | |||
2168 | --- hooks/charmhelpers/core/fstab.py 1970-01-01 00:00:00 +0000 | |||
2169 | +++ hooks/charmhelpers/core/fstab.py 2014-10-06 15:38:41 +0000 | |||
2170 | @@ -0,0 +1,116 @@ | |||
2171 | 1 | #!/usr/bin/env python | ||
2172 | 2 | # -*- coding: utf-8 -*- | ||
2173 | 3 | |||
2174 | 4 | __author__ = 'Jorge Niedbalski R. <jorge.niedbalski@canonical.com>' | ||
2175 | 5 | |||
2176 | 6 | import os | ||
2177 | 7 | |||
2178 | 8 | |||
2179 | 9 | class Fstab(file): | ||
2180 | 10 | """This class extends file in order to implement a file reader/writer | ||
2181 | 11 | for file `/etc/fstab` | ||
2182 | 12 | """ | ||
2183 | 13 | |||
2184 | 14 | class Entry(object): | ||
2185 | 15 | """Entry class represents a non-comment line on the `/etc/fstab` file | ||
2186 | 16 | """ | ||
2187 | 17 | def __init__(self, device, mountpoint, filesystem, | ||
2188 | 18 | options, d=0, p=0): | ||
2189 | 19 | self.device = device | ||
2190 | 20 | self.mountpoint = mountpoint | ||
2191 | 21 | self.filesystem = filesystem | ||
2192 | 22 | |||
2193 | 23 | if not options: | ||
2194 | 24 | options = "defaults" | ||
2195 | 25 | |||
2196 | 26 | self.options = options | ||
2197 | 27 | self.d = d | ||
2198 | 28 | self.p = p | ||
2199 | 29 | |||
2200 | 30 | def __eq__(self, o): | ||
2201 | 31 | return str(self) == str(o) | ||
2202 | 32 | |||
2203 | 33 | def __str__(self): | ||
2204 | 34 | return "{} {} {} {} {} {}".format(self.device, | ||
2205 | 35 | self.mountpoint, | ||
2206 | 36 | self.filesystem, | ||
2207 | 37 | self.options, | ||
2208 | 38 | self.d, | ||
2209 | 39 | self.p) | ||
2210 | 40 | |||
2211 | 41 | DEFAULT_PATH = os.path.join(os.path.sep, 'etc', 'fstab') | ||
2212 | 42 | |||
2213 | 43 | def __init__(self, path=None): | ||
2214 | 44 | if path: | ||
2215 | 45 | self._path = path | ||
2216 | 46 | else: | ||
2217 | 47 | self._path = self.DEFAULT_PATH | ||
2218 | 48 | file.__init__(self, self._path, 'r+') | ||
2219 | 49 | |||
2220 | 50 | def _hydrate_entry(self, line): | ||
2221 | 51 | # NOTE: use split with no arguments to split on any | ||
2222 | 52 | # whitespace including tabs | ||
2223 | 53 | return Fstab.Entry(*filter( | ||
2224 | 54 | lambda x: x not in ('', None), | ||
2225 | 55 | line.strip("\n").split())) | ||
2226 | 56 | |||
2227 | 57 | @property | ||
2228 | 58 | def entries(self): | ||
2229 | 59 | self.seek(0) | ||
2230 | 60 | for line in self.readlines(): | ||
2231 | 61 | try: | ||
2232 | 62 | if not line.startswith("#"): | ||
2233 | 63 | yield self._hydrate_entry(line) | ||
2234 | 64 | except ValueError: | ||
2235 | 65 | pass | ||
2236 | 66 | |||
2237 | 67 | def get_entry_by_attr(self, attr, value): | ||
2238 | 68 | for entry in self.entries: | ||
2239 | 69 | e_attr = getattr(entry, attr) | ||
2240 | 70 | if e_attr == value: | ||
2241 | 71 | return entry | ||
2242 | 72 | return None | ||
2243 | 73 | |||
2244 | 74 | def add_entry(self, entry): | ||
2245 | 75 | if self.get_entry_by_attr('device', entry.device): | ||
2246 | 76 | return False | ||
2247 | 77 | |||
2248 | 78 | self.write(str(entry) + '\n') | ||
2249 | 79 | self.truncate() | ||
2250 | 80 | return entry | ||
2251 | 81 | |||
2252 | 82 | def remove_entry(self, entry): | ||
2253 | 83 | self.seek(0) | ||
2254 | 84 | |||
2255 | 85 | lines = self.readlines() | ||
2256 | 86 | |||
2257 | 87 | found = False | ||
2258 | 88 | for index, line in enumerate(lines): | ||
2259 | 89 | if not line.startswith("#"): | ||
2260 | 90 | if self._hydrate_entry(line) == entry: | ||
2261 | 91 | found = True | ||
2262 | 92 | break | ||
2263 | 93 | |||
2264 | 94 | if not found: | ||
2265 | 95 | return False | ||
2266 | 96 | |||
2267 | 97 | lines.remove(line) | ||
2268 | 98 | |||
2269 | 99 | self.seek(0) | ||
2270 | 100 | self.write(''.join(lines)) | ||
2271 | 101 | self.truncate() | ||
2272 | 102 | return True | ||
2273 | 103 | |||
2274 | 104 | @classmethod | ||
2275 | 105 | def remove_by_mountpoint(cls, mountpoint, path=None): | ||
2276 | 106 | fstab = cls(path=path) | ||
2277 | 107 | entry = fstab.get_entry_by_attr('mountpoint', mountpoint) | ||
2278 | 108 | if entry: | ||
2279 | 109 | return fstab.remove_entry(entry) | ||
2280 | 110 | return False | ||
2281 | 111 | |||
2282 | 112 | @classmethod | ||
2283 | 113 | def add(cls, device, mountpoint, filesystem, options=None, path=None): | ||
2284 | 114 | return cls(path=path).add_entry(Fstab.Entry(device, | ||
2285 | 115 | mountpoint, filesystem, | ||
2286 | 116 | options=options)) | ||
2287 | 0 | 117 | ||
2288 | === renamed file 'hooks/charmhelpers/core/fstab.py' => 'hooks/charmhelpers/core/fstab.py.moved' | |||
2289 | === modified file 'hooks/charmhelpers/core/hookenv.py' | |||
2290 | --- hooks/charmhelpers/core/hookenv.py 2014-05-19 11:39:11 +0000 | |||
2291 | +++ hooks/charmhelpers/core/hookenv.py 2014-10-06 15:38:41 +0000 | |||
2292 | @@ -25,7 +25,7 @@ | |||
2293 | 25 | def cached(func): | 25 | def cached(func): |
2294 | 26 | """Cache return values for multiple executions of func + args | 26 | """Cache return values for multiple executions of func + args |
2295 | 27 | 27 | ||
2297 | 28 | For example: | 28 | For example:: |
2298 | 29 | 29 | ||
2299 | 30 | @cached | 30 | @cached |
2300 | 31 | def unit_get(attribute): | 31 | def unit_get(attribute): |
2301 | @@ -156,12 +156,15 @@ | |||
2302 | 156 | 156 | ||
2303 | 157 | 157 | ||
2304 | 158 | class Config(dict): | 158 | class Config(dict): |
2311 | 159 | """A Juju charm config dictionary that can write itself to | 159 | """A dictionary representation of the charm's config.yaml, with some |
2312 | 160 | disk (as json) and track which values have changed since | 160 | extra features: |
2313 | 161 | the previous hook invocation. | 161 | |
2314 | 162 | 162 | - See which values in the dictionary have changed since the previous hook. | |
2315 | 163 | Do not instantiate this object directly - instead call | 163 | - For values that have changed, see what the previous value was. |
2316 | 164 | ``hookenv.config()`` | 164 | - Store arbitrary data for use in a later hook. |
2317 | 165 | |||
2318 | 166 | NOTE: Do not instantiate this object directly - instead call | ||
2319 | 167 | ``hookenv.config()``, which will return an instance of :class:`Config`. | ||
2320 | 165 | 168 | ||
2321 | 166 | Example usage:: | 169 | Example usage:: |
2322 | 167 | 170 | ||
2323 | @@ -170,8 +173,8 @@ | |||
2324 | 170 | >>> config = hookenv.config() | 173 | >>> config = hookenv.config() |
2325 | 171 | >>> config['foo'] | 174 | >>> config['foo'] |
2326 | 172 | 'bar' | 175 | 'bar' |
2327 | 176 | >>> # store a new key/value for later use | ||
2328 | 173 | >>> config['mykey'] = 'myval' | 177 | >>> config['mykey'] = 'myval' |
2329 | 174 | >>> config.save() | ||
2330 | 175 | 178 | ||
2331 | 176 | 179 | ||
2332 | 177 | >>> # user runs `juju set mycharm foo=baz` | 180 | >>> # user runs `juju set mycharm foo=baz` |
2333 | @@ -188,22 +191,34 @@ | |||
2334 | 188 | >>> # keys/values that we add are preserved across hooks | 191 | >>> # keys/values that we add are preserved across hooks |
2335 | 189 | >>> config['mykey'] | 192 | >>> config['mykey'] |
2336 | 190 | 'myval' | 193 | 'myval' |
2337 | 191 | >>> # don't forget to save at the end of hook! | ||
2338 | 192 | >>> config.save() | ||
2339 | 193 | 194 | ||
2340 | 194 | """ | 195 | """ |
2341 | 195 | CONFIG_FILE_NAME = '.juju-persistent-config' | 196 | CONFIG_FILE_NAME = '.juju-persistent-config' |
2342 | 196 | 197 | ||
2343 | 197 | def __init__(self, *args, **kw): | 198 | def __init__(self, *args, **kw): |
2344 | 198 | super(Config, self).__init__(*args, **kw) | 199 | super(Config, self).__init__(*args, **kw) |
2345 | 200 | self.implicit_save = True | ||
2346 | 199 | self._prev_dict = None | 201 | self._prev_dict = None |
2347 | 200 | self.path = os.path.join(charm_dir(), Config.CONFIG_FILE_NAME) | 202 | self.path = os.path.join(charm_dir(), Config.CONFIG_FILE_NAME) |
2348 | 201 | if os.path.exists(self.path): | 203 | if os.path.exists(self.path): |
2349 | 202 | self.load_previous() | 204 | self.load_previous() |
2350 | 203 | 205 | ||
2351 | 206 | def __getitem__(self, key): | ||
2352 | 207 | """For regular dict lookups, check the current juju config first, | ||
2353 | 208 | then the previous (saved) copy. This ensures that user-saved values | ||
2354 | 209 | will be returned by a dict lookup. | ||
2355 | 210 | |||
2356 | 211 | """ | ||
2357 | 212 | try: | ||
2358 | 213 | return dict.__getitem__(self, key) | ||
2359 | 214 | except KeyError: | ||
2360 | 215 | return (self._prev_dict or {})[key] | ||
2361 | 216 | |||
2362 | 204 | def load_previous(self, path=None): | 217 | def load_previous(self, path=None): |
2365 | 205 | """Load previous copy of config from disk so that current values | 218 | """Load previous copy of config from disk. |
2366 | 206 | can be compared to previous values. | 219 | |
2367 | 220 | In normal usage you don't need to call this method directly - it | ||
2368 | 221 | is called automatically at object initialization. | ||
2369 | 207 | 222 | ||
2370 | 208 | :param path: | 223 | :param path: |
2371 | 209 | 224 | ||
2372 | @@ -218,8 +233,8 @@ | |||
2373 | 218 | self._prev_dict = json.load(f) | 233 | self._prev_dict = json.load(f) |
2374 | 219 | 234 | ||
2375 | 220 | def changed(self, key): | 235 | def changed(self, key): |
2378 | 221 | """Return true if the value for this key has changed since | 236 | """Return True if the current value for this key is different from |
2379 | 222 | the last save. | 237 | the previous value. |
2380 | 223 | 238 | ||
2381 | 224 | """ | 239 | """ |
2382 | 225 | if self._prev_dict is None: | 240 | if self._prev_dict is None: |
2383 | @@ -228,7 +243,7 @@ | |||
2384 | 228 | 243 | ||
2385 | 229 | def previous(self, key): | 244 | def previous(self, key): |
2386 | 230 | """Return previous value for this key, or None if there | 245 | """Return previous value for this key, or None if there |
2388 | 231 | is no "previous" value. | 246 | is no previous value. |
2389 | 232 | 247 | ||
2390 | 233 | """ | 248 | """ |
2391 | 234 | if self._prev_dict: | 249 | if self._prev_dict: |
2392 | @@ -238,7 +253,13 @@ | |||
2393 | 238 | def save(self): | 253 | def save(self): |
2394 | 239 | """Save this config to disk. | 254 | """Save this config to disk. |
2395 | 240 | 255 | ||
2397 | 241 | Preserves items in _prev_dict that do not exist in self. | 256 | If the charm is using the :mod:`Services Framework <services.base>` |
2398 | 257 | or :meth:'@hook <Hooks.hook>' decorator, this | ||
2399 | 258 | is called automatically at the end of successful hook execution. | ||
2400 | 259 | Otherwise, it should be called directly by user code. | ||
2401 | 260 | |||
2402 | 261 | To disable automatic saves, set ``implicit_save=False`` on this | ||
2403 | 262 | instance. | ||
2404 | 242 | 263 | ||
2405 | 243 | """ | 264 | """ |
2406 | 244 | if self._prev_dict: | 265 | if self._prev_dict: |
2407 | @@ -285,8 +306,9 @@ | |||
2408 | 285 | raise | 306 | raise |
2409 | 286 | 307 | ||
2410 | 287 | 308 | ||
2412 | 288 | def relation_set(relation_id=None, relation_settings={}, **kwargs): | 309 | def relation_set(relation_id=None, relation_settings=None, **kwargs): |
2413 | 289 | """Set relation information for the current unit""" | 310 | """Set relation information for the current unit""" |
2414 | 311 | relation_settings = relation_settings if relation_settings else {} | ||
2415 | 290 | relation_cmd_line = ['relation-set'] | 312 | relation_cmd_line = ['relation-set'] |
2416 | 291 | if relation_id is not None: | 313 | if relation_id is not None: |
2417 | 292 | relation_cmd_line.extend(('-r', relation_id)) | 314 | relation_cmd_line.extend(('-r', relation_id)) |
2418 | @@ -445,27 +467,29 @@ | |||
2419 | 445 | class Hooks(object): | 467 | class Hooks(object): |
2420 | 446 | """A convenient handler for hook functions. | 468 | """A convenient handler for hook functions. |
2421 | 447 | 469 | ||
2423 | 448 | Example: | 470 | Example:: |
2424 | 471 | |||
2425 | 449 | hooks = Hooks() | 472 | hooks = Hooks() |
2426 | 450 | 473 | ||
2427 | 451 | # register a hook, taking its name from the function name | 474 | # register a hook, taking its name from the function name |
2428 | 452 | @hooks.hook() | 475 | @hooks.hook() |
2429 | 453 | def install(): | 476 | def install(): |
2431 | 454 | ... | 477 | pass # your code here |
2432 | 455 | 478 | ||
2433 | 456 | # register a hook, providing a custom hook name | 479 | # register a hook, providing a custom hook name |
2434 | 457 | @hooks.hook("config-changed") | 480 | @hooks.hook("config-changed") |
2435 | 458 | def config_changed(): | 481 | def config_changed(): |
2437 | 459 | ... | 482 | pass # your code here |
2438 | 460 | 483 | ||
2439 | 461 | if __name__ == "__main__": | 484 | if __name__ == "__main__": |
2440 | 462 | # execute a hook based on the name the program is called by | 485 | # execute a hook based on the name the program is called by |
2441 | 463 | hooks.execute(sys.argv) | 486 | hooks.execute(sys.argv) |
2442 | 464 | """ | 487 | """ |
2443 | 465 | 488 | ||
2445 | 466 | def __init__(self): | 489 | def __init__(self, config_save=True): |
2446 | 467 | super(Hooks, self).__init__() | 490 | super(Hooks, self).__init__() |
2447 | 468 | self._hooks = {} | 491 | self._hooks = {} |
2448 | 492 | self._config_save = config_save | ||
2449 | 469 | 493 | ||
2450 | 470 | def register(self, name, function): | 494 | def register(self, name, function): |
2451 | 471 | """Register a hook""" | 495 | """Register a hook""" |
2452 | @@ -476,6 +500,10 @@ | |||
2453 | 476 | hook_name = os.path.basename(args[0]) | 500 | hook_name = os.path.basename(args[0]) |
2454 | 477 | if hook_name in self._hooks: | 501 | if hook_name in self._hooks: |
2455 | 478 | self._hooks[hook_name]() | 502 | self._hooks[hook_name]() |
2456 | 503 | if self._config_save: | ||
2457 | 504 | cfg = config() | ||
2458 | 505 | if cfg.implicit_save: | ||
2459 | 506 | cfg.save() | ||
2460 | 479 | else: | 507 | else: |
2461 | 480 | raise UnregisteredHookError(hook_name) | 508 | raise UnregisteredHookError(hook_name) |
2462 | 481 | 509 | ||
2463 | 482 | 510 | ||
2464 | === modified file 'hooks/charmhelpers/core/host.py' | |||
2465 | --- hooks/charmhelpers/core/host.py 2014-08-27 07:17:33 +0000 | |||
2466 | +++ hooks/charmhelpers/core/host.py 2014-10-06 15:38:41 +0000 | |||
2467 | @@ -12,7 +12,8 @@ | |||
2468 | 12 | import string | 12 | import string |
2469 | 13 | import subprocess | 13 | import subprocess |
2470 | 14 | import hashlib | 14 | import hashlib |
2472 | 15 | import apt_pkg | 15 | import shutil |
2473 | 16 | from contextlib import contextmanager | ||
2474 | 16 | 17 | ||
2475 | 17 | from collections import OrderedDict | 18 | from collections import OrderedDict |
2476 | 18 | 19 | ||
2477 | @@ -53,7 +54,7 @@ | |||
2478 | 53 | def service_running(service): | 54 | def service_running(service): |
2479 | 54 | """Determine whether a system service is running""" | 55 | """Determine whether a system service is running""" |
2480 | 55 | try: | 56 | try: |
2482 | 56 | output = subprocess.check_output(['service', service, 'status']) | 57 | output = subprocess.check_output(['service', service, 'status'], stderr=subprocess.STDOUT) |
2483 | 57 | except subprocess.CalledProcessError: | 58 | except subprocess.CalledProcessError: |
2484 | 58 | return False | 59 | return False |
2485 | 59 | else: | 60 | else: |
2486 | @@ -63,6 +64,16 @@ | |||
2487 | 63 | return False | 64 | return False |
2488 | 64 | 65 | ||
2489 | 65 | 66 | ||
2490 | 67 | def service_available(service_name): | ||
2491 | 68 | """Determine whether a system service is available""" | ||
2492 | 69 | try: | ||
2493 | 70 | subprocess.check_output(['service', service_name, 'status'], stderr=subprocess.STDOUT) | ||
2494 | 71 | except subprocess.CalledProcessError as e: | ||
2495 | 72 | return 'unrecognized service' not in e.output | ||
2496 | 73 | else: | ||
2497 | 74 | return True | ||
2498 | 75 | |||
2499 | 76 | |||
2500 | 66 | def adduser(username, password=None, shell='/bin/bash', system_user=False): | 77 | def adduser(username, password=None, shell='/bin/bash', system_user=False): |
2501 | 67 | """Add a user to the system""" | 78 | """Add a user to the system""" |
2502 | 68 | try: | 79 | try: |
2503 | @@ -198,10 +209,15 @@ | |||
2504 | 198 | return system_mounts | 209 | return system_mounts |
2505 | 199 | 210 | ||
2506 | 200 | 211 | ||
2509 | 201 | def file_hash(path): | 212 | def file_hash(path, hash_type='md5'): |
2510 | 202 | """Generate a md5 hash of the contents of 'path' or None if not found """ | 213 | """ |
2511 | 214 | Generate a hash checksum of the contents of 'path' or None if not found. | ||
2512 | 215 | |||
2513 | 216 | :param str hash_type: Any hash alrgorithm supported by :mod:`hashlib`, | ||
2514 | 217 | such as md5, sha1, sha256, sha512, etc. | ||
2515 | 218 | """ | ||
2516 | 203 | if os.path.exists(path): | 219 | if os.path.exists(path): |
2518 | 204 | h = hashlib.md5() | 220 | h = getattr(hashlib, hash_type)() |
2519 | 205 | with open(path, 'r') as source: | 221 | with open(path, 'r') as source: |
2520 | 206 | h.update(source.read()) # IGNORE:E1101 - it does have update | 222 | h.update(source.read()) # IGNORE:E1101 - it does have update |
2521 | 207 | return h.hexdigest() | 223 | return h.hexdigest() |
2522 | @@ -209,16 +225,36 @@ | |||
2523 | 209 | return None | 225 | return None |
2524 | 210 | 226 | ||
2525 | 211 | 227 | ||
2526 | 228 | def check_hash(path, checksum, hash_type='md5'): | ||
2527 | 229 | """ | ||
2528 | 230 | Validate a file using a cryptographic checksum. | ||
2529 | 231 | |||
2530 | 232 | :param str checksum: Value of the checksum used to validate the file. | ||
2531 | 233 | :param str hash_type: Hash algorithm used to generate `checksum`. | ||
2532 | 234 | Can be any hash alrgorithm supported by :mod:`hashlib`, | ||
2533 | 235 | such as md5, sha1, sha256, sha512, etc. | ||
2534 | 236 | :raises ChecksumError: If the file fails the checksum | ||
2535 | 237 | |||
2536 | 238 | """ | ||
2537 | 239 | actual_checksum = file_hash(path, hash_type) | ||
2538 | 240 | if checksum != actual_checksum: | ||
2539 | 241 | raise ChecksumError("'%s' != '%s'" % (checksum, actual_checksum)) | ||
2540 | 242 | |||
2541 | 243 | |||
2542 | 244 | class ChecksumError(ValueError): | ||
2543 | 245 | pass | ||
2544 | 246 | |||
2545 | 247 | |||
2546 | 212 | def restart_on_change(restart_map, stopstart=False): | 248 | def restart_on_change(restart_map, stopstart=False): |
2547 | 213 | """Restart services based on configuration files changing | 249 | """Restart services based on configuration files changing |
2548 | 214 | 250 | ||
2550 | 215 | This function is used a decorator, for example | 251 | This function is used a decorator, for example:: |
2551 | 216 | 252 | ||
2552 | 217 | @restart_on_change({ | 253 | @restart_on_change({ |
2553 | 218 | '/etc/ceph/ceph.conf': [ 'cinder-api', 'cinder-volume' ] | 254 | '/etc/ceph/ceph.conf': [ 'cinder-api', 'cinder-volume' ] |
2554 | 219 | }) | 255 | }) |
2555 | 220 | def ceph_client_changed(): | 256 | def ceph_client_changed(): |
2557 | 221 | ... | 257 | pass # your code here |
2558 | 222 | 258 | ||
2559 | 223 | In this example, the cinder-api and cinder-volume services | 259 | In this example, the cinder-api and cinder-volume services |
2560 | 224 | would be restarted if /etc/ceph/ceph.conf is changed by the | 260 | would be restarted if /etc/ceph/ceph.conf is changed by the |
2561 | @@ -314,12 +350,40 @@ | |||
2562 | 314 | 350 | ||
2563 | 315 | def cmp_pkgrevno(package, revno, pkgcache=None): | 351 | def cmp_pkgrevno(package, revno, pkgcache=None): |
2564 | 316 | '''Compare supplied revno with the revno of the installed package | 352 | '''Compare supplied revno with the revno of the installed package |
2568 | 317 | 1 => Installed revno is greater than supplied arg | 353 | |
2569 | 318 | 0 => Installed revno is the same as supplied arg | 354 | * 1 => Installed revno is greater than supplied arg |
2570 | 319 | -1 => Installed revno is less than supplied arg | 355 | * 0 => Installed revno is the same as supplied arg |
2571 | 356 | * -1 => Installed revno is less than supplied arg | ||
2572 | 357 | |||
2573 | 320 | ''' | 358 | ''' |
2575 | 321 | from charmhelpers.fetch import apt_cache | 359 | <<<<<<< TREE |
2576 | 360 | from charmhelpers.fetch import apt_cache | ||
2577 | 361 | ======= | ||
2578 | 362 | import apt_pkg | ||
2579 | 363 | from charmhelpers.fetch import apt_cache | ||
2580 | 364 | >>>>>>> MERGE-SOURCE | ||
2581 | 322 | if not pkgcache: | 365 | if not pkgcache: |
2582 | 323 | pkgcache = apt_cache() | 366 | pkgcache = apt_cache() |
2583 | 324 | pkg = pkgcache[package] | 367 | pkg = pkgcache[package] |
2584 | 325 | return apt_pkg.version_compare(pkg.current_ver.ver_str, revno) | 368 | return apt_pkg.version_compare(pkg.current_ver.ver_str, revno) |
2585 | 369 | |||
2586 | 370 | |||
2587 | 371 | @contextmanager | ||
2588 | 372 | def chdir(d): | ||
2589 | 373 | cur = os.getcwd() | ||
2590 | 374 | try: | ||
2591 | 375 | yield os.chdir(d) | ||
2592 | 376 | finally: | ||
2593 | 377 | os.chdir(cur) | ||
2594 | 378 | |||
2595 | 379 | |||
2596 | 380 | def chownr(path, owner, group): | ||
2597 | 381 | uid = pwd.getpwnam(owner).pw_uid | ||
2598 | 382 | gid = grp.getgrnam(group).gr_gid | ||
2599 | 383 | |||
2600 | 384 | for root, dirs, files in os.walk(path): | ||
2601 | 385 | for name in dirs + files: | ||
2602 | 386 | full = os.path.join(root, name) | ||
2603 | 387 | broken_symlink = os.path.lexists(full) and not os.path.exists(full) | ||
2604 | 388 | if not broken_symlink: | ||
2605 | 389 | os.chown(full, uid, gid) | ||
2606 | 326 | 390 | ||
2607 | === added directory 'hooks/charmhelpers/core/services' | |||
2608 | === added file 'hooks/charmhelpers/core/services/__init__.py' | |||
2609 | --- hooks/charmhelpers/core/services/__init__.py 1970-01-01 00:00:00 +0000 | |||
2610 | +++ hooks/charmhelpers/core/services/__init__.py 2014-10-06 15:38:41 +0000 | |||
2611 | @@ -0,0 +1,2 @@ | |||
2612 | 1 | from .base import * | ||
2613 | 2 | from .helpers import * | ||
2614 | 0 | 3 | ||
2615 | === added file 'hooks/charmhelpers/core/services/base.py' | |||
2616 | --- hooks/charmhelpers/core/services/base.py 1970-01-01 00:00:00 +0000 | |||
2617 | +++ hooks/charmhelpers/core/services/base.py 2014-10-06 15:38:41 +0000 | |||
2618 | @@ -0,0 +1,313 @@ | |||
2619 | 1 | import os | ||
2620 | 2 | import re | ||
2621 | 3 | import json | ||
2622 | 4 | from collections import Iterable | ||
2623 | 5 | |||
2624 | 6 | from charmhelpers.core import host | ||
2625 | 7 | from charmhelpers.core import hookenv | ||
2626 | 8 | |||
2627 | 9 | |||
2628 | 10 | __all__ = ['ServiceManager', 'ManagerCallback', | ||
2629 | 11 | 'PortManagerCallback', 'open_ports', 'close_ports', 'manage_ports', | ||
2630 | 12 | 'service_restart', 'service_stop'] | ||
2631 | 13 | |||
2632 | 14 | |||
2633 | 15 | class ServiceManager(object): | ||
2634 | 16 | def __init__(self, services=None): | ||
2635 | 17 | """ | ||
2636 | 18 | Register a list of services, given their definitions. | ||
2637 | 19 | |||
2638 | 20 | Service definitions are dicts in the following formats (all keys except | ||
2639 | 21 | 'service' are optional):: | ||
2640 | 22 | |||
2641 | 23 | { | ||
2642 | 24 | "service": <service name>, | ||
2643 | 25 | "required_data": <list of required data contexts>, | ||
2644 | 26 | "provided_data": <list of provided data contexts>, | ||
2645 | 27 | "data_ready": <one or more callbacks>, | ||
2646 | 28 | "data_lost": <one or more callbacks>, | ||
2647 | 29 | "start": <one or more callbacks>, | ||
2648 | 30 | "stop": <one or more callbacks>, | ||
2649 | 31 | "ports": <list of ports to manage>, | ||
2650 | 32 | } | ||
2651 | 33 | |||
2652 | 34 | The 'required_data' list should contain dicts of required data (or | ||
2653 | 35 | dependency managers that act like dicts and know how to collect the data). | ||
2654 | 36 | Only when all items in the 'required_data' list are populated are the list | ||
2655 | 37 | of 'data_ready' and 'start' callbacks executed. See `is_ready()` for more | ||
2656 | 38 | information. | ||
2657 | 39 | |||
2658 | 40 | The 'provided_data' list should contain relation data providers, most likely | ||
2659 | 41 | a subclass of :class:`charmhelpers.core.services.helpers.RelationContext`, | ||
2660 | 42 | that will indicate a set of data to set on a given relation. | ||
2661 | 43 | |||
2662 | 44 | The 'data_ready' value should be either a single callback, or a list of | ||
2663 | 45 | callbacks, to be called when all items in 'required_data' pass `is_ready()`. | ||
2664 | 46 | Each callback will be called with the service name as the only parameter. | ||
2665 | 47 | After all of the 'data_ready' callbacks are called, the 'start' callbacks | ||
2666 | 48 | are fired. | ||
2667 | 49 | |||
2668 | 50 | The 'data_lost' value should be either a single callback, or a list of | ||
2669 | 51 | callbacks, to be called when a 'required_data' item no longer passes | ||
2670 | 52 | `is_ready()`. Each callback will be called with the service name as the | ||
2671 | 53 | only parameter. After all of the 'data_lost' callbacks are called, | ||
2672 | 54 | the 'stop' callbacks are fired. | ||
2673 | 55 | |||
2674 | 56 | The 'start' value should be either a single callback, or a list of | ||
2675 | 57 | callbacks, to be called when starting the service, after the 'data_ready' | ||
2676 | 58 | callbacks are complete. Each callback will be called with the service | ||
2677 | 59 | name as the only parameter. This defaults to | ||
2678 | 60 | `[host.service_start, services.open_ports]`. | ||
2679 | 61 | |||
2680 | 62 | The 'stop' value should be either a single callback, or a list of | ||
2681 | 63 | callbacks, to be called when stopping the service. If the service is | ||
2682 | 64 | being stopped because it no longer has all of its 'required_data', this | ||
2683 | 65 | will be called after all of the 'data_lost' callbacks are complete. | ||
2684 | 66 | Each callback will be called with the service name as the only parameter. | ||
2685 | 67 | This defaults to `[services.close_ports, host.service_stop]`. | ||
2686 | 68 | |||
2687 | 69 | The 'ports' value should be a list of ports to manage. The default | ||
2688 | 70 | 'start' handler will open the ports after the service is started, | ||
2689 | 71 | and the default 'stop' handler will close the ports prior to stopping | ||
2690 | 72 | the service. | ||
2691 | 73 | |||
2692 | 74 | |||
2693 | 75 | Examples: | ||
2694 | 76 | |||
2695 | 77 | The following registers an Upstart service called bingod that depends on | ||
2696 | 78 | a mongodb relation and which runs a custom `db_migrate` function prior to | ||
2697 | 79 | restarting the service, and a Runit service called spadesd:: | ||
2698 | 80 | |||
2699 | 81 | manager = services.ServiceManager([ | ||
2700 | 82 | { | ||
2701 | 83 | 'service': 'bingod', | ||
2702 | 84 | 'ports': [80, 443], | ||
2703 | 85 | 'required_data': [MongoRelation(), config(), {'my': 'data'}], | ||
2704 | 86 | 'data_ready': [ | ||
2705 | 87 | services.template(source='bingod.conf'), | ||
2706 | 88 | services.template(source='bingod.ini', | ||
2707 | 89 | target='/etc/bingod.ini', | ||
2708 | 90 | owner='bingo', perms=0400), | ||
2709 | 91 | ], | ||
2710 | 92 | }, | ||
2711 | 93 | { | ||
2712 | 94 | 'service': 'spadesd', | ||
2713 | 95 | 'data_ready': services.template(source='spadesd_run.j2', | ||
2714 | 96 | target='/etc/sv/spadesd/run', | ||
2715 | 97 | perms=0555), | ||
2716 | 98 | 'start': runit_start, | ||
2717 | 99 | 'stop': runit_stop, | ||
2718 | 100 | }, | ||
2719 | 101 | ]) | ||
2720 | 102 | manager.manage() | ||
2721 | 103 | """ | ||
2722 | 104 | self._ready_file = os.path.join(hookenv.charm_dir(), 'READY-SERVICES.json') | ||
2723 | 105 | self._ready = None | ||
2724 | 106 | self.services = {} | ||
2725 | 107 | for service in services or []: | ||
2726 | 108 | service_name = service['service'] | ||
2727 | 109 | self.services[service_name] = service | ||
2728 | 110 | |||
2729 | 111 | def manage(self): | ||
2730 | 112 | """ | ||
2731 | 113 | Handle the current hook by doing The Right Thing with the registered services. | ||
2732 | 114 | """ | ||
2733 | 115 | hook_name = hookenv.hook_name() | ||
2734 | 116 | if hook_name == 'stop': | ||
2735 | 117 | self.stop_services() | ||
2736 | 118 | else: | ||
2737 | 119 | self.provide_data() | ||
2738 | 120 | self.reconfigure_services() | ||
2739 | 121 | cfg = hookenv.config() | ||
2740 | 122 | if cfg.implicit_save: | ||
2741 | 123 | cfg.save() | ||
2742 | 124 | |||
2743 | 125 | def provide_data(self): | ||
2744 | 126 | """ | ||
2745 | 127 | Set the relation data for each provider in the ``provided_data`` list. | ||
2746 | 128 | |||
2747 | 129 | A provider must have a `name` attribute, which indicates which relation | ||
2748 | 130 | to set data on, and a `provide_data()` method, which returns a dict of | ||
2749 | 131 | data to set. | ||
2750 | 132 | """ | ||
2751 | 133 | hook_name = hookenv.hook_name() | ||
2752 | 134 | for service in self.services.values(): | ||
2753 | 135 | for provider in service.get('provided_data', []): | ||
2754 | 136 | if re.match(r'{}-relation-(joined|changed)'.format(provider.name), hook_name): | ||
2755 | 137 | data = provider.provide_data() | ||
2756 | 138 | _ready = provider._is_ready(data) if hasattr(provider, '_is_ready') else data | ||
2757 | 139 | if _ready: | ||
2758 | 140 | hookenv.relation_set(None, data) | ||
2759 | 141 | |||
2760 | 142 | def reconfigure_services(self, *service_names): | ||
2761 | 143 | """ | ||
2762 | 144 | Update all files for one or more registered services, and, | ||
2763 | 145 | if ready, optionally restart them. | ||
2764 | 146 | |||
2765 | 147 | If no service names are given, reconfigures all registered services. | ||
2766 | 148 | """ | ||
2767 | 149 | for service_name in service_names or self.services.keys(): | ||
2768 | 150 | if self.is_ready(service_name): | ||
2769 | 151 | self.fire_event('data_ready', service_name) | ||
2770 | 152 | self.fire_event('start', service_name, default=[ | ||
2771 | 153 | service_restart, | ||
2772 | 154 | manage_ports]) | ||
2773 | 155 | self.save_ready(service_name) | ||
2774 | 156 | else: | ||
2775 | 157 | if self.was_ready(service_name): | ||
2776 | 158 | self.fire_event('data_lost', service_name) | ||
2777 | 159 | self.fire_event('stop', service_name, default=[ | ||
2778 | 160 | manage_ports, | ||
2779 | 161 | service_stop]) | ||
2780 | 162 | self.save_lost(service_name) | ||
2781 | 163 | |||
2782 | 164 | def stop_services(self, *service_names): | ||
2783 | 165 | """ | ||
2784 | 166 | Stop one or more registered services, by name. | ||
2785 | 167 | |||
2786 | 168 | If no service names are given, stops all registered services. | ||
2787 | 169 | """ | ||
2788 | 170 | for service_name in service_names or self.services.keys(): | ||
2789 | 171 | self.fire_event('stop', service_name, default=[ | ||
2790 | 172 | manage_ports, | ||
2791 | 173 | service_stop]) | ||
2792 | 174 | |||
2793 | 175 | def get_service(self, service_name): | ||
2794 | 176 | """ | ||
2795 | 177 | Given the name of a registered service, return its service definition. | ||
2796 | 178 | """ | ||
2797 | 179 | service = self.services.get(service_name) | ||
2798 | 180 | if not service: | ||
2799 | 181 | raise KeyError('Service not registered: %s' % service_name) | ||
2800 | 182 | return service | ||
2801 | 183 | |||
2802 | 184 | def fire_event(self, event_name, service_name, default=None): | ||
2803 | 185 | """ | ||
2804 | 186 | Fire a data_ready, data_lost, start, or stop event on a given service. | ||
2805 | 187 | """ | ||
2806 | 188 | service = self.get_service(service_name) | ||
2807 | 189 | callbacks = service.get(event_name, default) | ||
2808 | 190 | if not callbacks: | ||
2809 | 191 | return | ||
2810 | 192 | if not isinstance(callbacks, Iterable): | ||
2811 | 193 | callbacks = [callbacks] | ||
2812 | 194 | for callback in callbacks: | ||
2813 | 195 | if isinstance(callback, ManagerCallback): | ||
2814 | 196 | callback(self, service_name, event_name) | ||
2815 | 197 | else: | ||
2816 | 198 | callback(service_name) | ||
2817 | 199 | |||
2818 | 200 | def is_ready(self, service_name): | ||
2819 | 201 | """ | ||
2820 | 202 | Determine if a registered service is ready, by checking its 'required_data'. | ||
2821 | 203 | |||
2822 | 204 | A 'required_data' item can be any mapping type, and is considered ready | ||
2823 | 205 | if `bool(item)` evaluates as True. | ||
2824 | 206 | """ | ||
2825 | 207 | service = self.get_service(service_name) | ||
2826 | 208 | reqs = service.get('required_data', []) | ||
2827 | 209 | return all(bool(req) for req in reqs) | ||
2828 | 210 | |||
2829 | 211 | def _load_ready_file(self): | ||
2830 | 212 | if self._ready is not None: | ||
2831 | 213 | return | ||
2832 | 214 | if os.path.exists(self._ready_file): | ||
2833 | 215 | with open(self._ready_file) as fp: | ||
2834 | 216 | self._ready = set(json.load(fp)) | ||
2835 | 217 | else: | ||
2836 | 218 | self._ready = set() | ||
2837 | 219 | |||
2838 | 220 | def _save_ready_file(self): | ||
2839 | 221 | if self._ready is None: | ||
2840 | 222 | return | ||
2841 | 223 | with open(self._ready_file, 'w') as fp: | ||
2842 | 224 | json.dump(list(self._ready), fp) | ||
2843 | 225 | |||
2844 | 226 | def save_ready(self, service_name): | ||
2845 | 227 | """ | ||
2846 | 228 | Save an indicator that the given service is now data_ready. | ||
2847 | 229 | """ | ||
2848 | 230 | self._load_ready_file() | ||
2849 | 231 | self._ready.add(service_name) | ||
2850 | 232 | self._save_ready_file() | ||
2851 | 233 | |||
2852 | 234 | def save_lost(self, service_name): | ||
2853 | 235 | """ | ||
2854 | 236 | Save an indicator that the given service is no longer data_ready. | ||
2855 | 237 | """ | ||
2856 | 238 | self._load_ready_file() | ||
2857 | 239 | self._ready.discard(service_name) | ||
2858 | 240 | self._save_ready_file() | ||
2859 | 241 | |||
2860 | 242 | def was_ready(self, service_name): | ||
2861 | 243 | """ | ||
2862 | 244 | Determine if the given service was previously data_ready. | ||
2863 | 245 | """ | ||
2864 | 246 | self._load_ready_file() | ||
2865 | 247 | return service_name in self._ready | ||
2866 | 248 | |||
2867 | 249 | |||
2868 | 250 | class ManagerCallback(object): | ||
2869 | 251 | """ | ||
2870 | 252 | Special case of a callback that takes the `ServiceManager` instance | ||
2871 | 253 | in addition to the service name. | ||
2872 | 254 | |||
2873 | 255 | Subclasses should implement `__call__` which should accept three parameters: | ||
2874 | 256 | |||
2875 | 257 | * `manager` The `ServiceManager` instance | ||
2876 | 258 | * `service_name` The name of the service it's being triggered for | ||
2877 | 259 | * `event_name` The name of the event that this callback is handling | ||
2878 | 260 | """ | ||
2879 | 261 | def __call__(self, manager, service_name, event_name): | ||
2880 | 262 | raise NotImplementedError() | ||
2881 | 263 | |||
2882 | 264 | |||
2883 | 265 | class PortManagerCallback(ManagerCallback): | ||
2884 | 266 | """ | ||
2885 | 267 | Callback class that will open or close ports, for use as either | ||
2886 | 268 | a start or stop action. | ||
2887 | 269 | """ | ||
2888 | 270 | def __call__(self, manager, service_name, event_name): | ||
2889 | 271 | service = manager.get_service(service_name) | ||
2890 | 272 | new_ports = service.get('ports', []) | ||
2891 | 273 | port_file = os.path.join(hookenv.charm_dir(), '.{}.ports'.format(service_name)) | ||
2892 | 274 | if os.path.exists(port_file): | ||
2893 | 275 | with open(port_file) as fp: | ||
2894 | 276 | old_ports = fp.read().split(',') | ||
2895 | 277 | for old_port in old_ports: | ||
2896 | 278 | if bool(old_port): | ||
2897 | 279 | old_port = int(old_port) | ||
2898 | 280 | if old_port not in new_ports: | ||
2899 | 281 | hookenv.close_port(old_port) | ||
2900 | 282 | with open(port_file, 'w') as fp: | ||
2901 | 283 | fp.write(','.join(str(port) for port in new_ports)) | ||
2902 | 284 | for port in new_ports: | ||
2903 | 285 | if event_name == 'start': | ||
2904 | 286 | hookenv.open_port(port) | ||
2905 | 287 | elif event_name == 'stop': | ||
2906 | 288 | hookenv.close_port(port) | ||
2907 | 289 | |||
2908 | 290 | |||
2909 | 291 | def service_stop(service_name): | ||
2910 | 292 | """ | ||
2911 | 293 | Wrapper around host.service_stop to prevent spurious "unknown service" | ||
2912 | 294 | messages in the logs. | ||
2913 | 295 | """ | ||
2914 | 296 | if host.service_running(service_name): | ||
2915 | 297 | host.service_stop(service_name) | ||
2916 | 298 | |||
2917 | 299 | |||
2918 | 300 | def service_restart(service_name): | ||
2919 | 301 | """ | ||
2920 | 302 | Wrapper around host.service_restart to prevent spurious "unknown service" | ||
2921 | 303 | messages in the logs. | ||
2922 | 304 | """ | ||
2923 | 305 | if host.service_available(service_name): | ||
2924 | 306 | if host.service_running(service_name): | ||
2925 | 307 | host.service_restart(service_name) | ||
2926 | 308 | else: | ||
2927 | 309 | host.service_start(service_name) | ||
2928 | 310 | |||
2929 | 311 | |||
2930 | 312 | # Convenience aliases | ||
2931 | 313 | open_ports = close_ports = manage_ports = PortManagerCallback() | ||
2932 | 0 | 314 | ||
2933 | === added file 'hooks/charmhelpers/core/services/helpers.py' | |||
2934 | --- hooks/charmhelpers/core/services/helpers.py 1970-01-01 00:00:00 +0000 | |||
2935 | +++ hooks/charmhelpers/core/services/helpers.py 2014-10-06 15:38:41 +0000 | |||
2936 | @@ -0,0 +1,239 @@ | |||
2937 | 1 | import os | ||
2938 | 2 | import yaml | ||
2939 | 3 | from charmhelpers.core import hookenv | ||
2940 | 4 | from charmhelpers.core import templating | ||
2941 | 5 | |||
2942 | 6 | from charmhelpers.core.services.base import ManagerCallback | ||
2943 | 7 | |||
2944 | 8 | |||
2945 | 9 | __all__ = ['RelationContext', 'TemplateCallback', | ||
2946 | 10 | 'render_template', 'template'] | ||
2947 | 11 | |||
2948 | 12 | |||
2949 | 13 | class RelationContext(dict): | ||
2950 | 14 | """ | ||
2951 | 15 | Base class for a context generator that gets relation data from juju. | ||
2952 | 16 | |||
2953 | 17 | Subclasses must provide the attributes `name`, which is the name of the | ||
2954 | 18 | interface of interest, `interface`, which is the type of the interface of | ||
2955 | 19 | interest, and `required_keys`, which is the set of keys required for the | ||
2956 | 20 | relation to be considered complete. The data for all interfaces matching | ||
2957 | 21 | the `name` attribute that are complete will used to populate the dictionary | ||
2958 | 22 | values (see `get_data`, below). | ||
2959 | 23 | |||
2960 | 24 | The generated context will be namespaced under the relation :attr:`name`, | ||
2961 | 25 | to prevent potential naming conflicts. | ||
2962 | 26 | |||
2963 | 27 | :param str name: Override the relation :attr:`name`, since it can vary from charm to charm | ||
2964 | 28 | :param list additional_required_keys: Extend the list of :attr:`required_keys` | ||
2965 | 29 | """ | ||
2966 | 30 | name = None | ||
2967 | 31 | interface = None | ||
2968 | 32 | required_keys = [] | ||
2969 | 33 | |||
2970 | 34 | def __init__(self, name=None, additional_required_keys=None): | ||
2971 | 35 | if name is not None: | ||
2972 | 36 | self.name = name | ||
2973 | 37 | if additional_required_keys is not None: | ||
2974 | 38 | self.required_keys.extend(additional_required_keys) | ||
2975 | 39 | self.get_data() | ||
2976 | 40 | |||
2977 | 41 | def __bool__(self): | ||
2978 | 42 | """ | ||
2979 | 43 | Returns True if all of the required_keys are available. | ||
2980 | 44 | """ | ||
2981 | 45 | return self.is_ready() | ||
2982 | 46 | |||
2983 | 47 | __nonzero__ = __bool__ | ||
2984 | 48 | |||
2985 | 49 | def __repr__(self): | ||
2986 | 50 | return super(RelationContext, self).__repr__() | ||
2987 | 51 | |||
2988 | 52 | def is_ready(self): | ||
2989 | 53 | """ | ||
2990 | 54 | Returns True if all of the `required_keys` are available from any units. | ||
2991 | 55 | """ | ||
2992 | 56 | ready = len(self.get(self.name, [])) > 0 | ||
2993 | 57 | if not ready: | ||
2994 | 58 | hookenv.log('Incomplete relation: {}'.format(self.__class__.__name__), hookenv.DEBUG) | ||
2995 | 59 | return ready | ||
2996 | 60 | |||
2997 | 61 | def _is_ready(self, unit_data): | ||
2998 | 62 | """ | ||
2999 | 63 | Helper method that tests a set of relation data and returns True if | ||
3000 | 64 | all of the `required_keys` are present. | ||
3001 | 65 | """ | ||
3002 | 66 | return set(unit_data.keys()).issuperset(set(self.required_keys)) | ||
3003 | 67 | |||
3004 | 68 | def get_data(self): | ||
3005 | 69 | """ | ||
3006 | 70 | Retrieve the relation data for each unit involved in a relation and, | ||
3007 | 71 | if complete, store it in a list under `self[self.name]`. This | ||
3008 | 72 | is automatically called when the RelationContext is instantiated. | ||
3009 | 73 | |||
3010 | 74 | The units are sorted lexographically first by the service ID, then by | ||
3011 | 75 | the unit ID. Thus, if an interface has two other services, 'db:1' | ||
3012 | 76 | and 'db:2', with 'db:1' having two units, 'wordpress/0' and 'wordpress/1', | ||
3013 | 77 | and 'db:2' having one unit, 'mediawiki/0', all of which have a complete | ||
3014 | 78 | set of data, the relation data for the units will be stored in the | ||
3015 | 79 | order: 'wordpress/0', 'wordpress/1', 'mediawiki/0'. | ||
3016 | 80 | |||
3017 | 81 | If you only care about a single unit on the relation, you can just | ||
3018 | 82 | access it as `{{ interface[0]['key'] }}`. However, if you can at all | ||
3019 | 83 | support multiple units on a relation, you should iterate over the list, | ||
3020 | 84 | like:: | ||
3021 | 85 | |||
3022 | 86 | {% for unit in interface -%} | ||
3023 | 87 | {{ unit['key'] }}{% if not loop.last %},{% endif %} | ||
3024 | 88 | {%- endfor %} | ||
3025 | 89 | |||
3026 | 90 | Note that since all sets of relation data from all related services and | ||
3027 | 91 | units are in a single list, if you need to know which service or unit a | ||
3028 | 92 | set of data came from, you'll need to extend this class to preserve | ||
3029 | 93 | that information. | ||
3030 | 94 | """ | ||
3031 | 95 | if not hookenv.relation_ids(self.name): | ||
3032 | 96 | return | ||
3033 | 97 | |||
3034 | 98 | ns = self.setdefault(self.name, []) | ||
3035 | 99 | for rid in sorted(hookenv.relation_ids(self.name)): | ||
3036 | 100 | for unit in sorted(hookenv.related_units(rid)): | ||
3037 | 101 | reldata = hookenv.relation_get(rid=rid, unit=unit) | ||
3038 | 102 | if self._is_ready(reldata): | ||
3039 | 103 | ns.append(reldata) | ||
3040 | 104 | |||
3041 | 105 | def provide_data(self): | ||
3042 | 106 | """ | ||
3043 | 107 | Return data to be relation_set for this interface. | ||
3044 | 108 | """ | ||
3045 | 109 | return {} | ||
3046 | 110 | |||
3047 | 111 | |||
3048 | 112 | class MysqlRelation(RelationContext): | ||
3049 | 113 | """ | ||
3050 | 114 | Relation context for the `mysql` interface. | ||
3051 | 115 | |||
3052 | 116 | :param str name: Override the relation :attr:`name`, since it can vary from charm to charm | ||
3053 | 117 | :param list additional_required_keys: Extend the list of :attr:`required_keys` | ||
3054 | 118 | """ | ||
3055 | 119 | name = 'db' | ||
3056 | 120 | interface = 'mysql' | ||
3057 | 121 | required_keys = ['host', 'user', 'password', 'database'] | ||
3058 | 122 | |||
3059 | 123 | |||
3060 | 124 | class HttpRelation(RelationContext): | ||
3061 | 125 | """ | ||
3062 | 126 | Relation context for the `http` interface. | ||
3063 | 127 | |||
3064 | 128 | :param str name: Override the relation :attr:`name`, since it can vary from charm to charm | ||
3065 | 129 | :param list additional_required_keys: Extend the list of :attr:`required_keys` | ||
3066 | 130 | """ | ||
3067 | 131 | name = 'website' | ||
3068 | 132 | interface = 'http' | ||
3069 | 133 | required_keys = ['host', 'port'] | ||
3070 | 134 | |||
3071 | 135 | def provide_data(self): | ||
3072 | 136 | return { | ||
3073 | 137 | 'host': hookenv.unit_get('private-address'), | ||
3074 | 138 | 'port': 80, | ||
3075 | 139 | } | ||
3076 | 140 | |||
3077 | 141 | |||
3078 | 142 | class RequiredConfig(dict): | ||
3079 | 143 | """ | ||
3080 | 144 | Data context that loads config options with one or more mandatory options. | ||
3081 | 145 | |||
3082 | 146 | Once the required options have been changed from their default values, all | ||
3083 | 147 | config options will be available, namespaced under `config` to prevent | ||
3084 | 148 | potential naming conflicts (for example, between a config option and a | ||
3085 | 149 | relation property). | ||
3086 | 150 | |||
3087 | 151 | :param list *args: List of options that must be changed from their default values. | ||
3088 | 152 | """ | ||
3089 | 153 | |||
3090 | 154 | def __init__(self, *args): | ||
3091 | 155 | self.required_options = args | ||
3092 | 156 | self['config'] = hookenv.config() | ||
3093 | 157 | with open(os.path.join(hookenv.charm_dir(), 'config.yaml')) as fp: | ||
3094 | 158 | self.config = yaml.load(fp).get('options', {}) | ||
3095 | 159 | |||
3096 | 160 | def __bool__(self): | ||
3097 | 161 | for option in self.required_options: | ||
3098 | 162 | if option not in self['config']: | ||
3099 | 163 | return False | ||
3100 | 164 | current_value = self['config'][option] | ||
3101 | 165 | default_value = self.config[option].get('default') | ||
3102 | 166 | if current_value == default_value: | ||
3103 | 167 | return False | ||
3104 | 168 | if current_value in (None, '') and default_value in (None, ''): | ||
3105 | 169 | return False | ||
3106 | 170 | return True | ||
3107 | 171 | |||
3108 | 172 | def __nonzero__(self): | ||
3109 | 173 | return self.__bool__() | ||
3110 | 174 | |||
3111 | 175 | |||
3112 | 176 | class StoredContext(dict): | ||
3113 | 177 | """ | ||
3114 | 178 | A data context that always returns the data that it was first created with. | ||
3115 | 179 | |||
3116 | 180 | This is useful to do a one-time generation of things like passwords, that | ||
3117 | 181 | will thereafter use the same value that was originally generated, instead | ||
3118 | 182 | of generating a new value each time it is run. | ||
3119 | 183 | """ | ||
3120 | 184 | def __init__(self, file_name, config_data): | ||
3121 | 185 | """ | ||
3122 | 186 | If the file exists, populate `self` with the data from the file. | ||
3123 | 187 | Otherwise, populate with the given data and persist it to the file. | ||
3124 | 188 | """ | ||
3125 | 189 | if os.path.exists(file_name): | ||
3126 | 190 | self.update(self.read_context(file_name)) | ||
3127 | 191 | else: | ||
3128 | 192 | self.store_context(file_name, config_data) | ||
3129 | 193 | self.update(config_data) | ||
3130 | 194 | |||
3131 | 195 | def store_context(self, file_name, config_data): | ||
3132 | 196 | if not os.path.isabs(file_name): | ||
3133 | 197 | file_name = os.path.join(hookenv.charm_dir(), file_name) | ||
3134 | 198 | with open(file_name, 'w') as file_stream: | ||
3135 | 199 | os.fchmod(file_stream.fileno(), 0600) | ||
3136 | 200 | yaml.dump(config_data, file_stream) | ||
3137 | 201 | |||
3138 | 202 | def read_context(self, file_name): | ||
3139 | 203 | if not os.path.isabs(file_name): | ||
3140 | 204 | file_name = os.path.join(hookenv.charm_dir(), file_name) | ||
3141 | 205 | with open(file_name, 'r') as file_stream: | ||
3142 | 206 | data = yaml.load(file_stream) | ||
3143 | 207 | if not data: | ||
3144 | 208 | raise OSError("%s is empty" % file_name) | ||
3145 | 209 | return data | ||
3146 | 210 | |||
3147 | 211 | |||
3148 | 212 | class TemplateCallback(ManagerCallback): | ||
3149 | 213 | """ | ||
3150 | 214 | Callback class that will render a Jinja2 template, for use as a ready action. | ||
3151 | 215 | |||
3152 | 216 | :param str source: The template source file, relative to `$CHARM_DIR/templates` | ||
3153 | 217 | :param str target: The target to write the rendered template to | ||
3154 | 218 | :param str owner: The owner of the rendered file | ||
3155 | 219 | :param str group: The group of the rendered file | ||
3156 | 220 | :param int perms: The permissions of the rendered file | ||
3157 | 221 | """ | ||
3158 | 222 | def __init__(self, source, target, owner='root', group='root', perms=0444): | ||
3159 | 223 | self.source = source | ||
3160 | 224 | self.target = target | ||
3161 | 225 | self.owner = owner | ||
3162 | 226 | self.group = group | ||
3163 | 227 | self.perms = perms | ||
3164 | 228 | |||
3165 | 229 | def __call__(self, manager, service_name, event_name): | ||
3166 | 230 | service = manager.get_service(service_name) | ||
3167 | 231 | context = {} | ||
3168 | 232 | for ctx in service.get('required_data', []): | ||
3169 | 233 | context.update(ctx) | ||
3170 | 234 | templating.render(self.source, self.target, context, | ||
3171 | 235 | self.owner, self.group, self.perms) | ||
3172 | 236 | |||
3173 | 237 | |||
3174 | 238 | # Convenience aliases for templates | ||
3175 | 239 | render_template = template = TemplateCallback | ||
3176 | 0 | 240 | ||
3177 | === added file 'hooks/charmhelpers/core/templating.py' | |||
3178 | --- hooks/charmhelpers/core/templating.py 1970-01-01 00:00:00 +0000 | |||
3179 | +++ hooks/charmhelpers/core/templating.py 2014-10-06 15:38:41 +0000 | |||
3180 | @@ -0,0 +1,51 @@ | |||
3181 | 1 | import os | ||
3182 | 2 | |||
3183 | 3 | from charmhelpers.core import host | ||
3184 | 4 | from charmhelpers.core import hookenv | ||
3185 | 5 | |||
3186 | 6 | |||
3187 | 7 | def render(source, target, context, owner='root', group='root', perms=0444, templates_dir=None): | ||
3188 | 8 | """ | ||
3189 | 9 | Render a template. | ||
3190 | 10 | |||
3191 | 11 | The `source` path, if not absolute, is relative to the `templates_dir`. | ||
3192 | 12 | |||
3193 | 13 | The `target` path should be absolute. | ||
3194 | 14 | |||
3195 | 15 | The context should be a dict containing the values to be replaced in the | ||
3196 | 16 | template. | ||
3197 | 17 | |||
3198 | 18 | The `owner`, `group`, and `perms` options will be passed to `write_file`. | ||
3199 | 19 | |||
3200 | 20 | If omitted, `templates_dir` defaults to the `templates` folder in the charm. | ||
3201 | 21 | |||
3202 | 22 | Note: Using this requires python-jinja2; if it is not installed, calling | ||
3203 | 23 | this will attempt to use charmhelpers.fetch.apt_install to install it. | ||
3204 | 24 | """ | ||
3205 | 25 | try: | ||
3206 | 26 | from jinja2 import FileSystemLoader, Environment, exceptions | ||
3207 | 27 | except ImportError: | ||
3208 | 28 | try: | ||
3209 | 29 | from charmhelpers.fetch import apt_install | ||
3210 | 30 | except ImportError: | ||
3211 | 31 | hookenv.log('Could not import jinja2, and could not import ' | ||
3212 | 32 | 'charmhelpers.fetch to install it', | ||
3213 | 33 | level=hookenv.ERROR) | ||
3214 | 34 | raise | ||
3215 | 35 | apt_install('python-jinja2', fatal=True) | ||
3216 | 36 | from jinja2 import FileSystemLoader, Environment, exceptions | ||
3217 | 37 | |||
3218 | 38 | if templates_dir is None: | ||
3219 | 39 | templates_dir = os.path.join(hookenv.charm_dir(), 'templates') | ||
3220 | 40 | loader = Environment(loader=FileSystemLoader(templates_dir)) | ||
3221 | 41 | try: | ||
3222 | 42 | source = source | ||
3223 | 43 | template = loader.get_template(source) | ||
3224 | 44 | except exceptions.TemplateNotFound as e: | ||
3225 | 45 | hookenv.log('Could not load template %s from %s.' % | ||
3226 | 46 | (source, templates_dir), | ||
3227 | 47 | level=hookenv.ERROR) | ||
3228 | 48 | raise e | ||
3229 | 49 | content = template.render(context) | ||
3230 | 50 | host.mkdir(os.path.dirname(target)) | ||
3231 | 51 | host.write_file(target, content, owner, group, perms) | ||
3232 | 0 | 52 | ||
3233 | === modified file 'hooks/charmhelpers/fetch/__init__.py' | |||
3234 | --- hooks/charmhelpers/fetch/__init__.py 2014-08-27 07:17:33 +0000 | |||
3235 | +++ hooks/charmhelpers/fetch/__init__.py 2014-10-06 15:38:41 +0000 | |||
3236 | @@ -1,4 +1,5 @@ | |||
3237 | 1 | import importlib | 1 | import importlib |
3238 | 2 | from tempfile import NamedTemporaryFile | ||
3239 | 2 | import time | 3 | import time |
3240 | 3 | from yaml import safe_load | 4 | from yaml import safe_load |
3241 | 4 | from charmhelpers.core.host import ( | 5 | from charmhelpers.core.host import ( |
3242 | @@ -13,7 +14,6 @@ | |||
3243 | 13 | config, | 14 | config, |
3244 | 14 | log, | 15 | log, |
3245 | 15 | ) | 16 | ) |
3246 | 16 | import apt_pkg | ||
3247 | 17 | import os | 17 | import os |
3248 | 18 | 18 | ||
3249 | 19 | 19 | ||
3250 | @@ -56,6 +56,15 @@ | |||
3251 | 56 | 'icehouse/proposed': 'precise-proposed/icehouse', | 56 | 'icehouse/proposed': 'precise-proposed/icehouse', |
3252 | 57 | 'precise-icehouse/proposed': 'precise-proposed/icehouse', | 57 | 'precise-icehouse/proposed': 'precise-proposed/icehouse', |
3253 | 58 | 'precise-proposed/icehouse': 'precise-proposed/icehouse', | 58 | 'precise-proposed/icehouse': 'precise-proposed/icehouse', |
3254 | 59 | # Juno | ||
3255 | 60 | 'juno': 'trusty-updates/juno', | ||
3256 | 61 | 'trusty-juno': 'trusty-updates/juno', | ||
3257 | 62 | 'trusty-juno/updates': 'trusty-updates/juno', | ||
3258 | 63 | 'trusty-updates/juno': 'trusty-updates/juno', | ||
3259 | 64 | 'juno/proposed': 'trusty-proposed/juno', | ||
3260 | 65 | 'juno/proposed': 'trusty-proposed/juno', | ||
3261 | 66 | 'trusty-juno/proposed': 'trusty-proposed/juno', | ||
3262 | 67 | 'trusty-proposed/juno': 'trusty-proposed/juno', | ||
3263 | 59 | } | 68 | } |
3264 | 60 | 69 | ||
3265 | 61 | # The order of this list is very important. Handlers should be listed in from | 70 | # The order of this list is very important. Handlers should be listed in from |
3266 | @@ -108,8 +117,12 @@ | |||
3267 | 108 | 117 | ||
3268 | 109 | def filter_installed_packages(packages): | 118 | def filter_installed_packages(packages): |
3269 | 110 | """Returns a list of packages that require installation""" | 119 | """Returns a list of packages that require installation""" |
3270 | 120 | <<<<<<< TREE | ||
3271 | 111 | 121 | ||
3272 | 112 | cache = apt_cache() | 122 | cache = apt_cache() |
3273 | 123 | ======= | ||
3274 | 124 | cache = apt_cache() | ||
3275 | 125 | >>>>>>> MERGE-SOURCE | ||
3276 | 113 | _pkgs = [] | 126 | _pkgs = [] |
3277 | 114 | for package in packages: | 127 | for package in packages: |
3278 | 115 | try: | 128 | try: |
3279 | @@ -122,15 +135,28 @@ | |||
3280 | 122 | return _pkgs | 135 | return _pkgs |
3281 | 123 | 136 | ||
3282 | 124 | 137 | ||
3292 | 125 | def apt_cache(in_memory=True): | 138 | <<<<<<< TREE |
3293 | 126 | """Build and return an apt cache""" | 139 | def apt_cache(in_memory=True): |
3294 | 127 | apt_pkg.init() | 140 | """Build and return an apt cache""" |
3295 | 128 | if in_memory: | 141 | apt_pkg.init() |
3296 | 129 | apt_pkg.config.set("Dir::Cache::pkgcache", "") | 142 | if in_memory: |
3297 | 130 | apt_pkg.config.set("Dir::Cache::srcpkgcache", "") | 143 | apt_pkg.config.set("Dir::Cache::pkgcache", "") |
3298 | 131 | return apt_pkg.Cache() | 144 | apt_pkg.config.set("Dir::Cache::srcpkgcache", "") |
3299 | 132 | 145 | return apt_pkg.Cache() | |
3300 | 133 | 146 | ||
3301 | 147 | |||
3302 | 148 | ======= | ||
3303 | 149 | def apt_cache(in_memory=True): | ||
3304 | 150 | """Build and return an apt cache""" | ||
3305 | 151 | import apt_pkg | ||
3306 | 152 | apt_pkg.init() | ||
3307 | 153 | if in_memory: | ||
3308 | 154 | apt_pkg.config.set("Dir::Cache::pkgcache", "") | ||
3309 | 155 | apt_pkg.config.set("Dir::Cache::srcpkgcache", "") | ||
3310 | 156 | return apt_pkg.Cache() | ||
3311 | 157 | |||
3312 | 158 | |||
3313 | 159 | >>>>>>> MERGE-SOURCE | ||
3314 | 134 | def apt_install(packages, options=None, fatal=False): | 160 | def apt_install(packages, options=None, fatal=False): |
3315 | 135 | """Install one or more packages""" | 161 | """Install one or more packages""" |
3316 | 136 | if options is None: | 162 | if options is None: |
3317 | @@ -196,6 +222,28 @@ | |||
3318 | 196 | 222 | ||
3319 | 197 | 223 | ||
3320 | 198 | def add_source(source, key=None): | 224 | def add_source(source, key=None): |
3321 | 225 | """Add a package source to this system. | ||
3322 | 226 | |||
3323 | 227 | @param source: a URL or sources.list entry, as supported by | ||
3324 | 228 | add-apt-repository(1). Examples:: | ||
3325 | 229 | |||
3326 | 230 | ppa:charmers/example | ||
3327 | 231 | deb https://stub:key@private.example.com/ubuntu trusty main | ||
3328 | 232 | |||
3329 | 233 | In addition: | ||
3330 | 234 | 'proposed:' may be used to enable the standard 'proposed' | ||
3331 | 235 | pocket for the release. | ||
3332 | 236 | 'cloud:' may be used to activate official cloud archive pockets, | ||
3333 | 237 | such as 'cloud:icehouse' | ||
3334 | 238 | |||
3335 | 239 | @param key: A key to be added to the system's APT keyring and used | ||
3336 | 240 | to verify the signatures on packages. Ideally, this should be an | ||
3337 | 241 | ASCII format GPG public key including the block headers. A GPG key | ||
3338 | 242 | id may also be used, but be aware that only insecure protocols are | ||
3339 | 243 | available to retrieve the actual public key from a public keyserver | ||
3340 | 244 | placing your Juju environment at risk. ppa and cloud archive keys | ||
3341 | 245 | are securely added automtically, so sould not be provided. | ||
3342 | 246 | """ | ||
3343 | 199 | if source is None: | 247 | if source is None: |
3344 | 200 | log('Source is not present. Skipping') | 248 | log('Source is not present. Skipping') |
3345 | 201 | return | 249 | return |
3346 | @@ -220,61 +268,96 @@ | |||
3347 | 220 | release = lsb_release()['DISTRIB_CODENAME'] | 268 | release = lsb_release()['DISTRIB_CODENAME'] |
3348 | 221 | with open('/etc/apt/sources.list.d/proposed.list', 'w') as apt: | 269 | with open('/etc/apt/sources.list.d/proposed.list', 'w') as apt: |
3349 | 222 | apt.write(PROPOSED_POCKET.format(release)) | 270 | apt.write(PROPOSED_POCKET.format(release)) |
3350 | 271 | else: | ||
3351 | 272 | raise SourceConfigError("Unknown source: {!r}".format(source)) | ||
3352 | 273 | |||
3353 | 223 | if key: | 274 | if key: |
3357 | 224 | subprocess.check_call(['apt-key', 'adv', '--keyserver', | 275 | if '-----BEGIN PGP PUBLIC KEY BLOCK-----' in key: |
3358 | 225 | 'hkp://keyserver.ubuntu.com:80', '--recv', | 276 | with NamedTemporaryFile() as key_file: |
3359 | 226 | key]) | 277 | key_file.write(key) |
3360 | 278 | key_file.flush() | ||
3361 | 279 | key_file.seek(0) | ||
3362 | 280 | subprocess.check_call(['apt-key', 'add', '-'], stdin=key_file) | ||
3363 | 281 | else: | ||
3364 | 282 | # Note that hkp: is in no way a secure protocol. Using a | ||
3365 | 283 | # GPG key id is pointless from a security POV unless you | ||
3366 | 284 | # absolutely trust your network and DNS. | ||
3367 | 285 | subprocess.check_call(['apt-key', 'adv', '--keyserver', | ||
3368 | 286 | 'hkp://keyserver.ubuntu.com:80', '--recv', | ||
3369 | 287 | key]) | ||
3370 | 227 | 288 | ||
3371 | 228 | 289 | ||
3372 | 229 | def configure_sources(update=False, | 290 | def configure_sources(update=False, |
3373 | 230 | sources_var='install_sources', | 291 | sources_var='install_sources', |
3374 | 231 | keys_var='install_keys'): | 292 | keys_var='install_keys'): |
3375 | 232 | """ | 293 | """ |
3377 | 233 | Configure multiple sources from charm configuration | 294 | Configure multiple sources from charm configuration. |
3378 | 295 | |||
3379 | 296 | The lists are encoded as yaml fragments in the configuration. | ||
3380 | 297 | The frament needs to be included as a string. Sources and their | ||
3381 | 298 | corresponding keys are of the types supported by add_source(). | ||
3382 | 234 | 299 | ||
3383 | 235 | Example config: | 300 | Example config: |
3385 | 236 | install_sources: | 301 | install_sources: | |
3386 | 237 | - "ppa:foo" | 302 | - "ppa:foo" |
3387 | 238 | - "http://example.com/repo precise main" | 303 | - "http://example.com/repo precise main" |
3389 | 239 | install_keys: | 304 | install_keys: | |
3390 | 240 | - null | 305 | - null |
3391 | 241 | - "a1b2c3d4" | 306 | - "a1b2c3d4" |
3392 | 242 | 307 | ||
3393 | 243 | Note that 'null' (a.k.a. None) should not be quoted. | 308 | Note that 'null' (a.k.a. None) should not be quoted. |
3394 | 244 | """ | 309 | """ |
3402 | 245 | sources = safe_load(config(sources_var)) | 310 | sources = safe_load((config(sources_var) or '').strip()) or [] |
3403 | 246 | keys = config(keys_var) | 311 | keys = safe_load((config(keys_var) or '').strip()) or None |
3404 | 247 | if keys is not None: | 312 | |
3405 | 248 | keys = safe_load(keys) | 313 | if isinstance(sources, basestring): |
3406 | 249 | if isinstance(sources, basestring) and ( | 314 | sources = [sources] |
3407 | 250 | keys is None or isinstance(keys, basestring)): | 315 | |
3408 | 251 | add_source(sources, keys) | 316 | if keys is None: |
3409 | 317 | for source in sources: | ||
3410 | 318 | add_source(source, None) | ||
3411 | 252 | else: | 319 | else: |
3417 | 253 | if not len(sources) == len(keys): | 320 | if isinstance(keys, basestring): |
3418 | 254 | msg = 'Install sources and keys lists are different lengths' | 321 | keys = [keys] |
3419 | 255 | raise SourceConfigError(msg) | 322 | |
3420 | 256 | for src_num in range(len(sources)): | 323 | if len(sources) != len(keys): |
3421 | 257 | add_source(sources[src_num], keys[src_num]) | 324 | raise SourceConfigError( |
3422 | 325 | 'Install sources and keys lists are different lengths') | ||
3423 | 326 | for source, key in zip(sources, keys): | ||
3424 | 327 | add_source(source, key) | ||
3425 | 258 | if update: | 328 | if update: |
3426 | 259 | apt_update(fatal=True) | 329 | apt_update(fatal=True) |
3427 | 260 | 330 | ||
3428 | 261 | 331 | ||
3430 | 262 | def install_remote(source): | 332 | def install_remote(source, *args, **kwargs): |
3431 | 263 | """ | 333 | """ |
3432 | 264 | Install a file tree from a remote source | 334 | Install a file tree from a remote source |
3433 | 265 | 335 | ||
3434 | 266 | The specified source should be a url of the form: | 336 | The specified source should be a url of the form: |
3435 | 267 | scheme://[host]/path[#[option=value][&...]] | 337 | scheme://[host]/path[#[option=value][&...]] |
3436 | 268 | 338 | ||
3439 | 269 | Schemes supported are based on this modules submodules | 339 | Schemes supported are based on this modules submodules. |
3440 | 270 | Options supported are submodule-specific""" | 340 | Options supported are submodule-specific. |
3441 | 341 | Additional arguments are passed through to the submodule. | ||
3442 | 342 | |||
3443 | 343 | For example:: | ||
3444 | 344 | |||
3445 | 345 | dest = install_remote('http://example.com/archive.tgz', | ||
3446 | 346 | checksum='deadbeef', | ||
3447 | 347 | hash_type='sha1') | ||
3448 | 348 | |||
3449 | 349 | This will download `archive.tgz`, validate it using SHA1 and, if | ||
3450 | 350 | the file is ok, extract it and return the directory in which it | ||
3451 | 351 | was extracted. If the checksum fails, it will raise | ||
3452 | 352 | :class:`charmhelpers.core.host.ChecksumError`. | ||
3453 | 353 | """ | ||
3454 | 271 | # We ONLY check for True here because can_handle may return a string | 354 | # We ONLY check for True here because can_handle may return a string |
3455 | 272 | # explaining why it can't handle a given source. | 355 | # explaining why it can't handle a given source. |
3456 | 273 | handlers = [h for h in plugins() if h.can_handle(source) is True] | 356 | handlers = [h for h in plugins() if h.can_handle(source) is True] |
3457 | 274 | installed_to = None | 357 | installed_to = None |
3458 | 275 | for handler in handlers: | 358 | for handler in handlers: |
3459 | 276 | try: | 359 | try: |
3461 | 277 | installed_to = handler.install(source) | 360 | installed_to = handler.install(source, *args, **kwargs) |
3462 | 278 | except UnhandledSource: | 361 | except UnhandledSource: |
3463 | 279 | pass | 362 | pass |
3464 | 280 | if not installed_to: | 363 | if not installed_to: |
3465 | 281 | 364 | ||
3466 | === modified file 'hooks/charmhelpers/fetch/archiveurl.py' | |||
3467 | --- hooks/charmhelpers/fetch/archiveurl.py 2014-03-20 13:47:46 +0000 | |||
3468 | +++ hooks/charmhelpers/fetch/archiveurl.py 2014-10-06 15:38:41 +0000 | |||
3469 | @@ -1,6 +1,8 @@ | |||
3470 | 1 | import os | 1 | import os |
3471 | 2 | import urllib2 | 2 | import urllib2 |
3472 | 3 | from urllib import urlretrieve | ||
3473 | 3 | import urlparse | 4 | import urlparse |
3474 | 5 | import hashlib | ||
3475 | 4 | 6 | ||
3476 | 5 | from charmhelpers.fetch import ( | 7 | from charmhelpers.fetch import ( |
3477 | 6 | BaseFetchHandler, | 8 | BaseFetchHandler, |
3478 | @@ -10,11 +12,19 @@ | |||
3479 | 10 | get_archive_handler, | 12 | get_archive_handler, |
3480 | 11 | extract, | 13 | extract, |
3481 | 12 | ) | 14 | ) |
3483 | 13 | from charmhelpers.core.host import mkdir | 15 | from charmhelpers.core.host import mkdir, check_hash |
3484 | 14 | 16 | ||
3485 | 15 | 17 | ||
3486 | 16 | class ArchiveUrlFetchHandler(BaseFetchHandler): | 18 | class ArchiveUrlFetchHandler(BaseFetchHandler): |
3488 | 17 | """Handler for archives via generic URLs""" | 19 | """ |
3489 | 20 | Handler to download archive files from arbitrary URLs. | ||
3490 | 21 | |||
3491 | 22 | Can fetch from http, https, ftp, and file URLs. | ||
3492 | 23 | |||
3493 | 24 | Can install either tarballs (.tar, .tgz, .tbz2, etc) or zip files. | ||
3494 | 25 | |||
3495 | 26 | Installs the contents of the archive in $CHARM_DIR/fetched/. | ||
3496 | 27 | """ | ||
3497 | 18 | def can_handle(self, source): | 28 | def can_handle(self, source): |
3498 | 19 | url_parts = self.parse_url(source) | 29 | url_parts = self.parse_url(source) |
3499 | 20 | if url_parts.scheme not in ('http', 'https', 'ftp', 'file'): | 30 | if url_parts.scheme not in ('http', 'https', 'ftp', 'file'): |
3500 | @@ -24,6 +34,12 @@ | |||
3501 | 24 | return False | 34 | return False |
3502 | 25 | 35 | ||
3503 | 26 | def download(self, source, dest): | 36 | def download(self, source, dest): |
3504 | 37 | """ | ||
3505 | 38 | Download an archive file. | ||
3506 | 39 | |||
3507 | 40 | :param str source: URL pointing to an archive file. | ||
3508 | 41 | :param str dest: Local path location to download archive file to. | ||
3509 | 42 | """ | ||
3510 | 27 | # propogate all exceptions | 43 | # propogate all exceptions |
3511 | 28 | # URLError, OSError, etc | 44 | # URLError, OSError, etc |
3512 | 29 | proto, netloc, path, params, query, fragment = urlparse.urlparse(source) | 45 | proto, netloc, path, params, query, fragment = urlparse.urlparse(source) |
3513 | @@ -48,7 +64,30 @@ | |||
3514 | 48 | os.unlink(dest) | 64 | os.unlink(dest) |
3515 | 49 | raise e | 65 | raise e |
3516 | 50 | 66 | ||
3518 | 51 | def install(self, source): | 67 | # Mandatory file validation via Sha1 or MD5 hashing. |
3519 | 68 | def download_and_validate(self, url, hashsum, validate="sha1"): | ||
3520 | 69 | tempfile, headers = urlretrieve(url) | ||
3521 | 70 | check_hash(tempfile, hashsum, validate) | ||
3522 | 71 | return tempfile | ||
3523 | 72 | |||
3524 | 73 | def install(self, source, dest=None, checksum=None, hash_type='sha1'): | ||
3525 | 74 | """ | ||
3526 | 75 | Download and install an archive file, with optional checksum validation. | ||
3527 | 76 | |||
3528 | 77 | The checksum can also be given on the `source` URL's fragment. | ||
3529 | 78 | For example:: | ||
3530 | 79 | |||
3531 | 80 | handler.install('http://example.com/file.tgz#sha1=deadbeef') | ||
3532 | 81 | |||
3533 | 82 | :param str source: URL pointing to an archive file. | ||
3534 | 83 | :param str dest: Local destination path to install to. If not given, | ||
3535 | 84 | installs to `$CHARM_DIR/archives/archive_file_name`. | ||
3536 | 85 | :param str checksum: If given, validate the archive file after download. | ||
3537 | 86 | :param str hash_type: Algorithm used to generate `checksum`. | ||
3538 | 87 | Can be any hash alrgorithm supported by :mod:`hashlib`, | ||
3539 | 88 | such as md5, sha1, sha256, sha512, etc. | ||
3540 | 89 | |||
3541 | 90 | """ | ||
3542 | 52 | url_parts = self.parse_url(source) | 91 | url_parts = self.parse_url(source) |
3543 | 53 | dest_dir = os.path.join(os.environ.get('CHARM_DIR'), 'fetched') | 92 | dest_dir = os.path.join(os.environ.get('CHARM_DIR'), 'fetched') |
3544 | 54 | if not os.path.exists(dest_dir): | 93 | if not os.path.exists(dest_dir): |
3545 | @@ -60,4 +99,10 @@ | |||
3546 | 60 | raise UnhandledSource(e.reason) | 99 | raise UnhandledSource(e.reason) |
3547 | 61 | except OSError as e: | 100 | except OSError as e: |
3548 | 62 | raise UnhandledSource(e.strerror) | 101 | raise UnhandledSource(e.strerror) |
3550 | 63 | return extract(dld_file) | 102 | options = urlparse.parse_qs(url_parts.fragment) |
3551 | 103 | for key, value in options.items(): | ||
3552 | 104 | if key in hashlib.algorithms: | ||
3553 | 105 | check_hash(dld_file, value, key) | ||
3554 | 106 | if checksum: | ||
3555 | 107 | check_hash(dld_file, checksum, hash_type) | ||
3556 | 108 | return extract(dld_file, dest) | ||
3557 | 64 | 109 | ||
3558 | === modified file 'hooks/swift_context.py' | |||
3559 | --- hooks/swift_context.py 2014-04-10 16:52:10 +0000 | |||
3560 | +++ hooks/swift_context.py 2014-10-06 15:38:41 +0000 | |||
3561 | @@ -4,7 +4,8 @@ | |||
3562 | 4 | relation_ids, | 4 | relation_ids, |
3563 | 5 | related_units, | 5 | related_units, |
3564 | 6 | relation_get, | 6 | relation_get, |
3566 | 7 | unit_get | 7 | unit_get, |
3567 | 8 | service_name | ||
3568 | 8 | ) | 9 | ) |
3569 | 9 | 10 | ||
3570 | 10 | from charmhelpers.contrib.openstack.context import ( | 11 | from charmhelpers.contrib.openstack.context import ( |
3571 | @@ -19,9 +20,14 @@ | |||
3572 | 19 | determine_apache_port, | 20 | determine_apache_port, |
3573 | 20 | ) | 21 | ) |
3574 | 21 | 22 | ||
3575 | 23 | from charmhelpers.contrib.network.ip import ( | ||
3576 | 24 | get_ipv6_addr | ||
3577 | 25 | ) | ||
3578 | 26 | |||
3579 | 22 | from charmhelpers.contrib.openstack.utils import get_host_ip | 27 | from charmhelpers.contrib.openstack.utils import get_host_ip |
3580 | 23 | import subprocess | 28 | import subprocess |
3581 | 24 | import os | 29 | import os |
3582 | 30 | import uuid | ||
3583 | 25 | 31 | ||
3584 | 26 | 32 | ||
3585 | 27 | from charmhelpers.contrib.hahelpers.apache import ( | 33 | from charmhelpers.contrib.hahelpers.apache import ( |
3586 | @@ -116,7 +122,11 @@ | |||
3587 | 116 | for relid in relation_ids('swift-storage'): | 122 | for relid in relation_ids('swift-storage'): |
3588 | 117 | for unit in related_units(relid): | 123 | for unit in related_units(relid): |
3589 | 118 | host = relation_get('private-address', unit, relid) | 124 | host = relation_get('private-address', unit, relid) |
3591 | 119 | allowed_hosts.append(get_host_ip(host)) | 125 | if config('prefer-ipv6'): |
3592 | 126 | host_ip = get_ipv6_addr(exc_list=[config('vip')])[0] | ||
3593 | 127 | else: | ||
3594 | 128 | host_ip = get_host_ip(host) | ||
3595 | 129 | allowed_hosts.append(host_ip) | ||
3596 | 120 | 130 | ||
3597 | 121 | ctxt = { | 131 | ctxt = { |
3598 | 122 | 'www_dir': WWW_DIR, | 132 | 'www_dir': WWW_DIR, |
3599 | @@ -134,12 +144,21 @@ | |||
3600 | 134 | if workers == '0': | 144 | if workers == '0': |
3601 | 135 | import multiprocessing | 145 | import multiprocessing |
3602 | 136 | workers = multiprocessing.cpu_count() | 146 | workers = multiprocessing.cpu_count() |
3603 | 147 | if config('prefer-ipv6'): | ||
3604 | 148 | proxy_ip = '[%s]' % get_ipv6_addr(exc_list=[config('vip')])[0] | ||
3605 | 149 | memcached_ip = 'ip6-localhost' | ||
3606 | 150 | else: | ||
3607 | 151 | proxy_ip = get_host_ip(unit_get('private-address')) | ||
3608 | 152 | memcached_ip = get_host_ip(unit_get('private-address')) | ||
3609 | 137 | ctxt = { | 153 | ctxt = { |
3611 | 138 | 'proxy_ip': get_host_ip(unit_get('private-address')), | 154 | 'proxy_ip': proxy_ip, |
3612 | 155 | 'memcached_ip': memcached_ip, | ||
3613 | 139 | 'bind_port': determine_api_port(bind_port), | 156 | 'bind_port': determine_api_port(bind_port), |
3614 | 140 | 'workers': workers, | 157 | 'workers': workers, |
3615 | 141 | 'operator_roles': config('operator-roles'), | 158 | 'operator_roles': config('operator-roles'), |
3617 | 142 | 'delay_auth_decision': config('delay-auth-decision') | 159 | 'delay_auth_decision': config('delay-auth-decision'), |
3618 | 160 | 'node_timeout': config('node-timeout'), | ||
3619 | 161 | 'recoverable_node_timeout': config('recoverable-node-timeout'), | ||
3620 | 143 | } | 162 | } |
3621 | 144 | 163 | ||
3622 | 145 | ctxt['ssl'] = False | 164 | ctxt['ssl'] = False |
3623 | @@ -194,9 +213,11 @@ | |||
3624 | 194 | class MemcachedContext(OSContextGenerator): | 213 | class MemcachedContext(OSContextGenerator): |
3625 | 195 | 214 | ||
3626 | 196 | def __call__(self): | 215 | def __call__(self): |
3630 | 197 | ctxt = { | 216 | ctxt = {} |
3631 | 198 | 'proxy_ip': get_host_ip(unit_get('private-address')) | 217 | if config('prefer-ipv6'): |
3632 | 199 | } | 218 | ctxt['memcached_ip'] = 'ip6-localhost' |
3633 | 219 | else: | ||
3634 | 220 | ctxt['memcached_ip'] = get_host_ip(unit_get('private-address')) | ||
3635 | 200 | return ctxt | 221 | return ctxt |
3636 | 201 | 222 | ||
3637 | 202 | SWIFT_HASH_FILE = '/var/lib/juju/swift-hash-path.conf' | 223 | SWIFT_HASH_FILE = '/var/lib/juju/swift-hash-path.conf' |
3638 | @@ -211,10 +232,8 @@ | |||
3639 | 211 | with open(SWIFT_HASH_FILE, 'w') as hashfile: | 232 | with open(SWIFT_HASH_FILE, 'w') as hashfile: |
3640 | 212 | hashfile.write(swift_hash) | 233 | hashfile.write(swift_hash) |
3641 | 213 | else: | 234 | else: |
3646 | 214 | cmd = ['od', '-t', 'x8', '-N', '8', '-A', 'n'] | 235 | swift_hash = str(uuid.uuid3(uuid.UUID(os.environ.get("JUJU_ENV_UUID")), |
3647 | 215 | rand = open('/dev/random', 'r') | 236 | service_name())) |
3644 | 216 | p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stdin=rand) | ||
3645 | 217 | swift_hash = p.communicate()[0].strip() | ||
3648 | 218 | with open(SWIFT_HASH_FILE, 'w') as hashfile: | 237 | with open(SWIFT_HASH_FILE, 'w') as hashfile: |
3649 | 219 | hashfile.write(swift_hash) | 238 | hashfile.write(swift_hash) |
3650 | 220 | return swift_hash | 239 | return swift_hash |
3651 | 221 | 240 | ||
3652 | === modified file 'hooks/swift_hooks.py' | |||
3653 | --- hooks/swift_hooks.py 2014-04-10 16:52:10 +0000 | |||
3654 | +++ hooks/swift_hooks.py 2014-10-06 15:38:41 +0000 | |||
3655 | @@ -24,7 +24,8 @@ | |||
3656 | 24 | add_to_ring, | 24 | add_to_ring, |
3657 | 25 | should_balance, | 25 | should_balance, |
3658 | 26 | do_openstack_upgrade, | 26 | do_openstack_upgrade, |
3660 | 27 | write_rc_script | 27 | write_rc_script, |
3661 | 28 | setup_ipv6 | ||
3662 | 28 | ) | 29 | ) |
3663 | 29 | from swift_context import get_swift_hash | 30 | from swift_context import get_swift_hash |
3664 | 30 | 31 | ||
3665 | @@ -48,6 +49,19 @@ | |||
3666 | 48 | ) | 49 | ) |
3667 | 49 | from charmhelpers.payload.execd import execd_preinstall | 50 | from charmhelpers.payload.execd import execd_preinstall |
3668 | 50 | 51 | ||
3669 | 52 | from charmhelpers.contrib.openstack.ip import ( | ||
3670 | 53 | canonical_url, | ||
3671 | 54 | PUBLIC, INTERNAL, ADMIN | ||
3672 | 55 | ) | ||
3673 | 56 | from charmhelpers.contrib.network.ip import ( | ||
3674 | 57 | get_iface_for_address, | ||
3675 | 58 | get_netmask_for_address, | ||
3676 | 59 | get_address_in_network, | ||
3677 | 60 | get_ipv6_addr, | ||
3678 | 61 | format_ipv6_addr, | ||
3679 | 62 | is_ipv6 | ||
3680 | 63 | ) | ||
3681 | 64 | |||
3682 | 51 | extra_pkgs = [ | 65 | extra_pkgs = [ |
3683 | 52 | "haproxy", | 66 | "haproxy", |
3684 | 53 | "python-jinja2" | 67 | "python-jinja2" |
3685 | @@ -71,7 +85,6 @@ | |||
3686 | 71 | pkgs = determine_packages(rel) | 85 | pkgs = determine_packages(rel) |
3687 | 72 | apt_install(pkgs, fatal=True) | 86 | apt_install(pkgs, fatal=True) |
3688 | 73 | apt_install(extra_pkgs, fatal=True) | 87 | apt_install(extra_pkgs, fatal=True) |
3689 | 74 | |||
3690 | 75 | ensure_swift_dir() | 88 | ensure_swift_dir() |
3691 | 76 | # initialize new storage rings. | 89 | # initialize new storage rings. |
3692 | 77 | for ring in SWIFT_RINGS.iteritems(): | 90 | for ring in SWIFT_RINGS.iteritems(): |
3693 | @@ -92,20 +105,16 @@ | |||
3694 | 92 | def keystone_joined(relid=None): | 105 | def keystone_joined(relid=None): |
3695 | 93 | if not cluster.eligible_leader(SWIFT_HA_RES): | 106 | if not cluster.eligible_leader(SWIFT_HA_RES): |
3696 | 94 | return | 107 | return |
3697 | 95 | if cluster.is_clustered(): | ||
3698 | 96 | hostname = config('vip') | ||
3699 | 97 | else: | ||
3700 | 98 | hostname = unit_get('private-address') | ||
3701 | 99 | port = config('bind-port') | 108 | port = config('bind-port') |
3708 | 100 | if cluster.https(): | 109 | admin_url = '%s:%s' % (canonical_url(CONFIGS, ADMIN), port) |
3709 | 101 | proto = 'https' | 110 | internal_url = '%s:%s/v1/AUTH_$(tenant_id)s' % \ |
3710 | 102 | else: | 111 | (canonical_url(CONFIGS, INTERNAL), port) |
3711 | 103 | proto = 'http' | 112 | public_url = '%s:%s/v1/AUTH_$(tenant_id)s' % \ |
3712 | 104 | admin_url = '%s://%s:%s' % (proto, hostname, port) | 113 | (canonical_url(CONFIGS, PUBLIC), port) |
3707 | 105 | internal_url = public_url = '%s/v1/AUTH_$(tenant_id)s' % admin_url | ||
3713 | 106 | relation_set(service='swift', | 114 | relation_set(service='swift', |
3714 | 107 | region=config('region'), | 115 | region=config('region'), |
3716 | 108 | public_url=public_url, internal_url=internal_url, | 116 | public_url=public_url, |
3717 | 117 | internal_url=internal_url, | ||
3718 | 109 | admin_url=admin_url, | 118 | admin_url=admin_url, |
3719 | 110 | requested_roles=config('operator-roles'), | 119 | requested_roles=config('operator-roles'), |
3720 | 111 | relation_id=relid) | 120 | relation_id=relid) |
3721 | @@ -142,9 +151,12 @@ | |||
3722 | 142 | 151 | ||
3723 | 143 | if cluster.is_clustered(): | 152 | if cluster.is_clustered(): |
3724 | 144 | hostname = config('vip') | 153 | hostname = config('vip') |
3725 | 154 | elif config('prefer-ipv6'): | ||
3726 | 155 | hostname = get_ipv6_addr(exc_list=[config('vip')])[0] | ||
3727 | 145 | else: | 156 | else: |
3728 | 146 | hostname = unit_get('private-address') | 157 | hostname = unit_get('private-address') |
3729 | 147 | 158 | ||
3730 | 159 | hostname = format_ipv6_addr(hostname) or hostname | ||
3731 | 148 | rings_url = 'http://%s/%s' % (hostname, path) | 160 | rings_url = 'http://%s/%s' % (hostname, path) |
3732 | 149 | # notify storage nodes that there is a new ring to fetch. | 161 | # notify storage nodes that there is a new ring to fetch. |
3733 | 150 | for relid in relation_ids('swift-storage'): | 162 | for relid in relation_ids('swift-storage'): |
3734 | @@ -157,9 +169,14 @@ | |||
3735 | 157 | @hooks.hook('swift-storage-relation-changed') | 169 | @hooks.hook('swift-storage-relation-changed') |
3736 | 158 | @restart_on_change(restart_map()) | 170 | @restart_on_change(restart_map()) |
3737 | 159 | def storage_changed(): | 171 | def storage_changed(): |
3738 | 172 | if config('prefer-ipv6'): | ||
3739 | 173 | host_ip = '[%s]' % relation_get('private-address') | ||
3740 | 174 | else: | ||
3741 | 175 | host_ip = openstack.get_host_ip(relation_get('private-address')) | ||
3742 | 176 | |||
3743 | 160 | zone = get_zone(config('zone-assignment')) | 177 | zone = get_zone(config('zone-assignment')) |
3744 | 161 | node_settings = { | 178 | node_settings = { |
3746 | 162 | 'ip': openstack.get_host_ip(relation_get('private-address')), | 179 | 'ip': host_ip, |
3747 | 163 | 'zone': zone, | 180 | 'zone': zone, |
3748 | 164 | 'account_port': relation_get('account_port'), | 181 | 'account_port': relation_get('account_port'), |
3749 | 165 | 'object_port': relation_get('object_port'), | 182 | 'object_port': relation_get('object_port'), |
3750 | @@ -195,16 +212,33 @@ | |||
3751 | 195 | @hooks.hook('config-changed') | 212 | @hooks.hook('config-changed') |
3752 | 196 | @restart_on_change(restart_map()) | 213 | @restart_on_change(restart_map()) |
3753 | 197 | def config_changed(): | 214 | def config_changed(): |
3754 | 215 | if config('prefer-ipv6'): | ||
3755 | 216 | setup_ipv6() | ||
3756 | 217 | |||
3757 | 198 | configure_https() | 218 | configure_https() |
3758 | 199 | open_port(config('bind-port')) | 219 | open_port(config('bind-port')) |
3759 | 200 | # Determine whether or not we should do an upgrade, based on the | 220 | # Determine whether or not we should do an upgrade, based on the |
3760 | 201 | # the version offered in keyston-release. | 221 | # the version offered in keyston-release. |
3761 | 202 | if (openstack.openstack_upgrade_available('python-swift')): | 222 | if (openstack.openstack_upgrade_available('python-swift')): |
3762 | 203 | do_openstack_upgrade(CONFIGS) | 223 | do_openstack_upgrade(CONFIGS) |
3767 | 204 | 224 | for r_id in relation_ids('identity-service'): | |
3768 | 205 | 225 | keystone_joined(relid=r_id) | |
3769 | 206 | @hooks.hook('cluster-relation-changed', | 226 | |
3770 | 207 | 'cluster-relation-joined') | 227 | |
3771 | 228 | @hooks.hook('cluster-relation-joined') | ||
3772 | 229 | def cluster_joined(relation_id=None): | ||
3773 | 230 | if config('prefer-ipv6'): | ||
3774 | 231 | private_addr = get_ipv6_addr(exc_list=[config('vip')])[0] | ||
3775 | 232 | else: | ||
3776 | 233 | private_addr = unit_get('private-address') | ||
3777 | 234 | |||
3778 | 235 | address = get_address_in_network(config('os-internal-network'), | ||
3779 | 236 | private_addr) | ||
3780 | 237 | relation_set(relation_id=relation_id, | ||
3781 | 238 | relation_settings={'private-address': address}) | ||
3782 | 239 | |||
3783 | 240 | |||
3784 | 241 | @hooks.hook('cluster-relation-changed') | ||
3785 | 208 | @restart_on_change(restart_map()) | 242 | @restart_on_change(restart_map()) |
3786 | 209 | def cluster_changed(): | 243 | def cluster_changed(): |
3787 | 210 | CONFIGS.write_all() | 244 | CONFIGS.write_all() |
3788 | @@ -229,8 +263,6 @@ | |||
3789 | 229 | corosync_bindiface = config('ha-bindiface') | 263 | corosync_bindiface = config('ha-bindiface') |
3790 | 230 | corosync_mcastport = config('ha-mcastport') | 264 | corosync_mcastport = config('ha-mcastport') |
3791 | 231 | vip = config('vip') | 265 | vip = config('vip') |
3792 | 232 | vip_cidr = config('vip_cidr') | ||
3793 | 233 | vip_iface = config('vip_iface') | ||
3794 | 234 | if not vip: | 266 | if not vip: |
3795 | 235 | log('Unable to configure hacluster as vip not provided', | 267 | log('Unable to configure hacluster as vip not provided', |
3796 | 236 | level=ERROR) | 268 | level=ERROR) |
3797 | @@ -238,14 +270,37 @@ | |||
3798 | 238 | 270 | ||
3799 | 239 | # Obtain resources | 271 | # Obtain resources |
3800 | 240 | resources = { | 272 | resources = { |
3801 | 241 | 'res_swift_vip': 'ocf:heartbeat:IPaddr2', | ||
3802 | 242 | 'res_swift_haproxy': 'lsb:haproxy' | 273 | 'res_swift_haproxy': 'lsb:haproxy' |
3803 | 243 | } | 274 | } |
3804 | 244 | resource_params = { | 275 | resource_params = { |
3805 | 245 | 'res_swift_vip': 'params ip="%s" cidr_netmask="%s" nic="%s"' % | ||
3806 | 246 | (vip, vip_cidr, vip_iface), | ||
3807 | 247 | 'res_swift_haproxy': 'op monitor interval="5s"' | 276 | 'res_swift_haproxy': 'op monitor interval="5s"' |
3808 | 248 | } | 277 | } |
3809 | 278 | |||
3810 | 279 | vip_group = [] | ||
3811 | 280 | for vip in vip.split(): | ||
3812 | 281 | if is_ipv6(vip): | ||
3813 | 282 | res_swift_vip = 'ocf:heartbeat:IPv6addr' | ||
3814 | 283 | vip_params = 'ipv6addr' | ||
3815 | 284 | else: | ||
3816 | 285 | res_swift_vip = 'ocf:heartbeat:IPaddr2' | ||
3817 | 286 | vip_params = 'ip' | ||
3818 | 287 | |||
3819 | 288 | iface = get_iface_for_address(vip) | ||
3820 | 289 | if iface is not None: | ||
3821 | 290 | vip_key = 'res_swift_{}_vip'.format(iface) | ||
3822 | 291 | resources[vip_key] = res_swift_vip | ||
3823 | 292 | resource_params[vip_key] = ( | ||
3824 | 293 | 'params {ip}="{vip}" cidr_netmask="{netmask}"' | ||
3825 | 294 | ' nic="{iface}"'.format(ip=vip_params, | ||
3826 | 295 | vip=vip, | ||
3827 | 296 | iface=iface, | ||
3828 | 297 | netmask=get_netmask_for_address(vip)) | ||
3829 | 298 | ) | ||
3830 | 299 | vip_group.append(vip_key) | ||
3831 | 300 | |||
3832 | 301 | if len(vip_group) >= 1: | ||
3833 | 302 | relation_set(groups={'grp_swift_vips': ' '.join(vip_group)}) | ||
3834 | 303 | |||
3835 | 249 | init_services = { | 304 | init_services = { |
3836 | 250 | 'res_swift_haproxy': 'haproxy' | 305 | 'res_swift_haproxy': 'haproxy' |
3837 | 251 | } | 306 | } |
3838 | 252 | 307 | ||
3839 | === modified file 'hooks/swift_utils.py' | |||
3840 | --- hooks/swift_utils.py 2014-08-11 08:59:49 +0000 | |||
3841 | +++ hooks/swift_utils.py 2014-10-06 15:38:41 +0000 | |||
3842 | @@ -12,7 +12,13 @@ | |||
3843 | 12 | ) | 12 | ) |
3844 | 13 | from charmhelpers.fetch import ( | 13 | from charmhelpers.fetch import ( |
3845 | 14 | apt_update, | 14 | apt_update, |
3847 | 15 | apt_upgrade | 15 | apt_upgrade, |
3848 | 16 | apt_install, | ||
3849 | 17 | add_source | ||
3850 | 18 | ) | ||
3851 | 19 | |||
3852 | 20 | from charmhelpers.core.host import ( | ||
3853 | 21 | lsb_release | ||
3854 | 16 | ) | 22 | ) |
3855 | 17 | 23 | ||
3856 | 18 | import charmhelpers.contrib.openstack.context as context | 24 | import charmhelpers.contrib.openstack.context as context |
3857 | @@ -63,7 +69,7 @@ | |||
3858 | 63 | # > Folsom specific packages | 69 | # > Folsom specific packages |
3859 | 64 | FOLSOM_PACKAGES = BASE_PACKAGES + ['swift-plugin-s3'] | 70 | FOLSOM_PACKAGES = BASE_PACKAGES + ['swift-plugin-s3'] |
3860 | 65 | 71 | ||
3862 | 66 | SWIFT_HA_RES = 'res_swift_vip' | 72 | SWIFT_HA_RES = 'grp_swift_vips' |
3863 | 67 | 73 | ||
3864 | 68 | TEMPLATES = 'templates/' | 74 | TEMPLATES = 'templates/' |
3865 | 69 | 75 | ||
3866 | @@ -75,7 +81,8 @@ | |||
3867 | 75 | 'services': ['swift-proxy'], | 81 | 'services': ['swift-proxy'], |
3868 | 76 | }), | 82 | }), |
3869 | 77 | (SWIFT_PROXY_CONF, { | 83 | (SWIFT_PROXY_CONF, { |
3871 | 78 | 'hook_contexts': [swift_context.SwiftIdentityContext()], | 84 | 'hook_contexts': [swift_context.SwiftIdentityContext(), |
3872 | 85 | context.BindHostContext()], | ||
3873 | 79 | 'services': ['swift-proxy'], | 86 | 'services': ['swift-proxy'], |
3874 | 80 | }), | 87 | }), |
3875 | 81 | (HAPROXY_CONF, { | 88 | (HAPROXY_CONF, { |
3876 | @@ -368,3 +375,19 @@ | |||
3877 | 368 | apt_upgrade(options=dpkg_opts, fatal=True, dist=True) | 375 | apt_upgrade(options=dpkg_opts, fatal=True, dist=True) |
3878 | 369 | configs.set_release(openstack_release=new_os_rel) | 376 | configs.set_release(openstack_release=new_os_rel) |
3879 | 370 | configs.write_all() | 377 | configs.write_all() |
3880 | 378 | |||
3881 | 379 | |||
3882 | 380 | def setup_ipv6(): | ||
3883 | 381 | ubuntu_rel = lsb_release()['DISTRIB_CODENAME'].lower() | ||
3884 | 382 | if ubuntu_rel < "trusty": | ||
3885 | 383 | raise Exception("IPv6 is not supported in the charms for Ubuntu " | ||
3886 | 384 | "versions less than Trusty 14.04") | ||
3887 | 385 | |||
3888 | 386 | # NOTE(xianghui): Need to install haproxy(1.5.3) from trusty-backports | ||
3889 | 387 | # to support ipv6 address, so check is required to make sure not | ||
3890 | 388 | # breaking other versions, IPv6 only support for >= Trusty | ||
3891 | 389 | if ubuntu_rel == 'trusty': | ||
3892 | 390 | add_source('deb http://archive.ubuntu.com/ubuntu trusty-backports' | ||
3893 | 391 | ' main') | ||
3894 | 392 | apt_update() | ||
3895 | 393 | apt_install('haproxy/trusty-backports', fatal=True) | ||
3896 | 371 | 394 | ||
3897 | === modified file 'revision' | |||
3898 | --- revision 2013-09-27 12:02:37 +0000 | |||
3899 | +++ revision 2014-10-06 15:38:41 +0000 | |||
3900 | @@ -1,1 +1,1 @@ | |||
3902 | 1 | 146 | 1 | 147 |
3903 | 2 | 2 | ||
3904 | === modified file 'templates/essex/proxy-server.conf' | |||
3905 | --- templates/essex/proxy-server.conf 2014-02-27 12:17:53 +0000 | |||
3906 | +++ templates/essex/proxy-server.conf 2014-10-06 15:38:41 +0000 | |||
3907 | @@ -19,6 +19,8 @@ | |||
3908 | 19 | use = egg:swift#proxy | 19 | use = egg:swift#proxy |
3909 | 20 | allow_account_management = true | 20 | allow_account_management = true |
3910 | 21 | {% if auth_type == 'keystone' %}account_autocreate = true{% endif %} | 21 | {% if auth_type == 'keystone' %}account_autocreate = true{% endif %} |
3911 | 22 | node_timeout = {{ node_timeout }} | ||
3912 | 23 | recoverable_node_timeout = {{ recoverable_node_timeout }} | ||
3913 | 22 | 24 | ||
3914 | 23 | [filter:tempauth] | 25 | [filter:tempauth] |
3915 | 24 | use = egg:swift#tempauth | 26 | use = egg:swift#tempauth |
3916 | 25 | 27 | ||
3917 | === modified file 'templates/grizzly/proxy-server.conf' | |||
3918 | --- templates/grizzly/proxy-server.conf 2014-03-27 11:23:24 +0000 | |||
3919 | +++ templates/grizzly/proxy-server.conf 2014-10-06 15:38:41 +0000 | |||
3920 | @@ -19,6 +19,8 @@ | |||
3921 | 19 | use = egg:swift#proxy | 19 | use = egg:swift#proxy |
3922 | 20 | allow_account_management = true | 20 | allow_account_management = true |
3923 | 21 | {% if auth_type == 'keystone' %}account_autocreate = true{% endif %} | 21 | {% if auth_type == 'keystone' %}account_autocreate = true{% endif %} |
3924 | 22 | node_timeout = {{ node_timeout }} | ||
3925 | 23 | recoverable_node_timeout = {{ recoverable_node_timeout }} | ||
3926 | 22 | 24 | ||
3927 | 23 | [filter:tempauth] | 25 | [filter:tempauth] |
3928 | 24 | use = egg:swift#tempauth | 26 | use = egg:swift#tempauth |
3929 | 25 | 27 | ||
3930 | === modified file 'templates/havana/proxy-server.conf' | |||
3931 | --- templates/havana/proxy-server.conf 2014-03-27 11:23:24 +0000 | |||
3932 | +++ templates/havana/proxy-server.conf 2014-10-06 15:38:41 +0000 | |||
3933 | @@ -19,6 +19,8 @@ | |||
3934 | 19 | use = egg:swift#proxy | 19 | use = egg:swift#proxy |
3935 | 20 | allow_account_management = true | 20 | allow_account_management = true |
3936 | 21 | {% if auth_type == 'keystone' %}account_autocreate = true{% endif %} | 21 | {% if auth_type == 'keystone' %}account_autocreate = true{% endif %} |
3937 | 22 | node_timeout = {{ node_timeout }} | ||
3938 | 23 | recoverable_node_timeout = {{ recoverable_node_timeout }} | ||
3939 | 22 | 24 | ||
3940 | 23 | [filter:tempauth] | 25 | [filter:tempauth] |
3941 | 24 | use = egg:swift#tempauth | 26 | use = egg:swift#tempauth |
3942 | 25 | 27 | ||
3943 | === modified file 'templates/icehouse/proxy-server.conf' | |||
3944 | --- templates/icehouse/proxy-server.conf 2014-04-07 14:44:39 +0000 | |||
3945 | +++ templates/icehouse/proxy-server.conf 2014-10-06 15:38:41 +0000 | |||
3946 | @@ -2,6 +2,7 @@ | |||
3947 | 2 | bind_port = {{ bind_port }} | 2 | bind_port = {{ bind_port }} |
3948 | 3 | workers = {{ workers }} | 3 | workers = {{ workers }} |
3949 | 4 | user = swift | 4 | user = swift |
3950 | 5 | bind_ip = {{ bind_host }} | ||
3951 | 5 | {% if ssl %} | 6 | {% if ssl %} |
3952 | 6 | cert_file = {{ ssl_cert }} | 7 | cert_file = {{ ssl_cert }} |
3953 | 7 | key_file = {{ ssl_key }} | 8 | key_file = {{ ssl_key }} |
3954 | @@ -19,6 +20,8 @@ | |||
3955 | 19 | use = egg:swift#proxy | 20 | use = egg:swift#proxy |
3956 | 20 | allow_account_management = true | 21 | allow_account_management = true |
3957 | 21 | {% if auth_type == 'keystone' %}account_autocreate = true{% endif %} | 22 | {% if auth_type == 'keystone' %}account_autocreate = true{% endif %} |
3958 | 23 | node_timeout = {{ node_timeout }} | ||
3959 | 24 | recoverable_node_timeout = {{ recoverable_node_timeout }} | ||
3960 | 22 | 25 | ||
3961 | 23 | [filter:tempauth] | 26 | [filter:tempauth] |
3962 | 24 | use = egg:swift#tempauth | 27 | use = egg:swift#tempauth |
3963 | @@ -29,7 +32,7 @@ | |||
3964 | 29 | 32 | ||
3965 | 30 | [filter:cache] | 33 | [filter:cache] |
3966 | 31 | use = egg:swift#memcache | 34 | use = egg:swift#memcache |
3968 | 32 | memcache_servers = {{ proxy_ip }}:11211 | 35 | memcache_servers = {{ memcached_ip }}:11211 |
3969 | 33 | 36 | ||
3970 | 34 | [filter:account-quotas] | 37 | [filter:account-quotas] |
3971 | 35 | use = egg:swift#account_quotas | 38 | use = egg:swift#account_quotas |
3972 | 36 | 39 | ||
3973 | === modified file 'templates/memcached.conf' | |||
3974 | --- templates/memcached.conf 2013-09-27 12:02:37 +0000 | |||
3975 | +++ templates/memcached.conf 2014-10-06 15:38:41 +0000 | |||
3976 | @@ -32,7 +32,7 @@ | |||
3977 | 32 | # Specify which IP address to listen on. The default is to listen on all IP addresses | 32 | # Specify which IP address to listen on. The default is to listen on all IP addresses |
3978 | 33 | # This parameter is one of the only security measures that memcached has, so make sure | 33 | # This parameter is one of the only security measures that memcached has, so make sure |
3979 | 34 | # it's listening on a firewalled interface. | 34 | # it's listening on a firewalled interface. |
3981 | 35 | -l {{ proxy_ip }} | 35 | -l {{ memcached_ip }} |
3982 | 36 | 36 | ||
3983 | 37 | # Limit the number of simultaneous incoming connections. The daemon default is 1024 | 37 | # Limit the number of simultaneous incoming connections. The daemon default is 1024 |
3984 | 38 | # -c 1024 | 38 | # -c 1024 |
3985 | 39 | 39 | ||
3986 | === added directory 'tests' | |||
3987 | === added file 'tests/00-setup' | |||
3988 | --- tests/00-setup 1970-01-01 00:00:00 +0000 | |||
3989 | +++ tests/00-setup 2014-10-06 15:38:41 +0000 | |||
3990 | @@ -0,0 +1,11 @@ | |||
3991 | 1 | #!/bin/bash | ||
3992 | 2 | |||
3993 | 3 | set -ex | ||
3994 | 4 | |||
3995 | 5 | sudo add-apt-repository --yes ppa:juju/stable | ||
3996 | 6 | sudo apt-get update --yes | ||
3997 | 7 | sudo apt-get install --yes python-amulet | ||
3998 | 8 | sudo apt-get install --yes python-swiftclient | ||
3999 | 9 | sudo apt-get install --yes python-glanceclient | ||
4000 | 10 | sudo apt-get install --yes python-keystoneclient | ||
4001 | 11 | sudo apt-get install --yes python-novaclient | ||
4002 | 0 | 12 | ||
4003 | === added file 'tests/10-basic-precise-essex' | |||
4004 | --- tests/10-basic-precise-essex 1970-01-01 00:00:00 +0000 | |||
4005 | +++ tests/10-basic-precise-essex 2014-10-06 15:38:41 +0000 | |||
4006 | @@ -0,0 +1,9 @@ | |||
4007 | 1 | #!/usr/bin/python | ||
4008 | 2 | |||
4009 | 3 | """Amulet tests on a basic swift-proxy deployment on precise-essex.""" | ||
4010 | 4 | |||
4011 | 5 | from basic_deployment import SwiftProxyBasicDeployment | ||
4012 | 6 | |||
4013 | 7 | if __name__ == '__main__': | ||
4014 | 8 | deployment = SwiftProxyBasicDeployment(series='precise') | ||
4015 | 9 | deployment.run_tests() | ||
4016 | 0 | 10 | ||
4017 | === added file 'tests/11-basic-precise-folsom' | |||
4018 | --- tests/11-basic-precise-folsom 1970-01-01 00:00:00 +0000 | |||
4019 | +++ tests/11-basic-precise-folsom 2014-10-06 15:38:41 +0000 | |||
4020 | @@ -0,0 +1,11 @@ | |||
4021 | 1 | #!/usr/bin/python | ||
4022 | 2 | |||
4023 | 3 | """Amulet tests on a basic swift-proxy deployment on precise-folsom.""" | ||
4024 | 4 | |||
4025 | 5 | from basic_deployment import SwiftProxyBasicDeployment | ||
4026 | 6 | |||
4027 | 7 | if __name__ == '__main__': | ||
4028 | 8 | deployment = SwiftProxyBasicDeployment(series='precise', | ||
4029 | 9 | openstack='cloud:precise-folsom', | ||
4030 | 10 | source='cloud:precise-updates/folsom') | ||
4031 | 11 | deployment.run_tests() | ||
4032 | 0 | 12 | ||
4033 | === added file 'tests/12-basic-precise-grizzly' | |||
4034 | --- tests/12-basic-precise-grizzly 1970-01-01 00:00:00 +0000 | |||
4035 | +++ tests/12-basic-precise-grizzly 2014-10-06 15:38:41 +0000 | |||
4036 | @@ -0,0 +1,11 @@ | |||
4037 | 1 | #!/usr/bin/python | ||
4038 | 2 | |||
4039 | 3 | """Amulet tests on a basic swift-proxy deployment on precise-grizzly.""" | ||
4040 | 4 | |||
4041 | 5 | from basic_deployment import SwiftProxyBasicDeployment | ||
4042 | 6 | |||
4043 | 7 | if __name__ == '__main__': | ||
4044 | 8 | deployment = SwiftProxyBasicDeployment(series='precise', | ||
4045 | 9 | openstack='cloud:precise-grizzly', | ||
4046 | 10 | source='cloud:precise-updates/grizzly') | ||
4047 | 11 | deployment.run_tests() | ||
4048 | 0 | 12 | ||
4049 | === added file 'tests/13-basic-precise-havana' | |||
4050 | --- tests/13-basic-precise-havana 1970-01-01 00:00:00 +0000 | |||
4051 | +++ tests/13-basic-precise-havana 2014-10-06 15:38:41 +0000 | |||
4052 | @@ -0,0 +1,11 @@ | |||
4053 | 1 | #!/usr/bin/python | ||
4054 | 2 | |||
4055 | 3 | """Amulet tests on a basic swift-proxy deployment on precise-havana.""" | ||
4056 | 4 | |||
4057 | 5 | from basic_deployment import SwiftProxyBasicDeployment | ||
4058 | 6 | |||
4059 | 7 | if __name__ == '__main__': | ||
4060 | 8 | deployment = SwiftProxyBasicDeployment(series='precise', | ||
4061 | 9 | openstack='cloud:precise-havana', | ||
4062 | 10 | source='cloud:precise-updates/havana') | ||
4063 | 11 | deployment.run_tests() | ||
4064 | 0 | 12 | ||
4065 | === added file 'tests/14-basic-precise-icehouse' | |||
4066 | --- tests/14-basic-precise-icehouse 1970-01-01 00:00:00 +0000 | |||
4067 | +++ tests/14-basic-precise-icehouse 2014-10-06 15:38:41 +0000 | |||
4068 | @@ -0,0 +1,11 @@ | |||
4069 | 1 | #!/usr/bin/python | ||
4070 | 2 | |||
4071 | 3 | """Amulet tests on a basic swift-proxy deployment on precise-icehouse.""" | ||
4072 | 4 | |||
4073 | 5 | from basic_deployment import SwiftProxyBasicDeployment | ||
4074 | 6 | |||
4075 | 7 | if __name__ == '__main__': | ||
4076 | 8 | deployment = SwiftProxyBasicDeployment(series='precise', | ||
4077 | 9 | openstack='cloud:precise-icehouse', | ||
4078 | 10 | source='cloud:precise-updates/icehouse') | ||
4079 | 11 | deployment.run_tests() | ||
4080 | 0 | 12 | ||
4081 | === added file 'tests/15-basic-trusty-icehouse' | |||
4082 | --- tests/15-basic-trusty-icehouse 1970-01-01 00:00:00 +0000 | |||
4083 | +++ tests/15-basic-trusty-icehouse 2014-10-06 15:38:41 +0000 | |||
4084 | @@ -0,0 +1,9 @@ | |||
4085 | 1 | #!/usr/bin/python | ||
4086 | 2 | |||
4087 | 3 | """Amulet tests on a basic swift-proxy deployment on trusty-icehouse.""" | ||
4088 | 4 | |||
4089 | 5 | from basic_deployment import SwiftProxyBasicDeployment | ||
4090 | 6 | |||
4091 | 7 | if __name__ == '__main__': | ||
4092 | 8 | deployment = SwiftProxyBasicDeployment(series='trusty') | ||
4093 | 9 | deployment.run_tests() | ||
4094 | 0 | 10 | ||
4095 | === added file 'tests/README' | |||
4096 | --- tests/README 1970-01-01 00:00:00 +0000 | |||
4097 | +++ tests/README 2014-10-06 15:38:41 +0000 | |||
4098 | @@ -0,0 +1,52 @@ | |||
4099 | 1 | This directory provides Amulet tests that focus on verification of swift-proxy | ||
4100 | 2 | deployments. | ||
4101 | 3 | |||
4102 | 4 | If you use a web proxy server to access the web, you'll need to set the | ||
4103 | 5 | AMULET_HTTP_PROXY environment variable to the http URL of the proxy server. | ||
4104 | 6 | |||
4105 | 7 | The following examples demonstrate different ways that tests can be executed. | ||
4106 | 8 | All examples are run from the charm's root directory. | ||
4107 | 9 | |||
4108 | 10 | * To run all tests (starting with 00-setup): | ||
4109 | 11 | |||
4110 | 12 | make test | ||
4111 | 13 | |||
4112 | 14 | * To run a specific test module (or modules): | ||
4113 | 15 | |||
4114 | 16 | juju test -v -p AMULET_HTTP_PROXY 15-basic-trusty-icehouse | ||
4115 | 17 | |||
4116 | 18 | * To run a specific test module (or modules), and keep the environment | ||
4117 | 19 | deployed after a failure: | ||
4118 | 20 | |||
4119 | 21 | juju test --set-e -v -p AMULET_HTTP_PROXY 15-basic-trusty-icehouse | ||
4120 | 22 | |||
4121 | 23 | * To re-run a test module against an already deployed environment (one | ||
4122 | 24 | that was deployed by a previous call to 'juju test --set-e'): | ||
4123 | 25 | |||
4124 | 26 | ./tests/15-basic-trusty-icehouse | ||
4125 | 27 | |||
4126 | 28 | For debugging and test development purposes, all code should be idempotent. | ||
4127 | 29 | In other words, the code should have the ability to be re-run without changing | ||
4128 | 30 | the results beyond the initial run. This enables editing and re-running of a | ||
4129 | 31 | test module against an already deployed environment, as described above. | ||
4130 | 32 | |||
4131 | 33 | Manual debugging tips: | ||
4132 | 34 | |||
4133 | 35 | * Set the following env vars before using the OpenStack CLI as admin: | ||
4134 | 36 | export OS_AUTH_URL=http://`juju-deployer -f keystone 2>&1 | tail -n 1`:5000/v2.0 | ||
4135 | 37 | export OS_TENANT_NAME=admin | ||
4136 | 38 | export OS_USERNAME=admin | ||
4137 | 39 | export OS_PASSWORD=openstack | ||
4138 | 40 | export OS_REGION_NAME=RegionOne | ||
4139 | 41 | |||
4140 | 42 | * Set the following env vars before using the OpenStack CLI as demoUser: | ||
4141 | 43 | export OS_AUTH_URL=http://`juju-deployer -f keystone 2>&1 | tail -n 1`:5000/v2.0 | ||
4142 | 44 | export OS_TENANT_NAME=demoTenant | ||
4143 | 45 | export OS_USERNAME=demoUser | ||
4144 | 46 | export OS_PASSWORD=password | ||
4145 | 47 | export OS_REGION_NAME=RegionOne | ||
4146 | 48 | |||
4147 | 49 | * Sample swift command: | ||
4148 | 50 | swift -A $OS_AUTH_URL --os-tenant-name services --os-username swift \ | ||
4149 | 51 | --os-password password list | ||
4150 | 52 | (where tenant/user names and password are in swift-proxy's nova.conf file) | ||
4151 | 0 | 53 | ||
4152 | === added file 'tests/basic_deployment.py' | |||
4153 | --- tests/basic_deployment.py 1970-01-01 00:00:00 +0000 | |||
4154 | +++ tests/basic_deployment.py 2014-10-06 15:38:41 +0000 | |||
4155 | @@ -0,0 +1,827 @@ | |||
4156 | 1 | #!/usr/bin/python | ||
4157 | 2 | |||
4158 | 3 | import amulet | ||
4159 | 4 | import swiftclient | ||
4160 | 5 | |||
4161 | 6 | from charmhelpers.contrib.openstack.amulet.deployment import ( | ||
4162 | 7 | OpenStackAmuletDeployment | ||
4163 | 8 | ) | ||
4164 | 9 | |||
4165 | 10 | from charmhelpers.contrib.openstack.amulet.utils import ( | ||
4166 | 11 | OpenStackAmuletUtils, | ||
4167 | 12 | DEBUG, # flake8: noqa | ||
4168 | 13 | ERROR | ||
4169 | 14 | ) | ||
4170 | 15 | |||
4171 | 16 | # Use DEBUG to turn on debug logging | ||
4172 | 17 | u = OpenStackAmuletUtils(ERROR) | ||
4173 | 18 | |||
4174 | 19 | |||
4175 | 20 | class SwiftProxyBasicDeployment(OpenStackAmuletDeployment): | ||
4176 | 21 | """Amulet tests on a basic swift-proxy deployment.""" | ||
4177 | 22 | |||
4178 | 23 | def __init__(self, series, openstack=None, source=None): | ||
4179 | 24 | """Deploy the entire test environment.""" | ||
4180 | 25 | super(SwiftProxyBasicDeployment, self).__init__(series, openstack, | ||
4181 | 26 | source) | ||
4182 | 27 | self._add_services() | ||
4183 | 28 | self._add_relations() | ||
4184 | 29 | self._configure_services() | ||
4185 | 30 | self._deploy() | ||
4186 | 31 | self._initialize_tests() | ||
4187 | 32 | |||
4188 | 33 | def _add_services(self): | ||
4189 | 34 | """Add the service that we're testing, including the number of units, | ||
4190 | 35 | where swift-proxy is local, and the other charms are from | ||
4191 | 36 | the charm store.""" | ||
4192 | 37 | this_service = ('swift-proxy', 1) | ||
4193 | 38 | other_services = [('mysql', 1), | ||
4194 | 39 | ('keystone', 1), ('glance', 1), ('swift-storage', 1)] | ||
4195 | 40 | super(SwiftProxyBasicDeployment, self)._add_services(this_service, | ||
4196 | 41 | other_services) | ||
4197 | 42 | |||
4198 | 43 | def _add_relations(self): | ||
4199 | 44 | """Add all of the relations for the services.""" | ||
4200 | 45 | relations = { | ||
4201 | 46 | 'keystone:shared-db': 'mysql:shared-db', | ||
4202 | 47 | 'swift-proxy:identity-service': 'keystone:identity-service', | ||
4203 | 48 | 'swift-storage:swift-storage': 'swift-proxy:swift-storage', | ||
4204 | 49 | 'glance:identity-service': 'keystone:identity-service', | ||
4205 | 50 | 'glance:shared-db': 'mysql:shared-db', | ||
4206 | 51 | 'glance:object-store': 'swift-proxy:object-store' | ||
4207 | 52 | } | ||
4208 | 53 | super(SwiftProxyBasicDeployment, self)._add_relations(relations) | ||
4209 | 54 | |||
4210 | 55 | def _configure_services(self): | ||
4211 | 56 | """Configure all of the services.""" | ||
4212 | 57 | keystone_config = {'admin-password': 'openstack', | ||
4213 | 58 | 'admin-token': 'ubuntutesting'} | ||
4214 | 59 | swift_proxy_config = {'zone-assignment': 'manual', | ||
4215 | 60 | 'replicas': '1', | ||
4216 | 61 | 'swift-hash': 'fdfef9d4-8b06-11e2-8ac0-531c923c8fae', | ||
4217 | 62 | 'use-https': 'no'} | ||
4218 | 63 | swift_storage_config = {'zone': '1', | ||
4219 | 64 | 'block-device': 'vdb', | ||
4220 | 65 | 'overwrite': 'true'} | ||
4221 | 66 | configs = {'keystone': keystone_config, | ||
4222 | 67 | 'swift-proxy': swift_proxy_config, | ||
4223 | 68 | 'swift-storage': swift_storage_config} | ||
4224 | 69 | super(SwiftProxyBasicDeployment, self)._configure_services(configs) | ||
4225 | 70 | |||
4226 | 71 | def _initialize_tests(self): | ||
4227 | 72 | """Perform final initialization before tests get run.""" | ||
4228 | 73 | # Access the sentries for inspecting service units | ||
4229 | 74 | self.mysql_sentry = self.d.sentry.unit['mysql/0'] | ||
4230 | 75 | self.keystone_sentry = self.d.sentry.unit['keystone/0'] | ||
4231 | 76 | self.glance_sentry = self.d.sentry.unit['glance/0'] | ||
4232 | 77 | self.swift_proxy_sentry = self.d.sentry.unit['swift-proxy/0'] | ||
4233 | 78 | self.swift_storage_sentry = self.d.sentry.unit['swift-storage/0'] | ||
4234 | 79 | |||
4235 | 80 | # Authenticate admin with keystone | ||
4236 | 81 | self.keystone = u.authenticate_keystone_admin(self.keystone_sentry, | ||
4237 | 82 | user='admin', | ||
4238 | 83 | password='openstack', | ||
4239 | 84 | tenant='admin') | ||
4240 | 85 | |||
4241 | 86 | # Authenticate admin with glance endpoint | ||
4242 | 87 | self.glance = u.authenticate_glance_admin(self.keystone) | ||
4243 | 88 | |||
4244 | 89 | # Authenticate swift user | ||
4245 | 90 | keystone_relation = self.keystone_sentry.relation('identity-service', | ||
4246 | 91 | 'swift-proxy:identity-service') | ||
4247 | 92 | ep = self.keystone.service_catalog.url_for(service_type='identity', | ||
4248 | 93 | endpoint_type='publicURL') | ||
4249 | 94 | self.swift = swiftclient.Connection(authurl=ep, | ||
4250 | 95 | user=keystone_relation['service_username'], | ||
4251 | 96 | key=keystone_relation['service_password'], | ||
4252 | 97 | tenant_name=keystone_relation['service_tenant'], | ||
4253 | 98 | auth_version='2.0') | ||
4254 | 99 | |||
4255 | 100 | # Create a demo tenant/role/user | ||
4256 | 101 | self.demo_tenant = 'demoTenant' | ||
4257 | 102 | self.demo_role = 'demoRole' | ||
4258 | 103 | self.demo_user = 'demoUser' | ||
4259 | 104 | if not u.tenant_exists(self.keystone, self.demo_tenant): | ||
4260 | 105 | tenant = self.keystone.tenants.create(tenant_name=self.demo_tenant, | ||
4261 | 106 | description='demo tenant', | ||
4262 | 107 | enabled=True) | ||
4263 | 108 | self.keystone.roles.create(name=self.demo_role) | ||
4264 | 109 | self.keystone.users.create(name=self.demo_user, | ||
4265 | 110 | password='password', | ||
4266 | 111 | tenant_id=tenant.id, | ||
4267 | 112 | email='demo@demo.com') | ||
4268 | 113 | |||
4269 | 114 | # Authenticate demo user with keystone | ||
4270 | 115 | self.keystone_demo = \ | ||
4271 | 116 | u.authenticate_keystone_user(self.keystone, user=self.demo_user, | ||
4272 | 117 | password='password', | ||
4273 | 118 | tenant=self.demo_tenant) | ||
4274 | 119 | |||
4275 | 120 | def test_services(self): | ||
4276 | 121 | """Verify the expected services are running on the corresponding | ||
4277 | 122 | service units.""" | ||
4278 | 123 | swift_storage_services = ['status swift-account', | ||
4279 | 124 | 'status swift-account-auditor', | ||
4280 | 125 | 'status swift-account-reaper', | ||
4281 | 126 | 'status swift-account-replicator', | ||
4282 | 127 | 'status swift-container', | ||
4283 | 128 | 'status swift-container-auditor', | ||
4284 | 129 | 'status swift-container-replicator', | ||
4285 | 130 | 'status swift-container-updater', | ||
4286 | 131 | 'status swift-object', | ||
4287 | 132 | 'status swift-object-auditor', | ||
4288 | 133 | 'status swift-object-replicator', | ||
4289 | 134 | 'status swift-object-updater'] | ||
4290 | 135 | if self._get_openstack_release() >= self.precise_icehouse: | ||
4291 | 136 | swift_storage_services.append('status swift-container-sync') | ||
4292 | 137 | |||
4293 | 138 | commands = { | ||
4294 | 139 | self.mysql_sentry: ['status mysql'], | ||
4295 | 140 | self.keystone_sentry: ['status keystone'], | ||
4296 | 141 | self.glance_sentry: ['status glance-registry', 'status glance-api'], | ||
4297 | 142 | self.swift_proxy_sentry: ['status swift-proxy'], | ||
4298 | 143 | self.swift_storage_sentry: swift_storage_services | ||
4299 | 144 | } | ||
4300 | 145 | |||
4301 | 146 | ret = u.validate_services(commands) | ||
4302 | 147 | if ret: | ||
4303 | 148 | amulet.raise_status(amulet.FAIL, msg=ret) | ||
4304 | 149 | |||
4305 | 150 | def test_users(self): | ||
4306 | 151 | """Verify all existing roles.""" | ||
4307 | 152 | user1 = {'name': 'demoUser', | ||
4308 | 153 | 'enabled': True, | ||
4309 | 154 | 'tenantId': u.not_null, | ||
4310 | 155 | 'id': u.not_null, | ||
4311 | 156 | 'email': 'demo@demo.com'} | ||
4312 | 157 | user2 = {'name': 'admin', | ||
4313 | 158 | 'enabled': True, | ||
4314 | 159 | 'tenantId': u.not_null, | ||
4315 | 160 | 'id': u.not_null, | ||
4316 | 161 | 'email': 'juju@localhost'} | ||
4317 | 162 | user3 = {'name': 'glance', | ||
4318 | 163 | 'enabled': True, | ||
4319 | 164 | 'tenantId': u.not_null, | ||
4320 | 165 | 'id': u.not_null, | ||
4321 | 166 | 'email': u'juju@localhost'} | ||
4322 | 167 | user4 = {'name': 'swift', | ||
4323 | 168 | 'enabled': True, | ||
4324 | 169 | 'tenantId': u.not_null, | ||
4325 | 170 | 'id': u.not_null, | ||
4326 | 171 | 'email': u'juju@localhost'} | ||
4327 | 172 | expected = [user1, user2, user3, user4] | ||
4328 | 173 | actual = self.keystone.users.list() | ||
4329 | 174 | |||
4330 | 175 | ret = u.validate_user_data(expected, actual) | ||
4331 | 176 | if ret: | ||
4332 | 177 | amulet.raise_status(amulet.FAIL, msg=ret) | ||
4333 | 178 | |||
4334 | 179 | def test_service_catalog(self): | ||
4335 | 180 | """Verify that the service catalog endpoint data is valid.""" | ||
4336 | 181 | endpoint_vol = {'adminURL': u.valid_url, | ||
4337 | 182 | 'region': 'RegionOne', | ||
4338 | 183 | 'publicURL': u.valid_url, | ||
4339 | 184 | 'internalURL': u.valid_url} | ||
4340 | 185 | endpoint_id = {'adminURL': u.valid_url, | ||
4341 | 186 | 'region': 'RegionOne', | ||
4342 | 187 | 'publicURL': u.valid_url, | ||
4343 | 188 | 'internalURL': u.valid_url} | ||
4344 | 189 | if self._get_openstack_release() >= self.precise_folsom: | ||
4345 | 190 | endpoint_vol['id'] = u.not_null | ||
4346 | 191 | endpoint_id['id'] = u.not_null | ||
4347 | 192 | expected = {'image': [endpoint_id], 'object-store': [endpoint_id], | ||
4348 | 193 | 'identity': [endpoint_id]} | ||
4349 | 194 | actual = self.keystone_demo.service_catalog.get_endpoints() | ||
4350 | 195 | |||
4351 | 196 | ret = u.validate_svc_catalog_endpoint_data(expected, actual) | ||
4352 | 197 | if ret: | ||
4353 | 198 | amulet.raise_status(amulet.FAIL, msg=ret) | ||
4354 | 199 | |||
4355 | 200 | def test_openstack_object_store_endpoint(self): | ||
4356 | 201 | """Verify the swift object-store endpoint data.""" | ||
4357 | 202 | endpoints = self.keystone.endpoints.list() | ||
4358 | 203 | admin_port = internal_port = public_port = '8080' | ||
4359 | 204 | expected = {'id': u.not_null, | ||
4360 | 205 | 'region': 'RegionOne', | ||
4361 | 206 | 'adminurl': u.valid_url, | ||
4362 | 207 | 'internalurl': u.valid_url, | ||
4363 | 208 | 'publicurl': u.valid_url, | ||
4364 | 209 | 'service_id': u.not_null} | ||
4365 | 210 | |||
4366 | 211 | ret = u.validate_endpoint_data(endpoints, admin_port, internal_port, | ||
4367 | 212 | public_port, expected) | ||
4368 | 213 | if ret: | ||
4369 | 214 | message = 'object-store endpoint: {}'.format(ret) | ||
4370 | 215 | amulet.raise_status(amulet.FAIL, msg=message) | ||
4371 | 216 | |||
4372 | 217 | def test_swift_proxy_identity_service_relation(self): | ||
4373 | 218 | """Verify the swift-proxy to keystone identity-service relation data.""" | ||
4374 | 219 | unit = self.swift_proxy_sentry | ||
4375 | 220 | relation = ['identity-service', 'keystone:identity-service'] | ||
4376 | 221 | expected = { | ||
4377 | 222 | 'service': 'swift', | ||
4378 | 223 | 'region': 'RegionOne', | ||
4379 | 224 | 'public_url': u.valid_url, | ||
4380 | 225 | 'internal_url': u.valid_url, | ||
4381 | 226 | 'private-address': u.valid_ip, | ||
4382 | 227 | 'requested_roles': 'Member,Admin', | ||
4383 | 228 | 'admin_url': u.valid_url | ||
4384 | 229 | } | ||
4385 | 230 | |||
4386 | 231 | ret = u.validate_relation_data(unit, relation, expected) | ||
4387 | 232 | if ret: | ||
4388 | 233 | message = u.relation_error('swift-proxy identity-service', ret) | ||
4389 | 234 | amulet.raise_status(amulet.FAIL, msg=message) | ||
4390 | 235 | |||
4391 | 236 | def test_keystone_identity_service_relation(self): | ||
4392 | 237 | """Verify the keystone to swift-proxy identity-service relation data.""" | ||
4393 | 238 | unit = self.keystone_sentry | ||
4394 | 239 | relation = ['identity-service', 'swift-proxy:identity-service'] | ||
4395 | 240 | expected = { | ||
4396 | 241 | 'service_protocol': 'http', | ||
4397 | 242 | 'service_tenant': 'services', | ||
4398 | 243 | 'admin_token': 'ubuntutesting', | ||
4399 | 244 | 'service_password': u.not_null, | ||
4400 | 245 | 'service_port': '5000', | ||
4401 | 246 | 'auth_port': '35357', | ||
4402 | 247 | 'auth_protocol': 'http', | ||
4403 | 248 | 'private-address': u.valid_ip, | ||
4404 | 249 | 'https_keystone': 'False', | ||
4405 | 250 | 'auth_host': u.valid_ip, | ||
4406 | 251 | 'service_username': 'swift', | ||
4407 | 252 | 'service_tenant_id': u.not_null, | ||
4408 | 253 | 'service_host': u.valid_ip | ||
4409 | 254 | } | ||
4410 | 255 | |||
4411 | 256 | ret = u.validate_relation_data(unit, relation, expected) | ||
4412 | 257 | if ret: | ||
4413 | 258 | message = u.relation_error('keystone identity-service', ret) | ||
4414 | 259 | amulet.raise_status(amulet.FAIL, msg=message) | ||
4415 | 260 | |||
4416 | 261 | def test_swift_storage_swift_storage_relation(self): | ||
4417 | 262 | """Verify the swift-storage to swift-proxy swift-storage relation | ||
4418 | 263 | data.""" | ||
4419 | 264 | unit = self.swift_storage_sentry | ||
4420 | 265 | relation = ['swift-storage', 'swift-proxy:swift-storage'] | ||
4421 | 266 | expected = { | ||
4422 | 267 | 'account_port': '6002', | ||
4423 | 268 | 'zone': '1', | ||
4424 | 269 | 'object_port': '6000', | ||
4425 | 270 | 'container_port': '6001', | ||
4426 | 271 | 'private-address': u.valid_ip, | ||
4427 | 272 | 'device': 'vdb' | ||
4428 | 273 | } | ||
4429 | 274 | |||
4430 | 275 | ret = u.validate_relation_data(unit, relation, expected) | ||
4431 | 276 | if ret: | ||
4432 | 277 | message = u.relation_error('swift-storage swift-storage', ret) | ||
4433 | 278 | amulet.raise_status(amulet.FAIL, msg=message) | ||
4434 | 279 | |||
4435 | 280 | def test_swift_proxy_swift_storage_relation(self): | ||
4436 | 281 | """Verify the swift-proxy to swift-storage swift-storage relation | ||
4437 | 282 | data.""" | ||
4438 | 283 | unit = self.swift_proxy_sentry | ||
4439 | 284 | relation = ['swift-storage', 'swift-storage:swift-storage'] | ||
4440 | 285 | expected = { | ||
4441 | 286 | 'private-address': u.valid_ip, | ||
4442 | 287 | 'trigger': u.not_null, | ||
4443 | 288 | 'rings_url': u.valid_url, | ||
4444 | 289 | 'swift_hash': u.not_null | ||
4445 | 290 | } | ||
4446 | 291 | |||
4447 | 292 | ret = u.validate_relation_data(unit, relation, expected) | ||
4448 | 293 | if ret: | ||
4449 | 294 | message = u.relation_error('swift-proxy swift-storage', ret) | ||
4450 | 295 | amulet.raise_status(amulet.FAIL, msg=message) | ||
4451 | 296 | |||
4452 | 297 | def test_glance_object_store_relation(self): | ||
4453 | 298 | """Verify the glance to swift-proxy object-store relation data.""" | ||
4454 | 299 | unit = self.glance_sentry | ||
4455 | 300 | relation = ['object-store', 'swift-proxy:object-store'] | ||
4456 | 301 | expected = { 'private-address': u.valid_ip } | ||
4457 | 302 | |||
4458 | 303 | ret = u.validate_relation_data(unit, relation, expected) | ||
4459 | 304 | if ret: | ||
4460 | 305 | message = u.relation_error('glance object-store', ret) | ||
4461 | 306 | amulet.raise_status(amulet.FAIL, msg=message) | ||
4462 | 307 | |||
4463 | 308 | def test_swift_proxy_object_store_relation(self): | ||
4464 | 309 | """Verify the swift-proxy to glance object-store relation data.""" | ||
4465 | 310 | unit = self.swift_proxy_sentry | ||
4466 | 311 | relation = ['object-store', 'glance:object-store'] | ||
4467 | 312 | expected = {'private-address': u.valid_ip} | ||
4468 | 313 | ret = u.validate_relation_data(unit, relation, expected) | ||
4469 | 314 | if ret: | ||
4470 | 315 | message = u.relation_error('swift-proxy object-store', ret) | ||
4471 | 316 | amulet.raise_status(amulet.FAIL, msg=message) | ||
4472 | 317 | |||
4473 | 318 | def test_restart_on_config_change(self): | ||
4474 | 319 | """Verify that the specified services are restarted when the config | ||
4475 | 320 | is changed.""" | ||
4476 | 321 | svc = 'swift-proxy' | ||
4477 | 322 | self.d.configure('swift-proxy', {'node-timeout': '90'}) | ||
4478 | 323 | |||
4479 | 324 | if not u.service_restarted(self.swift_proxy_sentry, svc, | ||
4480 | 325 | '/etc/swift/proxy-server.conf'): | ||
4481 | 326 | msg = "service {} didn't restart after config change".format(svc) | ||
4482 | 327 | amulet.raise_status(amulet.FAIL, msg=msg) | ||
4483 | 328 | |||
4484 | 329 | self.d.configure('swift-proxy', {'node-timeout': '60'}) | ||
4485 | 330 | |||
4486 | 331 | def test_swift_config(self): | ||
4487 | 332 | """Verify the data in the swift config file.""" | ||
4488 | 333 | unit = self.swift_proxy_sentry | ||
4489 | 334 | conf = '/etc/swift/swift.conf' | ||
4490 | 335 | swift_proxy_relation = unit.relation('swift-storage', | ||
4491 | 336 | 'swift-storage:swift-storage') | ||
4492 | 337 | expected = { | ||
4493 | 338 | 'swift_hash_path_suffix': swift_proxy_relation['swift_hash'] | ||
4494 | 339 | } | ||
4495 | 340 | |||
4496 | 341 | ret = u.validate_config_data(unit, conf, 'swift-hash', expected) | ||
4497 | 342 | if ret: | ||
4498 | 343 | message = "swift config error: {}".format(ret) | ||
4499 | 344 | amulet.raise_status(amulet.FAIL, msg=message) | ||
4500 | 345 | |||
4501 | 346 | def test_proxy_server_icehouse_config(self): | ||
4502 | 347 | """Verify the data in the proxy-server config file.""" | ||
4503 | 348 | if self._get_openstack_release() < self.precise_icehouse: | ||
4504 | 349 | return | ||
4505 | 350 | |||
4506 | 351 | unit = self.swift_proxy_sentry | ||
4507 | 352 | conf = '/etc/swift/proxy-server.conf' | ||
4508 | 353 | keystone_relation = self.keystone_sentry.relation('identity-service', | ||
4509 | 354 | 'swift-proxy:identity-service') | ||
4510 | 355 | swift_proxy_relation = unit.relation('identity-service', | ||
4511 | 356 | 'keystone:identity-service') | ||
4512 | 357 | swift_proxy_ip = swift_proxy_relation['private-address'] | ||
4513 | 358 | auth_host = keystone_relation['auth_host'] | ||
4514 | 359 | auth_protocol = keystone_relation['auth_protocol'] | ||
4515 | 360 | |||
4516 | 361 | expected = { | ||
4517 | 362 | 'DEFAULT': { | ||
4518 | 363 | 'bind_port': '8080', | ||
4519 | 364 | 'workers': '0', | ||
4520 | 365 | 'user': 'swift' | ||
4521 | 366 | }, | ||
4522 | 367 | 'pipeline:main': { | ||
4523 | 368 | 'pipeline': 'gatekeeper healthcheck cache swift3 s3token ' | ||
4524 | 369 | 'container_sync bulk tempurl slo dlo formpost ' | ||
4525 | 370 | 'authtoken keystoneauth staticweb ' | ||
4526 | 371 | 'container-quotas account-quotas proxy-server' | ||
4527 | 372 | }, | ||
4528 | 373 | 'app:proxy-server': { | ||
4529 | 374 | 'use': 'egg:swift#proxy', | ||
4530 | 375 | 'allow_account_management': 'true', | ||
4531 | 376 | 'account_autocreate': 'true', | ||
4532 | 377 | 'node_timeout': '60', | ||
4533 | 378 | 'recoverable_node_timeout': '30' | ||
4534 | 379 | }, | ||
4535 | 380 | 'filter:tempauth': { | ||
4536 | 381 | 'use': 'egg:swift#tempauth', | ||
4537 | 382 | 'user_system_root': 'testpass .admin https://{}:8080/v1/' | ||
4538 | 383 | 'AUTH_system'.format(swift_proxy_ip) | ||
4539 | 384 | }, | ||
4540 | 385 | 'filter:healthcheck': {'use': 'egg:swift#healthcheck'}, | ||
4541 | 386 | 'filter:cache': { | ||
4542 | 387 | 'use': 'egg:swift#memcache', | ||
4543 | 388 | 'memcache_servers': '{}:11211'.format(swift_proxy_ip) | ||
4544 | 389 | }, | ||
4545 | 390 | 'filter:account-quotas': {'use': 'egg:swift#account_quotas'}, | ||
4546 | 391 | 'filter:container-quotas': {'use': 'egg:swift#container_quotas'}, | ||
4547 | 392 | 'filter:staticweb': {'use': 'egg:swift#staticweb'}, | ||
4548 | 393 | 'filter:bulk': {'use': 'egg:swift#bulk'}, | ||
4549 | 394 | 'filter:slo': {'use': 'egg:swift#slo'}, | ||
4550 | 395 | 'filter:dlo': {'use': 'egg:swift#dlo'}, | ||
4551 | 396 | 'filter:formpost': {'use': 'egg:swift#formpost'}, | ||
4552 | 397 | 'filter:tempurl': {'use': 'egg:swift#tempurl'}, | ||
4553 | 398 | 'filter:container_sync': {'use': 'egg:swift#container_sync'}, | ||
4554 | 399 | 'filter:gatekeeper': {'use': 'egg:swift#gatekeeper'}, | ||
4555 | 400 | 'filter:keystoneauth': { | ||
4556 | 401 | 'use': 'egg:swift#keystoneauth', | ||
4557 | 402 | 'operator_roles': 'Member,Admin' | ||
4558 | 403 | }, | ||
4559 | 404 | 'filter:authtoken': { | ||
4560 | 405 | 'paste.filter_factory': 'keystoneclient.middleware.' | ||
4561 | 406 | 'auth_token:filter_factory', | ||
4562 | 407 | 'auth_host': auth_host, | ||
4563 | 408 | 'auth_port': keystone_relation['auth_port'], | ||
4564 | 409 | 'auth_protocol': auth_protocol, | ||
4565 | 410 | 'auth_uri': '{}://{}:{}'.format(auth_protocol, auth_host, | ||
4566 | 411 | keystone_relation['service_port']), | ||
4567 | 412 | 'admin_tenant_name': keystone_relation['service_tenant'], | ||
4568 | 413 | 'admin_user': keystone_relation['service_username'], | ||
4569 | 414 | 'admin_password': keystone_relation['service_password'], | ||
4570 | 415 | 'delay_auth_decision': 'true', | ||
4571 | 416 | 'signing_dir': '/etc/swift', | ||
4572 | 417 | 'cache': 'swift.cache' | ||
4573 | 418 | }, | ||
4574 | 419 | 'filter:s3token': { | ||
4575 | 420 | 'paste.filter_factory': 'keystoneclient.middleware.' | ||
4576 | 421 | 's3_token:filter_factory', | ||
4577 | 422 | 'service_host': keystone_relation['service_host'], | ||
4578 | 423 | 'service_port': keystone_relation['service_port'], | ||
4579 | 424 | 'auth_port': keystone_relation['auth_port'], | ||
4580 | 425 | 'auth_host': keystone_relation['auth_host'], | ||
4581 | 426 | 'auth_protocol': keystone_relation['auth_protocol'], | ||
4582 | 427 | 'auth_token': keystone_relation['admin_token'], | ||
4583 | 428 | 'admin_token': keystone_relation['admin_token'] | ||
4584 | 429 | }, | ||
4585 | 430 | 'filter:swift3': {'use': 'egg:swift3#swift3'} | ||
4586 | 431 | } | ||
4587 | 432 | |||
4588 | 433 | for section, pairs in expected.iteritems(): | ||
4589 | 434 | ret = u.validate_config_data(unit, conf, section, pairs) | ||
4590 | 435 | if ret: | ||
4591 | 436 | message = "proxy-server config error: {}".format(ret) | ||
4592 | 437 | amulet.raise_status(amulet.FAIL, msg=message) | ||
4593 | 438 | |||
4594 | 439 | def test_proxy_server_havana_config(self): | ||
4595 | 440 | """Verify the data in the proxy-server config file.""" | ||
4596 | 441 | if self._get_openstack_release() != self.precise_havana: | ||
4597 | 442 | return | ||
4598 | 443 | |||
4599 | 444 | unit = self.swift_proxy_sentry | ||
4600 | 445 | conf = '/etc/swift/proxy-server.conf' | ||
4601 | 446 | keystone_relation = self.keystone_sentry.relation('identity-service', | ||
4602 | 447 | 'swift-proxy:identity-service') | ||
4603 | 448 | swift_proxy_relation = unit.relation('identity-service', | ||
4604 | 449 | 'keystone:identity-service') | ||
4605 | 450 | swift_proxy_ip = swift_proxy_relation['private-address'] | ||
4606 | 451 | auth_host = keystone_relation['auth_host'] | ||
4607 | 452 | auth_protocol = keystone_relation['auth_protocol'] | ||
4608 | 453 | |||
4609 | 454 | expected = { | ||
4610 | 455 | 'DEFAULT': { | ||
4611 | 456 | 'bind_port': '8080', | ||
4612 | 457 | 'workers': '0', | ||
4613 | 458 | 'user': 'swift' | ||
4614 | 459 | }, | ||
4615 | 460 | 'pipeline:main': { | ||
4616 | 461 | 'pipeline': 'healthcheck cache swift3 authtoken ' | ||
4617 | 462 | 'keystoneauth container-quotas account-quotas ' | ||
4618 | 463 | 'proxy-server' | ||
4619 | 464 | }, | ||
4620 | 465 | 'app:proxy-server': { | ||
4621 | 466 | 'use': 'egg:swift#proxy', | ||
4622 | 467 | 'allow_account_management': 'true', | ||
4623 | 468 | 'account_autocreate': 'true', | ||
4624 | 469 | 'node_timeout': '60', | ||
4625 | 470 | 'recoverable_node_timeout': '30' | ||
4626 | 471 | }, | ||
4627 | 472 | 'filter:tempauth': { | ||
4628 | 473 | 'use': 'egg:swift#tempauth', | ||
4629 | 474 | 'user_system_root': 'testpass .admin https://{}:8080/v1/' | ||
4630 | 475 | 'AUTH_system'.format(swift_proxy_ip) | ||
4631 | 476 | }, | ||
4632 | 477 | 'filter:healthcheck': {'use': 'egg:swift#healthcheck'}, | ||
4633 | 478 | 'filter:cache': { | ||
4634 | 479 | 'use': 'egg:swift#memcache', | ||
4635 | 480 | 'memcache_servers': '{}:11211'.format(swift_proxy_ip) | ||
4636 | 481 | }, | ||
4637 | 482 | 'filter:account-quotas': {'use': 'egg:swift#account_quotas'}, | ||
4638 | 483 | 'filter:container-quotas': {'use': 'egg:swift#container_quotas'}, | ||
4639 | 484 | 'filter:keystoneauth': { | ||
4640 | 485 | 'use': 'egg:swift#keystoneauth', | ||
4641 | 486 | 'operator_roles': 'Member,Admin' | ||
4642 | 487 | }, | ||
4643 | 488 | 'filter:authtoken': { | ||
4644 | 489 | 'paste.filter_factory': 'keystoneclient.middleware.' | ||
4645 | 490 | 'auth_token:filter_factory', | ||
4646 | 491 | 'auth_host': auth_host, | ||
4647 | 492 | 'auth_port': keystone_relation['auth_port'], | ||
4648 | 493 | 'auth_protocol': auth_protocol, | ||
4649 | 494 | 'auth_uri': '{}://{}:{}'.format(auth_protocol, auth_host, | ||
4650 | 495 | keystone_relation['service_port']), | ||
4651 | 496 | 'admin_tenant_name': keystone_relation['service_tenant'], | ||
4652 | 497 | 'admin_user': keystone_relation['service_username'], | ||
4653 | 498 | 'admin_password': keystone_relation['service_password'], | ||
4654 | 499 | 'delay_auth_decision': 'true', | ||
4655 | 500 | 'signing_dir': '/etc/swift', | ||
4656 | 501 | 'cache': 'swift.cache' | ||
4657 | 502 | }, | ||
4658 | 503 | 'filter:s3token': { | ||
4659 | 504 | 'paste.filter_factory': 'keystone.middleware.s3_token:' | ||
4660 | 505 | 'filter_factory', | ||
4661 | 506 | 'service_host': keystone_relation['service_host'], | ||
4662 | 507 | 'service_port': keystone_relation['service_port'], | ||
4663 | 508 | 'auth_port': keystone_relation['auth_port'], | ||
4664 | 509 | 'auth_host': keystone_relation['auth_host'], | ||
4665 | 510 | 'auth_protocol': keystone_relation['auth_protocol'], | ||
4666 | 511 | 'auth_token': keystone_relation['admin_token'], | ||
4667 | 512 | 'admin_token': keystone_relation['admin_token'], | ||
4668 | 513 | 'service_protocol': keystone_relation['service_protocol'] | ||
4669 | 514 | }, | ||
4670 | 515 | 'filter:swift3': {'use': 'egg:swift3#swift3'} | ||
4671 | 516 | } | ||
4672 | 517 | |||
4673 | 518 | for section, pairs in expected.iteritems(): | ||
4674 | 519 | ret = u.validate_config_data(unit, conf, section, pairs) | ||
4675 | 520 | if ret: | ||
4676 | 521 | message = "proxy-server config error: {}".format(ret) | ||
4677 | 522 | amulet.raise_status(amulet.FAIL, msg=message) | ||
4678 | 523 | |||
4679 | 524 | def test_proxy_server_grizzly_config(self): | ||
4680 | 525 | """Verify the data in the proxy-server config file.""" | ||
4681 | 526 | if self._get_openstack_release() != self.precise_grizzly: | ||
4682 | 527 | return | ||
4683 | 528 | |||
4684 | 529 | unit = self.swift_proxy_sentry | ||
4685 | 530 | conf = '/etc/swift/proxy-server.conf' | ||
4686 | 531 | keystone_relation = self.keystone_sentry.relation('identity-service', | ||
4687 | 532 | 'swift-proxy:identity-service') | ||
4688 | 533 | swift_proxy_relation = unit.relation('identity-service', | ||
4689 | 534 | 'keystone:identity-service') | ||
4690 | 535 | swift_proxy_ip = swift_proxy_relation['private-address'] | ||
4691 | 536 | auth_host = keystone_relation['auth_host'] | ||
4692 | 537 | auth_protocol = keystone_relation['auth_protocol'] | ||
4693 | 538 | |||
4694 | 539 | expected = { | ||
4695 | 540 | 'DEFAULT': { | ||
4696 | 541 | 'bind_port': '8080', | ||
4697 | 542 | 'workers': '0', | ||
4698 | 543 | 'user': 'swift' | ||
4699 | 544 | }, | ||
4700 | 545 | 'pipeline:main': { | ||
4701 | 546 | 'pipeline': 'healthcheck cache swift3 s3token authtoken ' | ||
4702 | 547 | 'keystone container-quotas account-quotas ' | ||
4703 | 548 | 'proxy-server' | ||
4704 | 549 | }, | ||
4705 | 550 | 'app:proxy-server': { | ||
4706 | 551 | 'use': 'egg:swift#proxy', | ||
4707 | 552 | 'allow_account_management': 'true', | ||
4708 | 553 | 'account_autocreate': 'true', | ||
4709 | 554 | 'node_timeout': '60', | ||
4710 | 555 | 'recoverable_node_timeout': '30' | ||
4711 | 556 | }, | ||
4712 | 557 | 'filter:tempauth': { | ||
4713 | 558 | 'use': 'egg:swift#tempauth', | ||
4714 | 559 | 'user_system_root': 'testpass .admin https://{}:8080/v1/' | ||
4715 | 560 | 'AUTH_system'.format(swift_proxy_ip) | ||
4716 | 561 | }, | ||
4717 | 562 | 'filter:healthcheck': {'use': 'egg:swift#healthcheck'}, | ||
4718 | 563 | 'filter:cache': { | ||
4719 | 564 | 'use': 'egg:swift#memcache', | ||
4720 | 565 | 'memcache_servers': '{}:11211'.format(swift_proxy_ip) | ||
4721 | 566 | }, | ||
4722 | 567 | 'filter:account-quotas': {'use': 'egg:swift#account_quotas'}, | ||
4723 | 568 | 'filter:container-quotas': {'use': 'egg:swift#container_quotas'}, | ||
4724 | 569 | 'filter:keystone': { | ||
4725 | 570 | 'paste.filter_factory': 'swift.common.middleware.' | ||
4726 | 571 | 'keystoneauth:filter_factory', | ||
4727 | 572 | 'operator_roles': 'Member,Admin' | ||
4728 | 573 | }, | ||
4729 | 574 | 'filter:authtoken': { | ||
4730 | 575 | 'paste.filter_factory': 'keystone.middleware.auth_token:' | ||
4731 | 576 | 'filter_factory', | ||
4732 | 577 | 'auth_host': auth_host, | ||
4733 | 578 | 'auth_port': keystone_relation['auth_port'], | ||
4734 | 579 | 'auth_protocol': auth_protocol, | ||
4735 | 580 | 'auth_uri': '{}://{}:{}'.format(auth_protocol, auth_host, | ||
4736 | 581 | keystone_relation['service_port']), | ||
4737 | 582 | 'admin_tenant_name': keystone_relation['service_tenant'], | ||
4738 | 583 | 'admin_user': keystone_relation['service_username'], | ||
4739 | 584 | 'admin_password': keystone_relation['service_password'], | ||
4740 | 585 | 'delay_auth_decision': 'true', | ||
4741 | 586 | 'signing_dir': '/etc/swift' | ||
4742 | 587 | }, | ||
4743 | 588 | 'filter:s3token': { | ||
4744 | 589 | 'paste.filter_factory': 'keystone.middleware.s3_token:' | ||
4745 | 590 | 'filter_factory', | ||
4746 | 591 | 'service_host': keystone_relation['service_host'], | ||
4747 | 592 | 'service_port': keystone_relation['service_port'], | ||
4748 | 593 | 'auth_port': keystone_relation['auth_port'], | ||
4749 | 594 | 'auth_host': keystone_relation['auth_host'], | ||
4750 | 595 | 'auth_protocol': keystone_relation['auth_protocol'], | ||
4751 | 596 | 'auth_token': keystone_relation['admin_token'], | ||
4752 | 597 | 'admin_token': keystone_relation['admin_token'], | ||
4753 | 598 | 'service_protocol': keystone_relation['service_protocol'] | ||
4754 | 599 | }, | ||
4755 | 600 | 'filter:swift3': {'use': 'egg:swift3#swift3'} | ||
4756 | 601 | } | ||
4757 | 602 | |||
4758 | 603 | for section, pairs in expected.iteritems(): | ||
4759 | 604 | ret = u.validate_config_data(unit, conf, section, pairs) | ||
4760 | 605 | if ret: | ||
4761 | 606 | message = "proxy-server config error: {}".format(ret) | ||
4762 | 607 | amulet.raise_status(amulet.FAIL, msg=message) | ||
4763 | 608 | |||
4764 | 609 | def test_proxy_server_folsom_config(self): | ||
4765 | 610 | """Verify the data in the proxy-server config file.""" | ||
4766 | 611 | if self._get_openstack_release() != self.precise_folsom: | ||
4767 | 612 | return | ||
4768 | 613 | |||
4769 | 614 | unit = self.swift_proxy_sentry | ||
4770 | 615 | conf = '/etc/swift/proxy-server.conf' | ||
4771 | 616 | keystone_relation = self.keystone_sentry.relation('identity-service', | ||
4772 | 617 | 'swift-proxy:identity-service') | ||
4773 | 618 | swift_proxy_relation = unit.relation('identity-service', | ||
4774 | 619 | 'keystone:identity-service') | ||
4775 | 620 | swift_proxy_ip = swift_proxy_relation['private-address'] | ||
4776 | 621 | auth_host = keystone_relation['auth_host'] | ||
4777 | 622 | auth_protocol = keystone_relation['auth_protocol'] | ||
4778 | 623 | |||
4779 | 624 | expected = { | ||
4780 | 625 | 'DEFAULT': { | ||
4781 | 626 | 'bind_port': '8080', | ||
4782 | 627 | 'workers': '0', | ||
4783 | 628 | 'user': 'swift' | ||
4784 | 629 | }, | ||
4785 | 630 | 'pipeline:main': { | ||
4786 | 631 | 'pipeline': 'healthcheck cache swift3 s3token authtoken ' | ||
4787 | 632 | 'keystone proxy-server' | ||
4788 | 633 | }, | ||
4789 | 634 | 'app:proxy-server': { | ||
4790 | 635 | 'use': 'egg:swift#proxy', | ||
4791 | 636 | 'allow_account_management': 'true', | ||
4792 | 637 | 'account_autocreate': 'true', | ||
4793 | 638 | 'node_timeout': '60', | ||
4794 | 639 | 'recoverable_node_timeout': '30' | ||
4795 | 640 | }, | ||
4796 | 641 | 'filter:tempauth': { | ||
4797 | 642 | 'use': 'egg:swift#tempauth', | ||
4798 | 643 | 'user_system_root': 'testpass .admin https://{}:8080/v1/' | ||
4799 | 644 | 'AUTH_system'.format(swift_proxy_ip) | ||
4800 | 645 | }, | ||
4801 | 646 | 'filter:healthcheck': {'use': 'egg:swift#healthcheck'}, | ||
4802 | 647 | 'filter:cache': { | ||
4803 | 648 | 'use': 'egg:swift#memcache', | ||
4804 | 649 | 'memcache_servers': '{}:11211'.format(swift_proxy_ip) | ||
4805 | 650 | }, | ||
4806 | 651 | 'filter:keystone': { | ||
4807 | 652 | 'paste.filter_factory': 'keystone.middleware.swift_auth:' | ||
4808 | 653 | 'filter_factory', | ||
4809 | 654 | 'operator_roles': 'Member,Admin' | ||
4810 | 655 | }, | ||
4811 | 656 | 'filter:authtoken': { | ||
4812 | 657 | 'paste.filter_factory': 'keystone.middleware.auth_token:' | ||
4813 | 658 | 'filter_factory', | ||
4814 | 659 | 'auth_host': auth_host, | ||
4815 | 660 | 'auth_port': keystone_relation['auth_port'], | ||
4816 | 661 | 'auth_protocol': auth_protocol, | ||
4817 | 662 | 'auth_uri': '{}://{}:{}'.format(auth_protocol, auth_host, | ||
4818 | 663 | keystone_relation['service_port']), | ||
4819 | 664 | 'admin_tenant_name': keystone_relation['service_tenant'], | ||
4820 | 665 | 'admin_user': keystone_relation['service_username'], | ||
4821 | 666 | 'admin_password': keystone_relation['service_password'], | ||
4822 | 667 | 'delay_auth_decision': '1' | ||
4823 | 668 | }, | ||
4824 | 669 | 'filter:s3token': { | ||
4825 | 670 | 'paste.filter_factory': 'keystone.middleware.s3_token:' | ||
4826 | 671 | 'filter_factory', | ||
4827 | 672 | 'service_host': keystone_relation['service_host'], | ||
4828 | 673 | 'service_port': keystone_relation['service_port'], | ||
4829 | 674 | 'auth_port': keystone_relation['auth_port'], | ||
4830 | 675 | 'auth_host': keystone_relation['auth_host'], | ||
4831 | 676 | 'auth_protocol': keystone_relation['auth_protocol'], | ||
4832 | 677 | 'auth_token': keystone_relation['admin_token'], | ||
4833 | 678 | 'admin_token': keystone_relation['admin_token'], | ||
4834 | 679 | 'service_protocol': keystone_relation['service_protocol'] | ||
4835 | 680 | }, | ||
4836 | 681 | 'filter:swift3': {'use': 'egg:swift#swift3'} | ||
4837 | 682 | } | ||
4838 | 683 | |||
4839 | 684 | for section, pairs in expected.iteritems(): | ||
4840 | 685 | ret = u.validate_config_data(unit, conf, section, pairs) | ||
4841 | 686 | if ret: | ||
4842 | 687 | message = "proxy-server config error: {}".format(ret) | ||
4843 | 688 | amulet.raise_status(amulet.FAIL, msg=message) | ||
4844 | 689 | |||
4845 | 690 | def test_proxy_server_essex_config(self): | ||
4846 | 691 | """Verify the data in the proxy-server config file.""" | ||
4847 | 692 | if self._get_openstack_release() != self.precise_essex: | ||
4848 | 693 | return | ||
4849 | 694 | |||
4850 | 695 | unit = self.swift_proxy_sentry | ||
4851 | 696 | conf = '/etc/swift/proxy-server.conf' | ||
4852 | 697 | keystone_relation = self.keystone_sentry.relation('identity-service', | ||
4853 | 698 | 'swift-proxy:identity-service') | ||
4854 | 699 | swift_proxy_relation = unit.relation('identity-service', | ||
4855 | 700 | 'keystone:identity-service') | ||
4856 | 701 | swift_proxy_ip = swift_proxy_relation['private-address'] | ||
4857 | 702 | auth_host = keystone_relation['auth_host'] | ||
4858 | 703 | auth_protocol = keystone_relation['auth_protocol'] | ||
4859 | 704 | |||
4860 | 705 | expected = { | ||
4861 | 706 | 'DEFAULT': { | ||
4862 | 707 | 'bind_port': '8080', | ||
4863 | 708 | 'workers': '0', | ||
4864 | 709 | 'user': 'swift' | ||
4865 | 710 | }, | ||
4866 | 711 | 'pipeline:main': { | ||
4867 | 712 | 'pipeline': 'healthcheck cache swift3 s3token authtoken ' | ||
4868 | 713 | 'keystone proxy-server' | ||
4869 | 714 | }, | ||
4870 | 715 | 'app:proxy-server': { | ||
4871 | 716 | 'use': 'egg:swift#proxy', | ||
4872 | 717 | 'allow_account_management': 'true', | ||
4873 | 718 | 'account_autocreate': 'true', | ||
4874 | 719 | 'node_timeout': '60', | ||
4875 | 720 | 'recoverable_node_timeout': '30' | ||
4876 | 721 | }, | ||
4877 | 722 | 'filter:tempauth': { | ||
4878 | 723 | 'use': 'egg:swift#tempauth', | ||
4879 | 724 | 'user_system_root': 'testpass .admin https://{}:8080/v1/' | ||
4880 | 725 | 'AUTH_system'.format(swift_proxy_ip) | ||
4881 | 726 | }, | ||
4882 | 727 | 'filter:healthcheck': {'use': 'egg:swift#healthcheck'}, | ||
4883 | 728 | 'filter:cache': { | ||
4884 | 729 | 'use': 'egg:swift#memcache', | ||
4885 | 730 | 'memcache_servers': '{}:11211'.format(swift_proxy_ip) | ||
4886 | 731 | }, | ||
4887 | 732 | 'filter:keystone': { | ||
4888 | 733 | 'paste.filter_factory': 'keystone.middleware.swift_auth:' | ||
4889 | 734 | 'filter_factory', | ||
4890 | 735 | 'operator_roles': 'Member,Admin' | ||
4891 | 736 | }, | ||
4892 | 737 | 'filter:authtoken': { | ||
4893 | 738 | 'paste.filter_factory': 'keystone.middleware.auth_token:' | ||
4894 | 739 | 'filter_factory', | ||
4895 | 740 | 'auth_host': auth_host, | ||
4896 | 741 | 'auth_port': keystone_relation['auth_port'], | ||
4897 | 742 | 'auth_protocol': auth_protocol, | ||
4898 | 743 | 'auth_uri': '{}://{}:{}'.format(auth_protocol, auth_host, | ||
4899 | 744 | keystone_relation['service_port']), | ||
4900 | 745 | 'admin_tenant_name': keystone_relation['service_tenant'], | ||
4901 | 746 | 'admin_user': keystone_relation['service_username'], | ||
4902 | 747 | 'admin_password': keystone_relation['service_password'], | ||
4903 | 748 | 'delay_auth_decision': '1' | ||
4904 | 749 | }, | ||
4905 | 750 | 'filter:s3token': { | ||
4906 | 751 | 'paste.filter_factory': 'keystone.middleware.s3_token:' | ||
4907 | 752 | 'filter_factory', | ||
4908 | 753 | 'service_host': keystone_relation['service_host'], | ||
4909 | 754 | 'service_port': keystone_relation['service_port'], | ||
4910 | 755 | 'auth_port': keystone_relation['auth_port'], | ||
4911 | 756 | 'auth_host': keystone_relation['auth_host'], | ||
4912 | 757 | 'auth_protocol': keystone_relation['auth_protocol'], | ||
4913 | 758 | 'auth_token': keystone_relation['admin_token'], | ||
4914 | 759 | 'admin_token': keystone_relation['admin_token'], | ||
4915 | 760 | 'service_protocol': keystone_relation['service_protocol'] | ||
4916 | 761 | }, | ||
4917 | 762 | 'filter:swift3': {'use': 'egg:swift#swift3'} | ||
4918 | 763 | } | ||
4919 | 764 | |||
4920 | 765 | for section, pairs in expected.iteritems(): | ||
4921 | 766 | ret = u.validate_config_data(unit, conf, section, pairs) | ||
4922 | 767 | if ret: | ||
4923 | 768 | message = "proxy-server config error: {}".format(ret) | ||
4924 | 769 | amulet.raise_status(amulet.FAIL, msg=message) | ||
4925 | 770 | |||
4926 | 771 | def test_image_create(self): | ||
4927 | 772 | """Create an instance in glance, which is backed by swift, and validate | ||
4928 | 773 | that some of the metadata for the image match in glance and swift.""" | ||
4929 | 774 | # NOTE(coreycb): Skipping failing test on folsom until resolved. On | ||
4930 | 775 | # folsom only, uploading an image to glance gets 400 Bad | ||
4931 | 776 | # Request - Error uploading image: (error): [Errno 111] | ||
4932 | 777 | # ECONNREFUSED (HTTP 400) | ||
4933 | 778 | if self._get_openstack_release() == self.precise_folsom: | ||
4934 | 779 | u.log.error("Skipping failing test until resolved") | ||
4935 | 780 | return | ||
4936 | 781 | |||
4937 | 782 | # Create glance image | ||
4938 | 783 | image = u.create_cirros_image(self.glance, "cirros-image") | ||
4939 | 784 | if not image: | ||
4940 | 785 | amulet.raise_status(amulet.FAIL, msg="Image create failed") | ||
4941 | 786 | |||
4942 | 787 | # Validate that cirros image exists in glance and get its checksum/size | ||
4943 | 788 | images = list(self.glance.images.list()) | ||
4944 | 789 | if len(images) != 1: | ||
4945 | 790 | msg = "Expected 1 glance image, found {}".format(len(images)) | ||
4946 | 791 | amulet.raise_status(amulet.FAIL, msg=msg) | ||
4947 | 792 | |||
4948 | 793 | if images[0].name != 'cirros-image': | ||
4949 | 794 | message = "cirros image does not exist" | ||
4950 | 795 | amulet.raise_status(amulet.FAIL, msg=message) | ||
4951 | 796 | |||
4952 | 797 | glance_image_md5 = image.checksum | ||
4953 | 798 | glance_image_size = image.size | ||
4954 | 799 | |||
4955 | 800 | # Validate that swift object's checksum/size match that from glance | ||
4956 | 801 | headers, containers = self.swift.get_account() | ||
4957 | 802 | if len(containers) != 1: | ||
4958 | 803 | msg = "Expected 1 swift container, found {}".format(len(containers)) | ||
4959 | 804 | amulet.raise_status(amulet.FAIL, msg=msg) | ||
4960 | 805 | |||
4961 | 806 | container_name = containers[0].get('name') | ||
4962 | 807 | |||
4963 | 808 | headers, objects = self.swift.get_container(container_name) | ||
4964 | 809 | if len(objects) != 1: | ||
4965 | 810 | msg = "Expected 1 swift object, found {}".format(len(objects)) | ||
4966 | 811 | amulet.raise_status(amulet.FAIL, msg=msg) | ||
4967 | 812 | |||
4968 | 813 | swift_object_size = objects[0].get('bytes') | ||
4969 | 814 | swift_object_md5 = objects[0].get('hash') | ||
4970 | 815 | |||
4971 | 816 | if glance_image_size != swift_object_size: | ||
4972 | 817 | msg = "Glance image size {} != swift object size {}".format( \ | ||
4973 | 818 | glance_image_size, swift_object_size) | ||
4974 | 819 | amulet.raise_status(amulet.FAIL, msg=msg) | ||
4975 | 820 | |||
4976 | 821 | if glance_image_md5 != swift_object_md5: | ||
4977 | 822 | msg = "Glance image hash {} != swift object hash {}".format( \ | ||
4978 | 823 | glance_image_md5, swift_object_md5) | ||
4979 | 824 | amulet.raise_status(amulet.FAIL, msg=msg) | ||
4980 | 825 | |||
4981 | 826 | # Cleanup | ||
4982 | 827 | u.delete_image(self.glance, image) | ||
4983 | 0 | 828 | ||
4984 | === added directory 'tests/charmhelpers' | |||
4985 | === added file 'tests/charmhelpers/__init__.py' | |||
4986 | === added directory 'tests/charmhelpers/contrib' | |||
4987 | === added file 'tests/charmhelpers/contrib/__init__.py' | |||
4988 | === added directory 'tests/charmhelpers/contrib/amulet' | |||
4989 | === added file 'tests/charmhelpers/contrib/amulet/__init__.py' | |||
4990 | === added file 'tests/charmhelpers/contrib/amulet/deployment.py' | |||
4991 | --- tests/charmhelpers/contrib/amulet/deployment.py 1970-01-01 00:00:00 +0000 | |||
4992 | +++ tests/charmhelpers/contrib/amulet/deployment.py 2014-10-06 15:38:41 +0000 | |||
4993 | @@ -0,0 +1,72 @@ | |||
4994 | 1 | import amulet | ||
4995 | 2 | |||
4996 | 3 | import os | ||
4997 | 4 | |||
4998 | 5 | |||
4999 | 6 | class AmuletDeployment(object): | ||
5000 | 7 | """Amulet deployment. |
The diff has been truncated for viewing.