Merge lp:~gnuoy/charms/trusty/cinder-ceph/1453940-stable into lp:~openstack-charmers-archive/charms/precise/cinder-ceph/trunk
- Trusty Tahr (14.04)
- 1453940-stable
- Merge into trunk
Status: | Merged |
---|---|
Merged at revision: | 36 |
Proposed branch: | lp:~gnuoy/charms/trusty/cinder-ceph/1453940-stable |
Merge into: | lp:~openstack-charmers-archive/charms/precise/cinder-ceph/trunk |
Diff against target: |
751 lines (+357/-82) 12 files modified
hooks/charmhelpers/cli/__init__.py (+1/-5) hooks/charmhelpers/cli/commands.py (+4/-4) hooks/charmhelpers/cli/hookenv.py (+23/-0) hooks/charmhelpers/contrib/openstack/context.py (+8/-9) hooks/charmhelpers/contrib/openstack/utils.py (+7/-5) hooks/charmhelpers/contrib/storage/linux/ceph.py (+224/-2) hooks/charmhelpers/contrib/storage/linux/utils.py (+3/-2) hooks/charmhelpers/core/hookenv.py (+1/-20) hooks/charmhelpers/core/host.py (+2/-2) hooks/cinder_hooks.py (+13/-22) tests/basic_deployment.py (+52/-8) unit_tests/test_cinder_hooks.py (+19/-3) |
To merge this branch: | bzr merge lp:~gnuoy/charms/trusty/cinder-ceph/1453940-stable |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Chris Glass (community) | Approve | ||
Ryan Beisner (community) | Needs Fixing | ||
Review via email: mp+271261@code.launchpad.net |
Commit message
Description of the change
uosci-testing-bot (uosci-testing-bot) wrote : | # |
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_lint_check #10411 cinder-ceph for gnuoy mp271261
LINT OK: passed
Build: http://
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_amulet_test #6551 cinder-ceph for gnuoy mp271261
AMULET FAIL: amulet-test failed
AMULET Results (max last 2 lines):
make: *** [functional_test] Error 1
ERROR:root:Make target returned non-zero.
Full amulet test output: http://
Build: http://
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_lint_check #10436 cinder-ceph for gnuoy mp271261
LINT OK: passed
Build: http://
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_unit_test #9629 cinder-ceph for gnuoy mp271261
UNIT OK: passed
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_amulet_test #6578 cinder-ceph for gnuoy mp271261
AMULET FAIL: amulet-test failed
AMULET Results (max last 2 lines):
make: *** [functional_test] Error 1
ERROR:root:Make target returned non-zero.
Full amulet test output: http://
Build: http://
Ryan Beisner (1chb1n) wrote : | # |
To save you the time of grepping logs, that amulet fail is real.
00:17:33.288 2015-09-22 13:59:57,026 test_201_
...
00:17:33.289 Broker request invalid or failed: None
Liam Young (gnuoy) wrote : | # |
OSCI failure caused by ceph having not landed yet.
- 38. By Liam Young
-
Empty commit to trigger osci
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_unit_test #9652 cinder-ceph for gnuoy mp271261
UNIT OK: passed
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_amulet_test #6585 cinder-ceph for gnuoy mp271261
AMULET FAIL: amulet-test failed
AMULET Results (max last 2 lines):
make: *** [functional_test] Error 1
ERROR:root:Make target returned non-zero.
Full amulet test output: http://
Build: http://
- 39. By Liam Young
-
Empty commit to trigger osci
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_unit_test #9654 cinder-ceph for gnuoy mp271261
UNIT OK: passed
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_lint_check #10463 cinder-ceph for gnuoy mp271261
LINT OK: passed
Build: http://
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_amulet_test #6606 cinder-ceph for gnuoy mp271261
AMULET FAIL: amulet-test failed
AMULET Results (max last 2 lines):
make: *** [functional_test] Error 1
ERROR:root:Make target returned non-zero.
Full amulet test output: http://
Build: http://
- 40. By Liam Young
-
Empty commit to kick osci
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_unit_test #9712 cinder-ceph for gnuoy mp271261
UNIT OK: passed
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_lint_check #10524 cinder-ceph for gnuoy mp271261
LINT OK: passed
Build: http://
Liam Young (gnuoy) wrote : | # |
Since the latest revision of ceph is still not in the charm store I tests an amulet run manually with the latest ceph from stable. It LGTM http://
Chris Glass (tribaal) wrote : | # |
After further testing on a bastion, this should pass. In order to cut down on wait time I'm going to go ahead and merge this already.
+1
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_amulet_test #6666 cinder-ceph for gnuoy mp271261
AMULET OK: passed
Build: http://
Preview Diff
1 | === modified file 'hooks/charmhelpers/cli/__init__.py' | |||
2 | --- hooks/charmhelpers/cli/__init__.py 2015-08-10 16:34:26 +0000 | |||
3 | +++ hooks/charmhelpers/cli/__init__.py 2015-09-23 07:31:24 +0000 | |||
4 | @@ -152,15 +152,11 @@ | |||
5 | 152 | arguments = self.argument_parser.parse_args() | 152 | arguments = self.argument_parser.parse_args() |
6 | 153 | argspec = inspect.getargspec(arguments.func) | 153 | argspec = inspect.getargspec(arguments.func) |
7 | 154 | vargs = [] | 154 | vargs = [] |
8 | 155 | kwargs = {} | ||
9 | 156 | for arg in argspec.args: | 155 | for arg in argspec.args: |
10 | 157 | vargs.append(getattr(arguments, arg)) | 156 | vargs.append(getattr(arguments, arg)) |
11 | 158 | if argspec.varargs: | 157 | if argspec.varargs: |
12 | 159 | vargs.extend(getattr(arguments, argspec.varargs)) | 158 | vargs.extend(getattr(arguments, argspec.varargs)) |
17 | 160 | if argspec.keywords: | 159 | output = arguments.func(*vargs) |
14 | 161 | for kwarg in argspec.keywords.items(): | ||
15 | 162 | kwargs[kwarg] = getattr(arguments, kwarg) | ||
16 | 163 | output = arguments.func(*vargs, **kwargs) | ||
18 | 164 | if getattr(arguments.func, '_cli_test_command', False): | 160 | if getattr(arguments.func, '_cli_test_command', False): |
19 | 165 | self.exit_code = 0 if output else 1 | 161 | self.exit_code = 0 if output else 1 |
20 | 166 | output = '' | 162 | output = '' |
21 | 167 | 163 | ||
22 | === modified file 'hooks/charmhelpers/cli/commands.py' | |||
23 | --- hooks/charmhelpers/cli/commands.py 2015-08-10 16:34:26 +0000 | |||
24 | +++ hooks/charmhelpers/cli/commands.py 2015-09-23 07:31:24 +0000 | |||
25 | @@ -26,7 +26,7 @@ | |||
26 | 26 | """ | 26 | """ |
27 | 27 | Import the sub-modules which have decorated subcommands to register with chlp. | 27 | Import the sub-modules which have decorated subcommands to register with chlp. |
28 | 28 | """ | 28 | """ |
33 | 29 | import host # noqa | 29 | from . import host # noqa |
34 | 30 | import benchmark # noqa | 30 | from . import benchmark # noqa |
35 | 31 | import unitdata # noqa | 31 | from . import unitdata # noqa |
36 | 32 | from charmhelpers.core import hookenv # noqa | 32 | from . import hookenv # noqa |
37 | 33 | 33 | ||
38 | === added file 'hooks/charmhelpers/cli/hookenv.py' | |||
39 | --- hooks/charmhelpers/cli/hookenv.py 1970-01-01 00:00:00 +0000 | |||
40 | +++ hooks/charmhelpers/cli/hookenv.py 2015-09-23 07:31:24 +0000 | |||
41 | @@ -0,0 +1,23 @@ | |||
42 | 1 | # Copyright 2014-2015 Canonical Limited. | ||
43 | 2 | # | ||
44 | 3 | # This file is part of charm-helpers. | ||
45 | 4 | # | ||
46 | 5 | # charm-helpers is free software: you can redistribute it and/or modify | ||
47 | 6 | # it under the terms of the GNU Lesser General Public License version 3 as | ||
48 | 7 | # published by the Free Software Foundation. | ||
49 | 8 | # | ||
50 | 9 | # charm-helpers is distributed in the hope that it will be useful, | ||
51 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
52 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
53 | 12 | # GNU Lesser General Public License for more details. | ||
54 | 13 | # | ||
55 | 14 | # You should have received a copy of the GNU Lesser General Public License | ||
56 | 15 | # along with charm-helpers. If not, see <http://www.gnu.org/licenses/>. | ||
57 | 16 | |||
58 | 17 | from . import cmdline | ||
59 | 18 | from charmhelpers.core import hookenv | ||
60 | 19 | |||
61 | 20 | |||
62 | 21 | cmdline.subcommand('relation-id')(hookenv.relation_id._wrapped) | ||
63 | 22 | cmdline.subcommand('service-name')(hookenv.service_name) | ||
64 | 23 | cmdline.subcommand('remote-service-name')(hookenv.remote_service_name._wrapped) | ||
65 | 0 | 24 | ||
66 | === modified file 'hooks/charmhelpers/contrib/openstack/context.py' | |||
67 | --- hooks/charmhelpers/contrib/openstack/context.py 2015-08-10 16:34:26 +0000 | |||
68 | +++ hooks/charmhelpers/contrib/openstack/context.py 2015-09-23 07:31:24 +0000 | |||
69 | @@ -483,13 +483,15 @@ | |||
70 | 483 | 483 | ||
71 | 484 | log('Generating template context for ceph', level=DEBUG) | 484 | log('Generating template context for ceph', level=DEBUG) |
72 | 485 | mon_hosts = [] | 485 | mon_hosts = [] |
76 | 486 | auth = None | 486 | ctxt = { |
77 | 487 | key = None | 487 | 'use_syslog': str(config('use-syslog')).lower() |
78 | 488 | use_syslog = str(config('use-syslog')).lower() | 488 | } |
79 | 489 | for rid in relation_ids('ceph'): | 489 | for rid in relation_ids('ceph'): |
80 | 490 | for unit in related_units(rid): | 490 | for unit in related_units(rid): |
83 | 491 | auth = relation_get('auth', rid=rid, unit=unit) | 491 | if not ctxt.get('auth'): |
84 | 492 | key = relation_get('key', rid=rid, unit=unit) | 492 | ctxt['auth'] = relation_get('auth', rid=rid, unit=unit) |
85 | 493 | if not ctxt.get('key'): | ||
86 | 494 | ctxt['key'] = relation_get('key', rid=rid, unit=unit) | ||
87 | 493 | ceph_pub_addr = relation_get('ceph-public-address', rid=rid, | 495 | ceph_pub_addr = relation_get('ceph-public-address', rid=rid, |
88 | 494 | unit=unit) | 496 | unit=unit) |
89 | 495 | unit_priv_addr = relation_get('private-address', rid=rid, | 497 | unit_priv_addr = relation_get('private-address', rid=rid, |
90 | @@ -498,10 +500,7 @@ | |||
91 | 498 | ceph_addr = format_ipv6_addr(ceph_addr) or ceph_addr | 500 | ceph_addr = format_ipv6_addr(ceph_addr) or ceph_addr |
92 | 499 | mon_hosts.append(ceph_addr) | 501 | mon_hosts.append(ceph_addr) |
93 | 500 | 502 | ||
98 | 501 | ctxt = {'mon_hosts': ' '.join(sorted(mon_hosts)), | 503 | ctxt['mon_hosts'] = ' '.join(sorted(mon_hosts)) |
95 | 502 | 'auth': auth, | ||
96 | 503 | 'key': key, | ||
97 | 504 | 'use_syslog': use_syslog} | ||
99 | 505 | 504 | ||
100 | 506 | if not os.path.isdir('/etc/ceph'): | 505 | if not os.path.isdir('/etc/ceph'): |
101 | 507 | os.mkdir('/etc/ceph') | 506 | os.mkdir('/etc/ceph') |
102 | 508 | 507 | ||
103 | === modified file 'hooks/charmhelpers/contrib/openstack/utils.py' | |||
104 | --- hooks/charmhelpers/contrib/openstack/utils.py 2015-08-10 16:34:26 +0000 | |||
105 | +++ hooks/charmhelpers/contrib/openstack/utils.py 2015-09-23 07:31:24 +0000 | |||
106 | @@ -1,5 +1,3 @@ | |||
107 | 1 | #!/usr/bin/python | ||
108 | 2 | |||
109 | 3 | # Copyright 2014-2015 Canonical Limited. | 1 | # Copyright 2014-2015 Canonical Limited. |
110 | 4 | # | 2 | # |
111 | 5 | # This file is part of charm-helpers. | 3 | # This file is part of charm-helpers. |
112 | @@ -167,9 +165,9 @@ | |||
113 | 167 | error_out(e) | 165 | error_out(e) |
114 | 168 | 166 | ||
115 | 169 | 167 | ||
117 | 170 | def get_os_version_codename(codename): | 168 | def get_os_version_codename(codename, version_map=OPENSTACK_CODENAMES): |
118 | 171 | '''Determine OpenStack version number from codename.''' | 169 | '''Determine OpenStack version number from codename.''' |
120 | 172 | for k, v in six.iteritems(OPENSTACK_CODENAMES): | 170 | for k, v in six.iteritems(version_map): |
121 | 173 | if v == codename: | 171 | if v == codename: |
122 | 174 | return k | 172 | return k |
123 | 175 | e = 'Could not derive OpenStack version for '\ | 173 | e = 'Could not derive OpenStack version for '\ |
124 | @@ -392,7 +390,11 @@ | |||
125 | 392 | import apt_pkg as apt | 390 | import apt_pkg as apt |
126 | 393 | src = config('openstack-origin') | 391 | src = config('openstack-origin') |
127 | 394 | cur_vers = get_os_version_package(package) | 392 | cur_vers = get_os_version_package(package) |
129 | 395 | available_vers = get_os_version_install_source(src) | 393 | if "swift" in package: |
130 | 394 | codename = get_os_codename_install_source(src) | ||
131 | 395 | available_vers = get_os_version_codename(codename, SWIFT_CODENAMES) | ||
132 | 396 | else: | ||
133 | 397 | available_vers = get_os_version_install_source(src) | ||
134 | 396 | apt.init() | 398 | apt.init() |
135 | 397 | return apt.version_compare(available_vers, cur_vers) == 1 | 399 | return apt.version_compare(available_vers, cur_vers) == 1 |
136 | 398 | 400 | ||
137 | 399 | 401 | ||
138 | === modified file 'hooks/charmhelpers/contrib/storage/linux/ceph.py' | |||
139 | --- hooks/charmhelpers/contrib/storage/linux/ceph.py 2015-08-10 16:34:26 +0000 | |||
140 | +++ hooks/charmhelpers/contrib/storage/linux/ceph.py 2015-09-23 07:31:24 +0000 | |||
141 | @@ -28,6 +28,7 @@ | |||
142 | 28 | import shutil | 28 | import shutil |
143 | 29 | import json | 29 | import json |
144 | 30 | import time | 30 | import time |
145 | 31 | import uuid | ||
146 | 31 | 32 | ||
147 | 32 | from subprocess import ( | 33 | from subprocess import ( |
148 | 33 | check_call, | 34 | check_call, |
149 | @@ -35,8 +36,10 @@ | |||
150 | 35 | CalledProcessError, | 36 | CalledProcessError, |
151 | 36 | ) | 37 | ) |
152 | 37 | from charmhelpers.core.hookenv import ( | 38 | from charmhelpers.core.hookenv import ( |
153 | 39 | local_unit, | ||
154 | 38 | relation_get, | 40 | relation_get, |
155 | 39 | relation_ids, | 41 | relation_ids, |
156 | 42 | relation_set, | ||
157 | 40 | related_units, | 43 | related_units, |
158 | 41 | log, | 44 | log, |
159 | 42 | DEBUG, | 45 | DEBUG, |
160 | @@ -411,17 +414,52 @@ | |||
161 | 411 | 414 | ||
162 | 412 | The API is versioned and defaults to version 1. | 415 | The API is versioned and defaults to version 1. |
163 | 413 | """ | 416 | """ |
165 | 414 | def __init__(self, api_version=1): | 417 | def __init__(self, api_version=1, request_id=None): |
166 | 415 | self.api_version = api_version | 418 | self.api_version = api_version |
167 | 419 | if request_id: | ||
168 | 420 | self.request_id = request_id | ||
169 | 421 | else: | ||
170 | 422 | self.request_id = str(uuid.uuid1()) | ||
171 | 416 | self.ops = [] | 423 | self.ops = [] |
172 | 417 | 424 | ||
173 | 418 | def add_op_create_pool(self, name, replica_count=3): | 425 | def add_op_create_pool(self, name, replica_count=3): |
174 | 419 | self.ops.append({'op': 'create-pool', 'name': name, | 426 | self.ops.append({'op': 'create-pool', 'name': name, |
175 | 420 | 'replicas': replica_count}) | 427 | 'replicas': replica_count}) |
176 | 421 | 428 | ||
177 | 429 | def set_ops(self, ops): | ||
178 | 430 | """Set request ops to provided value. | ||
179 | 431 | |||
180 | 432 | Useful for injecting ops that come from a previous request | ||
181 | 433 | to allow comparisons to ensure validity. | ||
182 | 434 | """ | ||
183 | 435 | self.ops = ops | ||
184 | 436 | |||
185 | 422 | @property | 437 | @property |
186 | 423 | def request(self): | 438 | def request(self): |
188 | 424 | return json.dumps({'api-version': self.api_version, 'ops': self.ops}) | 439 | return json.dumps({'api-version': self.api_version, 'ops': self.ops, |
189 | 440 | 'request-id': self.request_id}) | ||
190 | 441 | |||
191 | 442 | def _ops_equal(self, other): | ||
192 | 443 | if len(self.ops) == len(other.ops): | ||
193 | 444 | for req_no in range(0, len(self.ops)): | ||
194 | 445 | for key in ['replicas', 'name', 'op']: | ||
195 | 446 | if self.ops[req_no][key] != other.ops[req_no][key]: | ||
196 | 447 | return False | ||
197 | 448 | else: | ||
198 | 449 | return False | ||
199 | 450 | return True | ||
200 | 451 | |||
201 | 452 | def __eq__(self, other): | ||
202 | 453 | if not isinstance(other, self.__class__): | ||
203 | 454 | return False | ||
204 | 455 | if self.api_version == other.api_version and \ | ||
205 | 456 | self._ops_equal(other): | ||
206 | 457 | return True | ||
207 | 458 | else: | ||
208 | 459 | return False | ||
209 | 460 | |||
210 | 461 | def __ne__(self, other): | ||
211 | 462 | return not self.__eq__(other) | ||
212 | 425 | 463 | ||
213 | 426 | 464 | ||
214 | 427 | class CephBrokerRsp(object): | 465 | class CephBrokerRsp(object): |
215 | @@ -431,14 +469,198 @@ | |||
216 | 431 | 469 | ||
217 | 432 | The API is versioned and defaults to version 1. | 470 | The API is versioned and defaults to version 1. |
218 | 433 | """ | 471 | """ |
219 | 472 | |||
220 | 434 | def __init__(self, encoded_rsp): | 473 | def __init__(self, encoded_rsp): |
221 | 435 | self.api_version = None | 474 | self.api_version = None |
222 | 436 | self.rsp = json.loads(encoded_rsp) | 475 | self.rsp = json.loads(encoded_rsp) |
223 | 437 | 476 | ||
224 | 438 | @property | 477 | @property |
225 | 478 | def request_id(self): | ||
226 | 479 | return self.rsp.get('request-id') | ||
227 | 480 | |||
228 | 481 | @property | ||
229 | 439 | def exit_code(self): | 482 | def exit_code(self): |
230 | 440 | return self.rsp.get('exit-code') | 483 | return self.rsp.get('exit-code') |
231 | 441 | 484 | ||
232 | 442 | @property | 485 | @property |
233 | 443 | def exit_msg(self): | 486 | def exit_msg(self): |
234 | 444 | return self.rsp.get('stderr') | 487 | return self.rsp.get('stderr') |
235 | 488 | |||
236 | 489 | |||
237 | 490 | # Ceph Broker Conversation: | ||
238 | 491 | # If a charm needs an action to be taken by ceph it can create a CephBrokerRq | ||
239 | 492 | # and send that request to ceph via the ceph relation. The CephBrokerRq has a | ||
240 | 493 | # unique id so that the client can identity which CephBrokerRsp is associated | ||
241 | 494 | # with the request. Ceph will also respond to each client unit individually | ||
242 | 495 | # creating a response key per client unit eg glance/0 will get a CephBrokerRsp | ||
243 | 496 | # via key broker-rsp-glance-0 | ||
244 | 497 | # | ||
245 | 498 | # To use this the charm can just do something like: | ||
246 | 499 | # | ||
247 | 500 | # from charmhelpers.contrib.storage.linux.ceph import ( | ||
248 | 501 | # send_request_if_needed, | ||
249 | 502 | # is_request_complete, | ||
250 | 503 | # CephBrokerRq, | ||
251 | 504 | # ) | ||
252 | 505 | # | ||
253 | 506 | # @hooks.hook('ceph-relation-changed') | ||
254 | 507 | # def ceph_changed(): | ||
255 | 508 | # rq = CephBrokerRq() | ||
256 | 509 | # rq.add_op_create_pool(name='poolname', replica_count=3) | ||
257 | 510 | # | ||
258 | 511 | # if is_request_complete(rq): | ||
259 | 512 | # <Request complete actions> | ||
260 | 513 | # else: | ||
261 | 514 | # send_request_if_needed(get_ceph_request()) | ||
262 | 515 | # | ||
263 | 516 | # CephBrokerRq and CephBrokerRsp are serialized into JSON. Below is an example | ||
264 | 517 | # of glance having sent a request to ceph which ceph has successfully processed | ||
265 | 518 | # 'ceph:8': { | ||
266 | 519 | # 'ceph/0': { | ||
267 | 520 | # 'auth': 'cephx', | ||
268 | 521 | # 'broker-rsp-glance-0': '{"request-id": "0bc7dc54", "exit-code": 0}', | ||
269 | 522 | # 'broker_rsp': '{"request-id": "0da543b8", "exit-code": 0}', | ||
270 | 523 | # 'ceph-public-address': '10.5.44.103', | ||
271 | 524 | # 'key': 'AQCLDttVuHXINhAAvI144CB09dYchhHyTUY9BQ==', | ||
272 | 525 | # 'private-address': '10.5.44.103', | ||
273 | 526 | # }, | ||
274 | 527 | # 'glance/0': { | ||
275 | 528 | # 'broker_req': ('{"api-version": 1, "request-id": "0bc7dc54", ' | ||
276 | 529 | # '"ops": [{"replicas": 3, "name": "glance", ' | ||
277 | 530 | # '"op": "create-pool"}]}'), | ||
278 | 531 | # 'private-address': '10.5.44.109', | ||
279 | 532 | # }, | ||
280 | 533 | # } | ||
281 | 534 | |||
282 | 535 | def get_previous_request(rid): | ||
283 | 536 | """Return the last ceph broker request sent on a given relation | ||
284 | 537 | |||
285 | 538 | @param rid: Relation id to query for request | ||
286 | 539 | """ | ||
287 | 540 | request = None | ||
288 | 541 | broker_req = relation_get(attribute='broker_req', rid=rid, | ||
289 | 542 | unit=local_unit()) | ||
290 | 543 | if broker_req: | ||
291 | 544 | request_data = json.loads(broker_req) | ||
292 | 545 | request = CephBrokerRq(api_version=request_data['api-version'], | ||
293 | 546 | request_id=request_data['request-id']) | ||
294 | 547 | request.set_ops(request_data['ops']) | ||
295 | 548 | |||
296 | 549 | return request | ||
297 | 550 | |||
298 | 551 | |||
299 | 552 | def get_request_states(request): | ||
300 | 553 | """Return a dict of requests per relation id with their corresponding | ||
301 | 554 | completion state. | ||
302 | 555 | |||
303 | 556 | This allows a charm, which has a request for ceph, to see whether there is | ||
304 | 557 | an equivalent request already being processed and if so what state that | ||
305 | 558 | request is in. | ||
306 | 559 | |||
307 | 560 | @param request: A CephBrokerRq object | ||
308 | 561 | """ | ||
309 | 562 | complete = [] | ||
310 | 563 | requests = {} | ||
311 | 564 | for rid in relation_ids('ceph'): | ||
312 | 565 | complete = False | ||
313 | 566 | previous_request = get_previous_request(rid) | ||
314 | 567 | if request == previous_request: | ||
315 | 568 | sent = True | ||
316 | 569 | complete = is_request_complete_for_rid(previous_request, rid) | ||
317 | 570 | else: | ||
318 | 571 | sent = False | ||
319 | 572 | complete = False | ||
320 | 573 | |||
321 | 574 | requests[rid] = { | ||
322 | 575 | 'sent': sent, | ||
323 | 576 | 'complete': complete, | ||
324 | 577 | } | ||
325 | 578 | |||
326 | 579 | return requests | ||
327 | 580 | |||
328 | 581 | |||
329 | 582 | def is_request_sent(request): | ||
330 | 583 | """Check to see if a functionally equivalent request has already been sent | ||
331 | 584 | |||
332 | 585 | Returns True if a similair request has been sent | ||
333 | 586 | |||
334 | 587 | @param request: A CephBrokerRq object | ||
335 | 588 | """ | ||
336 | 589 | states = get_request_states(request) | ||
337 | 590 | for rid in states.keys(): | ||
338 | 591 | if not states[rid]['sent']: | ||
339 | 592 | return False | ||
340 | 593 | |||
341 | 594 | return True | ||
342 | 595 | |||
343 | 596 | |||
344 | 597 | def is_request_complete(request): | ||
345 | 598 | """Check to see if a functionally equivalent request has already been | ||
346 | 599 | completed | ||
347 | 600 | |||
348 | 601 | Returns True if a similair request has been completed | ||
349 | 602 | |||
350 | 603 | @param request: A CephBrokerRq object | ||
351 | 604 | """ | ||
352 | 605 | states = get_request_states(request) | ||
353 | 606 | for rid in states.keys(): | ||
354 | 607 | if not states[rid]['complete']: | ||
355 | 608 | return False | ||
356 | 609 | |||
357 | 610 | return True | ||
358 | 611 | |||
359 | 612 | |||
360 | 613 | def is_request_complete_for_rid(request, rid): | ||
361 | 614 | """Check if a given request has been completed on the given relation | ||
362 | 615 | |||
363 | 616 | @param request: A CephBrokerRq object | ||
364 | 617 | @param rid: Relation ID | ||
365 | 618 | """ | ||
366 | 619 | broker_key = get_broker_rsp_key() | ||
367 | 620 | for unit in related_units(rid): | ||
368 | 621 | rdata = relation_get(rid=rid, unit=unit) | ||
369 | 622 | if rdata.get(broker_key): | ||
370 | 623 | rsp = CephBrokerRsp(rdata.get(broker_key)) | ||
371 | 624 | if rsp.request_id == request.request_id: | ||
372 | 625 | if not rsp.exit_code: | ||
373 | 626 | return True | ||
374 | 627 | else: | ||
375 | 628 | # The remote unit sent no reply targeted at this unit so either the | ||
376 | 629 | # remote ceph cluster does not support unit targeted replies or it | ||
377 | 630 | # has not processed our request yet. | ||
378 | 631 | if rdata.get('broker_rsp'): | ||
379 | 632 | request_data = json.loads(rdata['broker_rsp']) | ||
380 | 633 | if request_data.get('request-id'): | ||
381 | 634 | log('Ignoring legacy broker_rsp without unit key as remote ' | ||
382 | 635 | 'service supports unit specific replies', level=DEBUG) | ||
383 | 636 | else: | ||
384 | 637 | log('Using legacy broker_rsp as remote service does not ' | ||
385 | 638 | 'supports unit specific replies', level=DEBUG) | ||
386 | 639 | rsp = CephBrokerRsp(rdata['broker_rsp']) | ||
387 | 640 | if not rsp.exit_code: | ||
388 | 641 | return True | ||
389 | 642 | |||
390 | 643 | return False | ||
391 | 644 | |||
392 | 645 | |||
393 | 646 | def get_broker_rsp_key(): | ||
394 | 647 | """Return broker response key for this unit | ||
395 | 648 | |||
396 | 649 | This is the key that ceph is going to use to pass request status | ||
397 | 650 | information back to this unit | ||
398 | 651 | """ | ||
399 | 652 | return 'broker-rsp-' + local_unit().replace('/', '-') | ||
400 | 653 | |||
401 | 654 | |||
402 | 655 | def send_request_if_needed(request): | ||
403 | 656 | """Send broker request if an equivalent request has not already been sent | ||
404 | 657 | |||
405 | 658 | @param request: A CephBrokerRq object | ||
406 | 659 | """ | ||
407 | 660 | if is_request_sent(request): | ||
408 | 661 | log('Request already sent but not complete, not sending new request', | ||
409 | 662 | level=DEBUG) | ||
410 | 663 | else: | ||
411 | 664 | for rid in relation_ids('ceph'): | ||
412 | 665 | log('Sending request {}'.format(request.request_id), level=DEBUG) | ||
413 | 666 | relation_set(relation_id=rid, broker_req=request.request) | ||
414 | 445 | 667 | ||
415 | === modified file 'hooks/charmhelpers/contrib/storage/linux/utils.py' | |||
416 | --- hooks/charmhelpers/contrib/storage/linux/utils.py 2015-08-10 16:34:26 +0000 | |||
417 | +++ hooks/charmhelpers/contrib/storage/linux/utils.py 2015-09-23 07:31:24 +0000 | |||
418 | @@ -43,9 +43,10 @@ | |||
419 | 43 | 43 | ||
420 | 44 | :param block_device: str: Full path of block device to clean. | 44 | :param block_device: str: Full path of block device to clean. |
421 | 45 | ''' | 45 | ''' |
422 | 46 | # https://github.com/ceph/ceph/commit/fdd7f8d83afa25c4e09aaedd90ab93f3b64a677b | ||
423 | 46 | # sometimes sgdisk exits non-zero; this is OK, dd will clean up | 47 | # sometimes sgdisk exits non-zero; this is OK, dd will clean up |
426 | 47 | call(['sgdisk', '--zap-all', '--mbrtogpt', | 48 | call(['sgdisk', '--zap-all', '--', block_device]) |
427 | 48 | '--clear', block_device]) | 49 | call(['sgdisk', '--clear', '--mbrtogpt', '--', block_device]) |
428 | 49 | dev_end = check_output(['blockdev', '--getsz', | 50 | dev_end = check_output(['blockdev', '--getsz', |
429 | 50 | block_device]).decode('UTF-8') | 51 | block_device]).decode('UTF-8') |
430 | 51 | gpt_end = int(dev_end.split()[0]) - 100 | 52 | gpt_end = int(dev_end.split()[0]) - 100 |
431 | 52 | 53 | ||
432 | === modified file 'hooks/charmhelpers/core/hookenv.py' | |||
433 | --- hooks/charmhelpers/core/hookenv.py 2015-08-10 16:34:26 +0000 | |||
434 | +++ hooks/charmhelpers/core/hookenv.py 2015-09-23 07:31:24 +0000 | |||
435 | @@ -34,23 +34,6 @@ | |||
436 | 34 | import tempfile | 34 | import tempfile |
437 | 35 | from subprocess import CalledProcessError | 35 | from subprocess import CalledProcessError |
438 | 36 | 36 | ||
439 | 37 | try: | ||
440 | 38 | from charmhelpers.cli import cmdline | ||
441 | 39 | except ImportError as e: | ||
442 | 40 | # due to the anti-pattern of partially synching charmhelpers directly | ||
443 | 41 | # into charms, it's possible that charmhelpers.cli is not available; | ||
444 | 42 | # if that's the case, they don't really care about using the cli anyway, | ||
445 | 43 | # so mock it out | ||
446 | 44 | if str(e) == 'No module named cli': | ||
447 | 45 | class cmdline(object): | ||
448 | 46 | @classmethod | ||
449 | 47 | def subcommand(cls, *args, **kwargs): | ||
450 | 48 | def _wrap(func): | ||
451 | 49 | return func | ||
452 | 50 | return _wrap | ||
453 | 51 | else: | ||
454 | 52 | raise | ||
455 | 53 | |||
456 | 54 | import six | 37 | import six |
457 | 55 | if not six.PY3: | 38 | if not six.PY3: |
458 | 56 | from UserDict import UserDict | 39 | from UserDict import UserDict |
459 | @@ -91,6 +74,7 @@ | |||
460 | 91 | res = func(*args, **kwargs) | 74 | res = func(*args, **kwargs) |
461 | 92 | cache[key] = res | 75 | cache[key] = res |
462 | 93 | return res | 76 | return res |
463 | 77 | wrapper._wrapped = func | ||
464 | 94 | return wrapper | 78 | return wrapper |
465 | 95 | 79 | ||
466 | 96 | 80 | ||
467 | @@ -190,7 +174,6 @@ | |||
468 | 190 | return os.environ.get('JUJU_RELATION', None) | 174 | return os.environ.get('JUJU_RELATION', None) |
469 | 191 | 175 | ||
470 | 192 | 176 | ||
471 | 193 | @cmdline.subcommand() | ||
472 | 194 | @cached | 177 | @cached |
473 | 195 | def relation_id(relation_name=None, service_or_unit=None): | 178 | def relation_id(relation_name=None, service_or_unit=None): |
474 | 196 | """The relation ID for the current or a specified relation""" | 179 | """The relation ID for the current or a specified relation""" |
475 | @@ -216,13 +199,11 @@ | |||
476 | 216 | return os.environ.get('JUJU_REMOTE_UNIT', None) | 199 | return os.environ.get('JUJU_REMOTE_UNIT', None) |
477 | 217 | 200 | ||
478 | 218 | 201 | ||
479 | 219 | @cmdline.subcommand() | ||
480 | 220 | def service_name(): | 202 | def service_name(): |
481 | 221 | """The name service group this unit belongs to""" | 203 | """The name service group this unit belongs to""" |
482 | 222 | return local_unit().split('/')[0] | 204 | return local_unit().split('/')[0] |
483 | 223 | 205 | ||
484 | 224 | 206 | ||
485 | 225 | @cmdline.subcommand() | ||
486 | 226 | @cached | 207 | @cached |
487 | 227 | def remote_service_name(relid=None): | 208 | def remote_service_name(relid=None): |
488 | 228 | """The remote service name for a given relation-id (or the current relation)""" | 209 | """The remote service name for a given relation-id (or the current relation)""" |
489 | 229 | 210 | ||
490 | === modified file 'hooks/charmhelpers/core/host.py' | |||
491 | --- hooks/charmhelpers/core/host.py 2015-08-10 16:34:26 +0000 | |||
492 | +++ hooks/charmhelpers/core/host.py 2015-09-23 07:31:24 +0000 | |||
493 | @@ -72,7 +72,7 @@ | |||
494 | 72 | stopped = service_stop(service_name) | 72 | stopped = service_stop(service_name) |
495 | 73 | # XXX: Support systemd too | 73 | # XXX: Support systemd too |
496 | 74 | override_path = os.path.join( | 74 | override_path = os.path.join( |
498 | 75 | init_dir, '{}.conf.override'.format(service_name)) | 75 | init_dir, '{}.override'.format(service_name)) |
499 | 76 | with open(override_path, 'w') as fh: | 76 | with open(override_path, 'w') as fh: |
500 | 77 | fh.write("manual\n") | 77 | fh.write("manual\n") |
501 | 78 | return stopped | 78 | return stopped |
502 | @@ -86,7 +86,7 @@ | |||
503 | 86 | if init_dir is None: | 86 | if init_dir is None: |
504 | 87 | init_dir = "/etc/init" | 87 | init_dir = "/etc/init" |
505 | 88 | override_path = os.path.join( | 88 | override_path = os.path.join( |
507 | 89 | init_dir, '{}.conf.override'.format(service_name)) | 89 | init_dir, '{}.override'.format(service_name)) |
508 | 90 | if os.path.exists(override_path): | 90 | if os.path.exists(override_path): |
509 | 91 | os.unlink(override_path) | 91 | os.unlink(override_path) |
510 | 92 | started = service_start(service_name) | 92 | started = service_start(service_name) |
511 | 93 | 93 | ||
512 | === modified file 'hooks/cinder_hooks.py' | |||
513 | --- hooks/cinder_hooks.py 2015-09-16 12:55:55 +0000 | |||
514 | +++ hooks/cinder_hooks.py 2015-09-23 07:31:24 +0000 | |||
515 | @@ -17,12 +17,9 @@ | |||
516 | 17 | UnregisteredHookError, | 17 | UnregisteredHookError, |
517 | 18 | config, | 18 | config, |
518 | 19 | service_name, | 19 | service_name, |
519 | 20 | relation_get, | ||
520 | 21 | relation_set, | 20 | relation_set, |
521 | 22 | relation_ids, | 21 | relation_ids, |
522 | 23 | log, | 22 | log, |
523 | 24 | INFO, | ||
524 | 25 | ERROR, | ||
525 | 26 | ) | 23 | ) |
526 | 27 | from charmhelpers.fetch import apt_install, apt_update | 24 | from charmhelpers.fetch import apt_install, apt_update |
527 | 28 | from charmhelpers.core.host import ( | 25 | from charmhelpers.core.host import ( |
528 | @@ -30,9 +27,10 @@ | |||
529 | 30 | service_restart, | 27 | service_restart, |
530 | 31 | ) | 28 | ) |
531 | 32 | from charmhelpers.contrib.storage.linux.ceph import ( | 29 | from charmhelpers.contrib.storage.linux.ceph import ( |
532 | 30 | send_request_if_needed, | ||
533 | 31 | is_request_complete, | ||
534 | 33 | ensure_ceph_keyring, | 32 | ensure_ceph_keyring, |
535 | 34 | CephBrokerRq, | 33 | CephBrokerRq, |
536 | 35 | CephBrokerRsp, | ||
537 | 36 | delete_keyring, | 34 | delete_keyring, |
538 | 37 | ) | 35 | ) |
539 | 38 | from charmhelpers.payload.execd import execd_preinstall | 36 | from charmhelpers.payload.execd import execd_preinstall |
540 | @@ -55,6 +53,14 @@ | |||
541 | 55 | os.mkdir('/etc/ceph') | 53 | os.mkdir('/etc/ceph') |
542 | 56 | 54 | ||
543 | 57 | 55 | ||
544 | 56 | def get_ceph_request(): | ||
545 | 57 | service = service_name() | ||
546 | 58 | rq = CephBrokerRq() | ||
547 | 59 | replicas = config('ceph-osd-replication-count') | ||
548 | 60 | rq.add_op_create_pool(name=service, replica_count=replicas) | ||
549 | 61 | return rq | ||
550 | 62 | |||
551 | 63 | |||
552 | 58 | @hooks.hook('ceph-relation-changed') | 64 | @hooks.hook('ceph-relation-changed') |
553 | 59 | @restart_on_change(restart_map()) | 65 | @restart_on_change(restart_map()) |
554 | 60 | def ceph_changed(): | 66 | def ceph_changed(): |
555 | @@ -68,32 +74,17 @@ | |||
556 | 68 | log('Could not create ceph keyring: peer not ready?') | 74 | log('Could not create ceph keyring: peer not ready?') |
557 | 69 | return | 75 | return |
558 | 70 | 76 | ||
570 | 71 | settings = relation_get() | 77 | if is_request_complete(get_ceph_request()): |
571 | 72 | if settings and 'broker_rsp' in settings: | 78 | log('Request complete') |
561 | 73 | rsp = CephBrokerRsp(settings['broker_rsp']) | ||
562 | 74 | # Non-zero return code implies failure | ||
563 | 75 | if rsp.exit_code: | ||
564 | 76 | log("Ceph broker request failed (rc=%s, msg=%s)" % | ||
565 | 77 | (rsp.exit_code, rsp.exit_msg), level=ERROR) | ||
566 | 78 | return | ||
567 | 79 | |||
568 | 80 | log("Ceph broker request succeeded (rc=%s, msg=%s)" % | ||
569 | 81 | (rsp.exit_code, rsp.exit_msg), level=INFO) | ||
572 | 82 | CONFIGS.write_all() | 79 | CONFIGS.write_all() |
573 | 83 | set_ceph_env_variables(service=service) | 80 | set_ceph_env_variables(service=service) |
574 | 84 | for rid in relation_ids('storage-backend'): | 81 | for rid in relation_ids('storage-backend'): |
575 | 85 | storage_backend(rid) | 82 | storage_backend(rid) |
576 | 86 | |||
577 | 87 | # Ensure that cinder-volume is restarted since only now can we | 83 | # Ensure that cinder-volume is restarted since only now can we |
578 | 88 | # guarantee that ceph resources are ready. | 84 | # guarantee that ceph resources are ready. |
579 | 89 | service_restart('cinder-volume') | 85 | service_restart('cinder-volume') |
580 | 90 | else: | 86 | else: |
587 | 91 | rq = CephBrokerRq() | 87 | send_request_if_needed(get_ceph_request()) |
582 | 92 | replicas = config('ceph-osd-replication-count') | ||
583 | 93 | rq.add_op_create_pool(name=service, replica_count=replicas) | ||
584 | 94 | for rid in relation_ids('ceph'): | ||
585 | 95 | relation_set(relation_id=rid, broker_req=rq.request) | ||
586 | 96 | log("Request(s) sent to Ceph broker (rid=%s)" % (rid)) | ||
588 | 97 | 88 | ||
589 | 98 | 89 | ||
590 | 99 | @hooks.hook('ceph-relation-broken') | 90 | @hooks.hook('ceph-relation-broken') |
591 | 100 | 91 | ||
592 | === modified file 'tests/basic_deployment.py' | |||
593 | --- tests/basic_deployment.py 2015-08-10 17:28:35 +0000 | |||
594 | +++ tests/basic_deployment.py 2015-09-23 07:31:24 +0000 | |||
595 | @@ -4,6 +4,7 @@ | |||
596 | 4 | Basic cinder-ceph functional test. | 4 | Basic cinder-ceph functional test. |
597 | 5 | """ | 5 | """ |
598 | 6 | import amulet | 6 | import amulet |
599 | 7 | import json | ||
600 | 7 | import time | 8 | import time |
601 | 8 | 9 | ||
602 | 9 | from charmhelpers.contrib.openstack.amulet.deployment import ( | 10 | from charmhelpers.contrib.openstack.amulet.deployment import ( |
603 | @@ -279,40 +280,83 @@ | |||
604 | 279 | amulet.raise_status(amulet.FAIL, | 280 | amulet.raise_status(amulet.FAIL, |
605 | 280 | msg='cinder endpoint: {}'.format(ret)) | 281 | msg='cinder endpoint: {}'.format(ret)) |
606 | 281 | 282 | ||
607 | 283 | def validate_broker_req(self, unit, relation, expected): | ||
608 | 284 | rel_data = json.loads(unit.relation( | ||
609 | 285 | relation[0], | ||
610 | 286 | relation[1])['broker_req']) | ||
611 | 287 | if rel_data['api-version'] != expected['api-version']: | ||
612 | 288 | return "Broker request api mismatch" | ||
613 | 289 | for index in range(0, len(rel_data['ops'])): | ||
614 | 290 | actual_op = rel_data['ops'][index] | ||
615 | 291 | expected_op = expected['ops'][index] | ||
616 | 292 | for key in ['op', 'name', 'replicas']: | ||
617 | 293 | if actual_op[key] == expected_op[key]: | ||
618 | 294 | u.log.debug("OK op {} key {}".format(index, key)) | ||
619 | 295 | else: | ||
620 | 296 | return "Mismatch, op: {} key: {}".format(index, key) | ||
621 | 297 | return None | ||
622 | 298 | |||
623 | 299 | def get_broker_request(self): | ||
624 | 300 | client_unit = self.cinder_ceph_sentry | ||
625 | 301 | broker_req = json.loads(client_unit.relation( | ||
626 | 302 | 'ceph', | ||
627 | 303 | 'ceph:client')['broker_req']) | ||
628 | 304 | return broker_req | ||
629 | 305 | |||
630 | 306 | def get_broker_response(self): | ||
631 | 307 | broker_request = self.get_broker_request() | ||
632 | 308 | response_key = "broker-rsp-cinder-ceph-0" | ||
633 | 309 | ceph_sentrys = [self.ceph0_sentry, self.ceph1_sentry, self.ceph2_sentry] | ||
634 | 310 | for sentry in ceph_sentrys: | ||
635 | 311 | relation_data = sentry.relation('client', 'cinder-ceph:ceph') | ||
636 | 312 | if relation_data.get(response_key): | ||
637 | 313 | broker_response = json.loads(relation_data[response_key]) | ||
638 | 314 | if broker_request['request-id'] == broker_response['request-id']: | ||
639 | 315 | return broker_response | ||
640 | 316 | |||
641 | 282 | def test_200_cinderceph_ceph_ceph_relation(self): | 317 | def test_200_cinderceph_ceph_ceph_relation(self): |
642 | 283 | u.log.debug('Checking cinder-ceph:ceph to ceph:client ' | 318 | u.log.debug('Checking cinder-ceph:ceph to ceph:client ' |
643 | 284 | 'relation data...') | 319 | 'relation data...') |
644 | 285 | unit = self.cinder_ceph_sentry | 320 | unit = self.cinder_ceph_sentry |
645 | 286 | relation = ['ceph', 'ceph:client'] | 321 | relation = ['ceph', 'ceph:client'] |
646 | 287 | 322 | ||
650 | 288 | req = ('{"api-version": 1, "ops": [{"replicas": 3, "name": ' | 323 | req = { |
651 | 289 | '"cinder-ceph", "op": "create-pool"}]}') | 324 | "api-version": 1, |
652 | 290 | 325 | "ops": [{"replicas": 3, "name": "cinder-ceph", "op": "create-pool"}] | |
653 | 326 | } | ||
654 | 291 | expected = { | 327 | expected = { |
655 | 292 | 'private-address': u.valid_ip, | 328 | 'private-address': u.valid_ip, |
657 | 293 | 'broker_req': req | 329 | 'broker_req': u.not_null, |
658 | 294 | } | 330 | } |
659 | 295 | ret = u.validate_relation_data(unit, relation, expected) | 331 | ret = u.validate_relation_data(unit, relation, expected) |
660 | 296 | if ret: | 332 | if ret: |
661 | 297 | msg = u.relation_error('cinder-ceph ceph', ret) | 333 | msg = u.relation_error('cinder-ceph ceph', ret) |
662 | 298 | amulet.raise_status(amulet.FAIL, msg=msg) | 334 | amulet.raise_status(amulet.FAIL, msg=msg) |
663 | 335 | ret = self.validate_broker_req(unit, relation, req) | ||
664 | 336 | if ret: | ||
665 | 337 | msg = u.relation_error('cinder-ceph ceph', ret) | ||
666 | 338 | amulet.raise_status(amulet.FAIL, msg=msg) | ||
667 | 299 | 339 | ||
668 | 300 | def test_201_ceph_cinderceph_ceph_relation(self): | 340 | def test_201_ceph_cinderceph_ceph_relation(self): |
669 | 301 | u.log.debug('Checking ceph:client to cinder-ceph:ceph ' | 341 | u.log.debug('Checking ceph:client to cinder-ceph:ceph ' |
670 | 302 | 'relation data...') | 342 | 'relation data...') |
672 | 303 | unit = self.ceph0_sentry | 343 | response_key = "broker-rsp-cinder-ceph-0" |
673 | 344 | ceph_unit = self.ceph0_sentry | ||
674 | 304 | relation = ['client', 'cinder-ceph:ceph'] | 345 | relation = ['client', 'cinder-ceph:ceph'] |
675 | 305 | expected = { | 346 | expected = { |
676 | 306 | 'key': u.not_null, | 347 | 'key': u.not_null, |
677 | 307 | 'private-address': u.valid_ip, | 348 | 'private-address': u.valid_ip, |
678 | 308 | 'broker_rsp': '{"exit-code": 0}', | ||
679 | 309 | 'ceph-public-address': u.valid_ip, | 349 | 'ceph-public-address': u.valid_ip, |
681 | 310 | 'auth': 'none' | 350 | 'auth': 'none', |
682 | 311 | } | 351 | } |
684 | 312 | ret = u.validate_relation_data(unit, relation, expected) | 352 | ret = u.validate_relation_data(ceph_unit, relation, expected) |
685 | 313 | if ret: | 353 | if ret: |
686 | 314 | msg = u.relation_error('cinder cinder-ceph storage-backend', ret) | 354 | msg = u.relation_error('cinder cinder-ceph storage-backend', ret) |
687 | 315 | amulet.raise_status(amulet.FAIL, msg=msg) | 355 | amulet.raise_status(amulet.FAIL, msg=msg) |
688 | 356 | broker_response = self.get_broker_response() | ||
689 | 357 | if not broker_response or broker_response['exit-code'] != 0: | ||
690 | 358 | msg='Broker request invalid or failed: {}'.format(broker_response) | ||
691 | 359 | amulet.raise_status(amulet.FAIL, msg=msg) | ||
692 | 316 | 360 | ||
693 | 317 | def test_202_cinderceph_cinder_backend_relation(self): | 361 | def test_202_cinderceph_cinder_backend_relation(self): |
694 | 318 | u.log.debug('Checking cinder-ceph:storage-backend to ' | 362 | u.log.debug('Checking cinder-ceph:storage-backend to ' |
695 | 319 | 363 | ||
696 | === modified file 'unit_tests/test_cinder_hooks.py' | |||
697 | --- unit_tests/test_cinder_hooks.py 2015-09-16 12:55:55 +0000 | |||
698 | +++ unit_tests/test_cinder_hooks.py 2015-09-23 07:31:24 +0000 | |||
699 | @@ -18,11 +18,12 @@ | |||
700 | 18 | 'register_configs', | 18 | 'register_configs', |
701 | 19 | 'restart_map', | 19 | 'restart_map', |
702 | 20 | 'set_ceph_env_variables', | 20 | 'set_ceph_env_variables', |
703 | 21 | 'is_request_complete', | ||
704 | 22 | 'send_request_if_needed', | ||
705 | 21 | 'CONFIGS', | 23 | 'CONFIGS', |
706 | 22 | # charmhelpers.core.hookenv | 24 | # charmhelpers.core.hookenv |
707 | 23 | 'config', | 25 | 'config', |
708 | 24 | 'relation_ids', | 26 | 'relation_ids', |
709 | 25 | 'relation_get', | ||
710 | 26 | 'relation_set', | 27 | 'relation_set', |
711 | 27 | 'service_name', | 28 | 'service_name', |
712 | 28 | 'service_restart', | 29 | 'service_restart', |
713 | @@ -69,9 +70,8 @@ | |||
714 | 69 | @patch('charmhelpers.core.hookenv.config') | 70 | @patch('charmhelpers.core.hookenv.config') |
715 | 70 | def test_ceph_changed(self, mock_config): | 71 | def test_ceph_changed(self, mock_config): |
716 | 71 | '''It ensures ceph assets created on ceph changed''' | 72 | '''It ensures ceph assets created on ceph changed''' |
717 | 73 | self.is_request_complete.return_value = True | ||
718 | 72 | self.CONFIGS.complete_contexts.return_value = ['ceph'] | 74 | self.CONFIGS.complete_contexts.return_value = ['ceph'] |
719 | 73 | rsp = json.dumps({'exit_code': 0}) | ||
720 | 74 | self.relation_get.return_value = {'broker_rsp': rsp} | ||
721 | 75 | self.service_name.return_value = 'cinder' | 75 | self.service_name.return_value = 'cinder' |
722 | 76 | self.ensure_ceph_keyring.return_value = True | 76 | self.ensure_ceph_keyring.return_value = True |
723 | 77 | hooks.hooks.execute(['hooks/ceph-relation-changed']) | 77 | hooks.hooks.execute(['hooks/ceph-relation-changed']) |
724 | @@ -81,11 +81,27 @@ | |||
725 | 81 | self.assertTrue(self.CONFIGS.write_all.called) | 81 | self.assertTrue(self.CONFIGS.write_all.called) |
726 | 82 | self.set_ceph_env_variables.assert_called_with(service='cinder') | 82 | self.set_ceph_env_variables.assert_called_with(service='cinder') |
727 | 83 | 83 | ||
728 | 84 | @patch.object(hooks, 'get_ceph_request') | ||
729 | 85 | @patch('charmhelpers.core.hookenv.config') | ||
730 | 86 | def test_ceph_changed_newrq(self, mock_config, mock_get_ceph_request): | ||
731 | 87 | '''It ensures ceph assets created on ceph changed''' | ||
732 | 88 | mock_get_ceph_request.return_value = 'cephreq' | ||
733 | 89 | self.is_request_complete.return_value = False | ||
734 | 90 | self.CONFIGS.complete_contexts.return_value = ['ceph'] | ||
735 | 91 | self.service_name.return_value = 'cinder' | ||
736 | 92 | self.ensure_ceph_keyring.return_value = True | ||
737 | 93 | hooks.hooks.execute(['hooks/ceph-relation-changed']) | ||
738 | 94 | self.ensure_ceph_keyring.assert_called_with(service='cinder', | ||
739 | 95 | user='cinder', | ||
740 | 96 | group='cinder') | ||
741 | 97 | self.send_request_if_needed.assert_called_with('cephreq') | ||
742 | 98 | |||
743 | 84 | @patch('charmhelpers.core.hookenv.config') | 99 | @patch('charmhelpers.core.hookenv.config') |
744 | 85 | def test_ceph_changed_no_keys(self, mock_config): | 100 | def test_ceph_changed_no_keys(self, mock_config): |
745 | 86 | '''It ensures ceph assets created on ceph changed''' | 101 | '''It ensures ceph assets created on ceph changed''' |
746 | 87 | self.CONFIGS.complete_contexts.return_value = ['ceph'] | 102 | self.CONFIGS.complete_contexts.return_value = ['ceph'] |
747 | 88 | self.service_name.return_value = 'cinder' | 103 | self.service_name.return_value = 'cinder' |
748 | 104 | self.is_request_complete.return_value = True | ||
749 | 89 | self.ensure_ceph_keyring.return_value = False | 105 | self.ensure_ceph_keyring.return_value = False |
750 | 90 | hooks.hooks.execute(['hooks/ceph-relation-changed']) | 106 | hooks.hooks.execute(['hooks/ceph-relation-changed']) |
751 | 91 | # NOTE(jamespage): If ensure_ceph keyring fails, then | 107 | # NOTE(jamespage): If ensure_ceph keyring fails, then |
charm_unit_test #9552 cinder-ceph for gnuoy mp271261
UNIT OK: passed
Build: http:// 10.245. 162.77: 8080/job/ charm_unit_ test/9552/