Merge lp:~gnuoy/charms/trusty/ceph/1453940-stable into lp:~openstack-charmers-archive/charms/trusty/ceph/trunk
- Trusty Tahr (14.04)
- 1453940-stable
- Merge into trunk
Proposed by
Liam Young
Status: | Merged |
---|---|
Merged at revision: | 110 |
Proposed branch: | lp:~gnuoy/charms/trusty/ceph/1453940-stable |
Merge into: | lp:~openstack-charmers-archive/charms/trusty/ceph/trunk |
Diff against target: |
487 lines (+278/-38) 8 files modified
hooks/ceph_broker.py (+12/-2) hooks/charmhelpers/cli/__init__.py (+1/-5) hooks/charmhelpers/cli/commands.py (+4/-4) hooks/charmhelpers/cli/hookenv.py (+23/-0) hooks/charmhelpers/contrib/storage/linux/ceph.py (+224/-2) hooks/charmhelpers/core/hookenv.py (+1/-20) hooks/charmhelpers/core/host.py (+2/-2) hooks/hooks.py (+11/-3) |
To merge this branch: | bzr merge lp:~gnuoy/charms/trusty/ceph/1453940-stable |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Chris Glass (community) | Approve | ||
Review via email: mp+271260@code.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote : | # |
Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_unit_test #9558 ceph for gnuoy mp271260
UNIT OK: passed
Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_amulet_test #6552 ceph for gnuoy mp271260
AMULET OK: passed
Build: http://
Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_lint_check #10438 ceph for gnuoy mp271260
LINT OK: passed
Build: http://
Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_unit_test #9630 ceph for gnuoy mp271260
UNIT OK: passed
Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_amulet_test #6579 ceph for gnuoy mp271260
AMULET OK: passed
Build: http://
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'hooks/ceph_broker.py' | |||
2 | --- hooks/ceph_broker.py 2014-11-19 21:33:12 +0000 | |||
3 | +++ hooks/ceph_broker.py 2015-09-16 09:02:26 +0000 | |||
4 | @@ -31,10 +31,16 @@ | |||
5 | 31 | This is a versioned api. API version must be supplied by the client making | 31 | This is a versioned api. API version must be supplied by the client making |
6 | 32 | the request. | 32 | the request. |
7 | 33 | """ | 33 | """ |
8 | 34 | request_id = reqs.get('request-id') | ||
9 | 34 | try: | 35 | try: |
10 | 35 | version = reqs.get('api-version') | 36 | version = reqs.get('api-version') |
11 | 36 | if version == 1: | 37 | if version == 1: |
13 | 37 | return process_requests_v1(reqs['ops']) | 38 | log('Processing request {}'.format(request_id), level=DEBUG) |
14 | 39 | resp = process_requests_v1(reqs['ops']) | ||
15 | 40 | if request_id: | ||
16 | 41 | resp['request-id'] = request_id | ||
17 | 42 | |||
18 | 43 | return resp | ||
19 | 38 | 44 | ||
20 | 39 | except Exception as exc: | 45 | except Exception as exc: |
21 | 40 | log(str(exc), level=ERROR) | 46 | log(str(exc), level=ERROR) |
22 | @@ -44,7 +50,11 @@ | |||
23 | 44 | return {'exit-code': 1, 'stderr': msg} | 50 | return {'exit-code': 1, 'stderr': msg} |
24 | 45 | 51 | ||
25 | 46 | msg = ("Missing or invalid api version (%s)" % (version)) | 52 | msg = ("Missing or invalid api version (%s)" % (version)) |
27 | 47 | return {'exit-code': 1, 'stderr': msg} | 53 | resp = {'exit-code': 1, 'stderr': msg} |
28 | 54 | if request_id: | ||
29 | 55 | resp['request-id'] = request_id | ||
30 | 56 | |||
31 | 57 | return resp | ||
32 | 48 | 58 | ||
33 | 49 | 59 | ||
34 | 50 | def process_requests_v1(reqs): | 60 | def process_requests_v1(reqs): |
35 | 51 | 61 | ||
36 | === modified file 'hooks/charmhelpers/cli/__init__.py' | |||
37 | --- hooks/charmhelpers/cli/__init__.py 2015-08-10 16:32:52 +0000 | |||
38 | +++ hooks/charmhelpers/cli/__init__.py 2015-09-16 09:02:26 +0000 | |||
39 | @@ -152,15 +152,11 @@ | |||
40 | 152 | arguments = self.argument_parser.parse_args() | 152 | arguments = self.argument_parser.parse_args() |
41 | 153 | argspec = inspect.getargspec(arguments.func) | 153 | argspec = inspect.getargspec(arguments.func) |
42 | 154 | vargs = [] | 154 | vargs = [] |
43 | 155 | kwargs = {} | ||
44 | 156 | for arg in argspec.args: | 155 | for arg in argspec.args: |
45 | 157 | vargs.append(getattr(arguments, arg)) | 156 | vargs.append(getattr(arguments, arg)) |
46 | 158 | if argspec.varargs: | 157 | if argspec.varargs: |
47 | 159 | vargs.extend(getattr(arguments, argspec.varargs)) | 158 | vargs.extend(getattr(arguments, argspec.varargs)) |
52 | 160 | if argspec.keywords: | 159 | output = arguments.func(*vargs) |
49 | 161 | for kwarg in argspec.keywords.items(): | ||
50 | 162 | kwargs[kwarg] = getattr(arguments, kwarg) | ||
51 | 163 | output = arguments.func(*vargs, **kwargs) | ||
53 | 164 | if getattr(arguments.func, '_cli_test_command', False): | 160 | if getattr(arguments.func, '_cli_test_command', False): |
54 | 165 | self.exit_code = 0 if output else 1 | 161 | self.exit_code = 0 if output else 1 |
55 | 166 | output = '' | 162 | output = '' |
56 | 167 | 163 | ||
57 | === modified file 'hooks/charmhelpers/cli/commands.py' | |||
58 | --- hooks/charmhelpers/cli/commands.py 2015-08-10 16:32:52 +0000 | |||
59 | +++ hooks/charmhelpers/cli/commands.py 2015-09-16 09:02:26 +0000 | |||
60 | @@ -26,7 +26,7 @@ | |||
61 | 26 | """ | 26 | """ |
62 | 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. |
63 | 28 | """ | 28 | """ |
68 | 29 | import host # noqa | 29 | from . import host # noqa |
69 | 30 | import benchmark # noqa | 30 | from . import benchmark # noqa |
70 | 31 | import unitdata # noqa | 31 | from . import unitdata # noqa |
71 | 32 | from charmhelpers.core import hookenv # noqa | 32 | from . import hookenv # noqa |
72 | 33 | 33 | ||
73 | === added file 'hooks/charmhelpers/cli/hookenv.py' | |||
74 | --- hooks/charmhelpers/cli/hookenv.py 1970-01-01 00:00:00 +0000 | |||
75 | +++ hooks/charmhelpers/cli/hookenv.py 2015-09-16 09:02:26 +0000 | |||
76 | @@ -0,0 +1,23 @@ | |||
77 | 1 | # Copyright 2014-2015 Canonical Limited. | ||
78 | 2 | # | ||
79 | 3 | # This file is part of charm-helpers. | ||
80 | 4 | # | ||
81 | 5 | # charm-helpers is free software: you can redistribute it and/or modify | ||
82 | 6 | # it under the terms of the GNU Lesser General Public License version 3 as | ||
83 | 7 | # published by the Free Software Foundation. | ||
84 | 8 | # | ||
85 | 9 | # charm-helpers is distributed in the hope that it will be useful, | ||
86 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
87 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
88 | 12 | # GNU Lesser General Public License for more details. | ||
89 | 13 | # | ||
90 | 14 | # You should have received a copy of the GNU Lesser General Public License | ||
91 | 15 | # along with charm-helpers. If not, see <http://www.gnu.org/licenses/>. | ||
92 | 16 | |||
93 | 17 | from . import cmdline | ||
94 | 18 | from charmhelpers.core import hookenv | ||
95 | 19 | |||
96 | 20 | |||
97 | 21 | cmdline.subcommand('relation-id')(hookenv.relation_id._wrapped) | ||
98 | 22 | cmdline.subcommand('service-name')(hookenv.service_name) | ||
99 | 23 | cmdline.subcommand('remote-service-name')(hookenv.remote_service_name._wrapped) | ||
100 | 0 | 24 | ||
101 | === modified file 'hooks/charmhelpers/contrib/storage/linux/ceph.py' | |||
102 | --- hooks/charmhelpers/contrib/storage/linux/ceph.py 2015-08-10 16:32:52 +0000 | |||
103 | +++ hooks/charmhelpers/contrib/storage/linux/ceph.py 2015-09-16 09:02:26 +0000 | |||
104 | @@ -28,6 +28,7 @@ | |||
105 | 28 | import shutil | 28 | import shutil |
106 | 29 | import json | 29 | import json |
107 | 30 | import time | 30 | import time |
108 | 31 | import uuid | ||
109 | 31 | 32 | ||
110 | 32 | from subprocess import ( | 33 | from subprocess import ( |
111 | 33 | check_call, | 34 | check_call, |
112 | @@ -35,8 +36,10 @@ | |||
113 | 35 | CalledProcessError, | 36 | CalledProcessError, |
114 | 36 | ) | 37 | ) |
115 | 37 | from charmhelpers.core.hookenv import ( | 38 | from charmhelpers.core.hookenv import ( |
116 | 39 | local_unit, | ||
117 | 38 | relation_get, | 40 | relation_get, |
118 | 39 | relation_ids, | 41 | relation_ids, |
119 | 42 | relation_set, | ||
120 | 40 | related_units, | 43 | related_units, |
121 | 41 | log, | 44 | log, |
122 | 42 | DEBUG, | 45 | DEBUG, |
123 | @@ -411,17 +414,52 @@ | |||
124 | 411 | 414 | ||
125 | 412 | The API is versioned and defaults to version 1. | 415 | The API is versioned and defaults to version 1. |
126 | 413 | """ | 416 | """ |
128 | 414 | def __init__(self, api_version=1): | 417 | def __init__(self, api_version=1, request_id=None): |
129 | 415 | self.api_version = api_version | 418 | self.api_version = api_version |
130 | 419 | if request_id: | ||
131 | 420 | self.request_id = request_id | ||
132 | 421 | else: | ||
133 | 422 | self.request_id = str(uuid.uuid1()) | ||
134 | 416 | self.ops = [] | 423 | self.ops = [] |
135 | 417 | 424 | ||
136 | 418 | def add_op_create_pool(self, name, replica_count=3): | 425 | def add_op_create_pool(self, name, replica_count=3): |
137 | 419 | self.ops.append({'op': 'create-pool', 'name': name, | 426 | self.ops.append({'op': 'create-pool', 'name': name, |
138 | 420 | 'replicas': replica_count}) | 427 | 'replicas': replica_count}) |
139 | 421 | 428 | ||
140 | 429 | def set_ops(self, ops): | ||
141 | 430 | """Set request ops to provided value. | ||
142 | 431 | |||
143 | 432 | Useful for injecting ops that come from a previous request | ||
144 | 433 | to allow comparisons to ensure validity. | ||
145 | 434 | """ | ||
146 | 435 | self.ops = ops | ||
147 | 436 | |||
148 | 422 | @property | 437 | @property |
149 | 423 | def request(self): | 438 | def request(self): |
151 | 424 | return json.dumps({'api-version': self.api_version, 'ops': self.ops}) | 439 | return json.dumps({'api-version': self.api_version, 'ops': self.ops, |
152 | 440 | 'request-id': self.request_id}) | ||
153 | 441 | |||
154 | 442 | def _ops_equal(self, other): | ||
155 | 443 | if len(self.ops) == len(other.ops): | ||
156 | 444 | for req_no in range(0, len(self.ops)): | ||
157 | 445 | for key in ['replicas', 'name', 'op']: | ||
158 | 446 | if self.ops[req_no][key] != other.ops[req_no][key]: | ||
159 | 447 | return False | ||
160 | 448 | else: | ||
161 | 449 | return False | ||
162 | 450 | return True | ||
163 | 451 | |||
164 | 452 | def __eq__(self, other): | ||
165 | 453 | if not isinstance(other, self.__class__): | ||
166 | 454 | return False | ||
167 | 455 | if self.api_version == other.api_version and \ | ||
168 | 456 | self._ops_equal(other): | ||
169 | 457 | return True | ||
170 | 458 | else: | ||
171 | 459 | return False | ||
172 | 460 | |||
173 | 461 | def __ne__(self, other): | ||
174 | 462 | return not self.__eq__(other) | ||
175 | 425 | 463 | ||
176 | 426 | 464 | ||
177 | 427 | class CephBrokerRsp(object): | 465 | class CephBrokerRsp(object): |
178 | @@ -431,14 +469,198 @@ | |||
179 | 431 | 469 | ||
180 | 432 | The API is versioned and defaults to version 1. | 470 | The API is versioned and defaults to version 1. |
181 | 433 | """ | 471 | """ |
182 | 472 | |||
183 | 434 | def __init__(self, encoded_rsp): | 473 | def __init__(self, encoded_rsp): |
184 | 435 | self.api_version = None | 474 | self.api_version = None |
185 | 436 | self.rsp = json.loads(encoded_rsp) | 475 | self.rsp = json.loads(encoded_rsp) |
186 | 437 | 476 | ||
187 | 438 | @property | 477 | @property |
188 | 478 | def request_id(self): | ||
189 | 479 | return self.rsp.get('request-id') | ||
190 | 480 | |||
191 | 481 | @property | ||
192 | 439 | def exit_code(self): | 482 | def exit_code(self): |
193 | 440 | return self.rsp.get('exit-code') | 483 | return self.rsp.get('exit-code') |
194 | 441 | 484 | ||
195 | 442 | @property | 485 | @property |
196 | 443 | def exit_msg(self): | 486 | def exit_msg(self): |
197 | 444 | return self.rsp.get('stderr') | 487 | return self.rsp.get('stderr') |
198 | 488 | |||
199 | 489 | |||
200 | 490 | # Ceph Broker Conversation: | ||
201 | 491 | # If a charm needs an action to be taken by ceph it can create a CephBrokerRq | ||
202 | 492 | # and send that request to ceph via the ceph relation. The CephBrokerRq has a | ||
203 | 493 | # unique id so that the client can identity which CephBrokerRsp is associated | ||
204 | 494 | # with the request. Ceph will also respond to each client unit individually | ||
205 | 495 | # creating a response key per client unit eg glance/0 will get a CephBrokerRsp | ||
206 | 496 | # via key broker-rsp-glance-0 | ||
207 | 497 | # | ||
208 | 498 | # To use this the charm can just do something like: | ||
209 | 499 | # | ||
210 | 500 | # from charmhelpers.contrib.storage.linux.ceph import ( | ||
211 | 501 | # send_request_if_needed, | ||
212 | 502 | # is_request_complete, | ||
213 | 503 | # CephBrokerRq, | ||
214 | 504 | # ) | ||
215 | 505 | # | ||
216 | 506 | # @hooks.hook('ceph-relation-changed') | ||
217 | 507 | # def ceph_changed(): | ||
218 | 508 | # rq = CephBrokerRq() | ||
219 | 509 | # rq.add_op_create_pool(name='poolname', replica_count=3) | ||
220 | 510 | # | ||
221 | 511 | # if is_request_complete(rq): | ||
222 | 512 | # <Request complete actions> | ||
223 | 513 | # else: | ||
224 | 514 | # send_request_if_needed(get_ceph_request()) | ||
225 | 515 | # | ||
226 | 516 | # CephBrokerRq and CephBrokerRsp are serialized into JSON. Below is an example | ||
227 | 517 | # of glance having sent a request to ceph which ceph has successfully processed | ||
228 | 518 | # 'ceph:8': { | ||
229 | 519 | # 'ceph/0': { | ||
230 | 520 | # 'auth': 'cephx', | ||
231 | 521 | # 'broker-rsp-glance-0': '{"request-id": "0bc7dc54", "exit-code": 0}', | ||
232 | 522 | # 'broker_rsp': '{"request-id": "0da543b8", "exit-code": 0}', | ||
233 | 523 | # 'ceph-public-address': '10.5.44.103', | ||
234 | 524 | # 'key': 'AQCLDttVuHXINhAAvI144CB09dYchhHyTUY9BQ==', | ||
235 | 525 | # 'private-address': '10.5.44.103', | ||
236 | 526 | # }, | ||
237 | 527 | # 'glance/0': { | ||
238 | 528 | # 'broker_req': ('{"api-version": 1, "request-id": "0bc7dc54", ' | ||
239 | 529 | # '"ops": [{"replicas": 3, "name": "glance", ' | ||
240 | 530 | # '"op": "create-pool"}]}'), | ||
241 | 531 | # 'private-address': '10.5.44.109', | ||
242 | 532 | # }, | ||
243 | 533 | # } | ||
244 | 534 | |||
245 | 535 | def get_previous_request(rid): | ||
246 | 536 | """Return the last ceph broker request sent on a given relation | ||
247 | 537 | |||
248 | 538 | @param rid: Relation id to query for request | ||
249 | 539 | """ | ||
250 | 540 | request = None | ||
251 | 541 | broker_req = relation_get(attribute='broker_req', rid=rid, | ||
252 | 542 | unit=local_unit()) | ||
253 | 543 | if broker_req: | ||
254 | 544 | request_data = json.loads(broker_req) | ||
255 | 545 | request = CephBrokerRq(api_version=request_data['api-version'], | ||
256 | 546 | request_id=request_data['request-id']) | ||
257 | 547 | request.set_ops(request_data['ops']) | ||
258 | 548 | |||
259 | 549 | return request | ||
260 | 550 | |||
261 | 551 | |||
262 | 552 | def get_request_states(request): | ||
263 | 553 | """Return a dict of requests per relation id with their corresponding | ||
264 | 554 | completion state. | ||
265 | 555 | |||
266 | 556 | This allows a charm, which has a request for ceph, to see whether there is | ||
267 | 557 | an equivalent request already being processed and if so what state that | ||
268 | 558 | request is in. | ||
269 | 559 | |||
270 | 560 | @param request: A CephBrokerRq object | ||
271 | 561 | """ | ||
272 | 562 | complete = [] | ||
273 | 563 | requests = {} | ||
274 | 564 | for rid in relation_ids('ceph'): | ||
275 | 565 | complete = False | ||
276 | 566 | previous_request = get_previous_request(rid) | ||
277 | 567 | if request == previous_request: | ||
278 | 568 | sent = True | ||
279 | 569 | complete = is_request_complete_for_rid(previous_request, rid) | ||
280 | 570 | else: | ||
281 | 571 | sent = False | ||
282 | 572 | complete = False | ||
283 | 573 | |||
284 | 574 | requests[rid] = { | ||
285 | 575 | 'sent': sent, | ||
286 | 576 | 'complete': complete, | ||
287 | 577 | } | ||
288 | 578 | |||
289 | 579 | return requests | ||
290 | 580 | |||
291 | 581 | |||
292 | 582 | def is_request_sent(request): | ||
293 | 583 | """Check to see if a functionally equivalent request has already been sent | ||
294 | 584 | |||
295 | 585 | Returns True if a similair request has been sent | ||
296 | 586 | |||
297 | 587 | @param request: A CephBrokerRq object | ||
298 | 588 | """ | ||
299 | 589 | states = get_request_states(request) | ||
300 | 590 | for rid in states.keys(): | ||
301 | 591 | if not states[rid]['sent']: | ||
302 | 592 | return False | ||
303 | 593 | |||
304 | 594 | return True | ||
305 | 595 | |||
306 | 596 | |||
307 | 597 | def is_request_complete(request): | ||
308 | 598 | """Check to see if a functionally equivalent request has already been | ||
309 | 599 | completed | ||
310 | 600 | |||
311 | 601 | Returns True if a similair request has been completed | ||
312 | 602 | |||
313 | 603 | @param request: A CephBrokerRq object | ||
314 | 604 | """ | ||
315 | 605 | states = get_request_states(request) | ||
316 | 606 | for rid in states.keys(): | ||
317 | 607 | if not states[rid]['complete']: | ||
318 | 608 | return False | ||
319 | 609 | |||
320 | 610 | return True | ||
321 | 611 | |||
322 | 612 | |||
323 | 613 | def is_request_complete_for_rid(request, rid): | ||
324 | 614 | """Check if a given request has been completed on the given relation | ||
325 | 615 | |||
326 | 616 | @param request: A CephBrokerRq object | ||
327 | 617 | @param rid: Relation ID | ||
328 | 618 | """ | ||
329 | 619 | broker_key = get_broker_rsp_key() | ||
330 | 620 | for unit in related_units(rid): | ||
331 | 621 | rdata = relation_get(rid=rid, unit=unit) | ||
332 | 622 | if rdata.get(broker_key): | ||
333 | 623 | rsp = CephBrokerRsp(rdata.get(broker_key)) | ||
334 | 624 | if rsp.request_id == request.request_id: | ||
335 | 625 | if not rsp.exit_code: | ||
336 | 626 | return True | ||
337 | 627 | else: | ||
338 | 628 | # The remote unit sent no reply targeted at this unit so either the | ||
339 | 629 | # remote ceph cluster does not support unit targeted replies or it | ||
340 | 630 | # has not processed our request yet. | ||
341 | 631 | if rdata.get('broker_rsp'): | ||
342 | 632 | request_data = json.loads(rdata['broker_rsp']) | ||
343 | 633 | if request_data.get('request-id'): | ||
344 | 634 | log('Ignoring legacy broker_rsp without unit key as remote ' | ||
345 | 635 | 'service supports unit specific replies', level=DEBUG) | ||
346 | 636 | else: | ||
347 | 637 | log('Using legacy broker_rsp as remote service does not ' | ||
348 | 638 | 'supports unit specific replies', level=DEBUG) | ||
349 | 639 | rsp = CephBrokerRsp(rdata['broker_rsp']) | ||
350 | 640 | if not rsp.exit_code: | ||
351 | 641 | return True | ||
352 | 642 | |||
353 | 643 | return False | ||
354 | 644 | |||
355 | 645 | |||
356 | 646 | def get_broker_rsp_key(): | ||
357 | 647 | """Return broker response key for this unit | ||
358 | 648 | |||
359 | 649 | This is the key that ceph is going to use to pass request status | ||
360 | 650 | information back to this unit | ||
361 | 651 | """ | ||
362 | 652 | return 'broker-rsp-' + local_unit().replace('/', '-') | ||
363 | 653 | |||
364 | 654 | |||
365 | 655 | def send_request_if_needed(request): | ||
366 | 656 | """Send broker request if an equivalent request has not already been sent | ||
367 | 657 | |||
368 | 658 | @param request: A CephBrokerRq object | ||
369 | 659 | """ | ||
370 | 660 | if is_request_sent(request): | ||
371 | 661 | log('Request already sent but not complete, not sending new request', | ||
372 | 662 | level=DEBUG) | ||
373 | 663 | else: | ||
374 | 664 | for rid in relation_ids('ceph'): | ||
375 | 665 | log('Sending request {}'.format(request.request_id), level=DEBUG) | ||
376 | 666 | relation_set(relation_id=rid, broker_req=request.request) | ||
377 | 445 | 667 | ||
378 | === modified file 'hooks/charmhelpers/core/hookenv.py' | |||
379 | --- hooks/charmhelpers/core/hookenv.py 2015-08-10 16:32:52 +0000 | |||
380 | +++ hooks/charmhelpers/core/hookenv.py 2015-09-16 09:02:26 +0000 | |||
381 | @@ -34,23 +34,6 @@ | |||
382 | 34 | import tempfile | 34 | import tempfile |
383 | 35 | from subprocess import CalledProcessError | 35 | from subprocess import CalledProcessError |
384 | 36 | 36 | ||
385 | 37 | try: | ||
386 | 38 | from charmhelpers.cli import cmdline | ||
387 | 39 | except ImportError as e: | ||
388 | 40 | # due to the anti-pattern of partially synching charmhelpers directly | ||
389 | 41 | # into charms, it's possible that charmhelpers.cli is not available; | ||
390 | 42 | # if that's the case, they don't really care about using the cli anyway, | ||
391 | 43 | # so mock it out | ||
392 | 44 | if str(e) == 'No module named cli': | ||
393 | 45 | class cmdline(object): | ||
394 | 46 | @classmethod | ||
395 | 47 | def subcommand(cls, *args, **kwargs): | ||
396 | 48 | def _wrap(func): | ||
397 | 49 | return func | ||
398 | 50 | return _wrap | ||
399 | 51 | else: | ||
400 | 52 | raise | ||
401 | 53 | |||
402 | 54 | import six | 37 | import six |
403 | 55 | if not six.PY3: | 38 | if not six.PY3: |
404 | 56 | from UserDict import UserDict | 39 | from UserDict import UserDict |
405 | @@ -91,6 +74,7 @@ | |||
406 | 91 | res = func(*args, **kwargs) | 74 | res = func(*args, **kwargs) |
407 | 92 | cache[key] = res | 75 | cache[key] = res |
408 | 93 | return res | 76 | return res |
409 | 77 | wrapper._wrapped = func | ||
410 | 94 | return wrapper | 78 | return wrapper |
411 | 95 | 79 | ||
412 | 96 | 80 | ||
413 | @@ -190,7 +174,6 @@ | |||
414 | 190 | return os.environ.get('JUJU_RELATION', None) | 174 | return os.environ.get('JUJU_RELATION', None) |
415 | 191 | 175 | ||
416 | 192 | 176 | ||
417 | 193 | @cmdline.subcommand() | ||
418 | 194 | @cached | 177 | @cached |
419 | 195 | def relation_id(relation_name=None, service_or_unit=None): | 178 | def relation_id(relation_name=None, service_or_unit=None): |
420 | 196 | """The relation ID for the current or a specified relation""" | 179 | """The relation ID for the current or a specified relation""" |
421 | @@ -216,13 +199,11 @@ | |||
422 | 216 | return os.environ.get('JUJU_REMOTE_UNIT', None) | 199 | return os.environ.get('JUJU_REMOTE_UNIT', None) |
423 | 217 | 200 | ||
424 | 218 | 201 | ||
425 | 219 | @cmdline.subcommand() | ||
426 | 220 | def service_name(): | 202 | def service_name(): |
427 | 221 | """The name service group this unit belongs to""" | 203 | """The name service group this unit belongs to""" |
428 | 222 | return local_unit().split('/')[0] | 204 | return local_unit().split('/')[0] |
429 | 223 | 205 | ||
430 | 224 | 206 | ||
431 | 225 | @cmdline.subcommand() | ||
432 | 226 | @cached | 207 | @cached |
433 | 227 | def remote_service_name(relid=None): | 208 | def remote_service_name(relid=None): |
434 | 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)""" |
435 | 229 | 210 | ||
436 | === modified file 'hooks/charmhelpers/core/host.py' | |||
437 | --- hooks/charmhelpers/core/host.py 2015-08-10 16:32:52 +0000 | |||
438 | +++ hooks/charmhelpers/core/host.py 2015-09-16 09:02:26 +0000 | |||
439 | @@ -72,7 +72,7 @@ | |||
440 | 72 | stopped = service_stop(service_name) | 72 | stopped = service_stop(service_name) |
441 | 73 | # XXX: Support systemd too | 73 | # XXX: Support systemd too |
442 | 74 | override_path = os.path.join( | 74 | override_path = os.path.join( |
444 | 75 | init_dir, '{}.conf.override'.format(service_name)) | 75 | init_dir, '{}.override'.format(service_name)) |
445 | 76 | with open(override_path, 'w') as fh: | 76 | with open(override_path, 'w') as fh: |
446 | 77 | fh.write("manual\n") | 77 | fh.write("manual\n") |
447 | 78 | return stopped | 78 | return stopped |
448 | @@ -86,7 +86,7 @@ | |||
449 | 86 | if init_dir is None: | 86 | if init_dir is None: |
450 | 87 | init_dir = "/etc/init" | 87 | init_dir = "/etc/init" |
451 | 88 | override_path = os.path.join( | 88 | override_path = os.path.join( |
453 | 89 | init_dir, '{}.conf.override'.format(service_name)) | 89 | init_dir, '{}.override'.format(service_name)) |
454 | 90 | if os.path.exists(override_path): | 90 | if os.path.exists(override_path): |
455 | 91 | os.unlink(override_path) | 91 | os.unlink(override_path) |
456 | 92 | started = service_start(service_name) | 92 | started = service_start(service_name) |
457 | 93 | 93 | ||
458 | === modified file 'hooks/hooks.py' | |||
459 | --- hooks/hooks.py 2015-03-23 17:40:42 +0000 | |||
460 | +++ hooks/hooks.py 2015-09-16 09:02:26 +0000 | |||
461 | @@ -144,8 +144,8 @@ | |||
462 | 144 | umount(e_mountpoint) | 144 | umount(e_mountpoint) |
463 | 145 | 145 | ||
464 | 146 | osd_journal = config('osd-journal') | 146 | osd_journal = config('osd-journal') |
467 | 147 | if (osd_journal and not os.path.exists(JOURNAL_ZAPPED) | 147 | if (osd_journal and not os.path.exists(JOURNAL_ZAPPED) and |
468 | 148 | and os.path.exists(osd_journal)): | 148 | os.path.exists(osd_journal)): |
469 | 149 | ceph.zap_disk(osd_journal) | 149 | ceph.zap_disk(osd_journal) |
470 | 150 | with open(JOURNAL_ZAPPED, 'w') as zapped: | 150 | with open(JOURNAL_ZAPPED, 'w') as zapped: |
471 | 151 | zapped.write('DONE') | 151 | zapped.write('DONE') |
472 | @@ -319,7 +319,15 @@ | |||
473 | 319 | log("Not leader - ignoring broker request", level=DEBUG) | 319 | log("Not leader - ignoring broker request", level=DEBUG) |
474 | 320 | else: | 320 | else: |
475 | 321 | rsp = process_requests(settings['broker_req']) | 321 | rsp = process_requests(settings['broker_req']) |
477 | 322 | relation_set(relation_settings={'broker_rsp': rsp}) | 322 | unit_id = remote_unit().replace('/', '-') |
478 | 323 | unit_response_key = 'broker-rsp-' + unit_id | ||
479 | 324 | # broker_rsp is being left for backward compatibility, | ||
480 | 325 | # unit_response_key superscedes it | ||
481 | 326 | data = { | ||
482 | 327 | 'broker_rsp': rsp, | ||
483 | 328 | unit_response_key: rsp, | ||
484 | 329 | } | ||
485 | 330 | relation_set(relation_settings=data) | ||
486 | 323 | else: | 331 | else: |
487 | 324 | log('mon cluster not in quorum', level=DEBUG) | 332 | log('mon cluster not in quorum', level=DEBUG) |
488 | 325 | 333 |
charm_lint_check #10408 ceph for gnuoy mp271260
LINT OK: passed
Build: http:// 10.245. 162.77: 8080/job/ charm_lint_ check/10408/