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