Merge lp:~james-page/charms/trusty/neutron-openvswitch/lp1531102-trunk into lp:~openstack-charmers-archive/charms/trusty/neutron-openvswitch/trunk
- Trusty Tahr (14.04)
- lp1531102-trunk
- Merge into trunk
Proposed by
James Page
on 2016-01-07
Status: | Merged | ||||
---|---|---|---|---|---|
Merged at revision: | 74 | ||||
Proposed branch: | lp:~james-page/charms/trusty/neutron-openvswitch/lp1531102-trunk | ||||
Merge into: | lp:~openstack-charmers-archive/charms/trusty/neutron-openvswitch/trunk | ||||
Diff against target: |
680 lines (+326/-36) 9 files modified
hooks/charmhelpers/contrib/openstack/amulet/deployment.py (+100/-1) hooks/charmhelpers/contrib/openstack/amulet/utils.py (+26/-4) hooks/charmhelpers/contrib/openstack/context.py (+25/-9) hooks/charmhelpers/contrib/openstack/neutron.py (+14/-0) hooks/charmhelpers/contrib/openstack/utils.py (+22/-17) hooks/charmhelpers/core/host.py (+12/-1) hooks/charmhelpers/core/hugepage.py (+2/-0) tests/charmhelpers/contrib/openstack/amulet/deployment.py (+100/-1) tests/charmhelpers/contrib/openstack/amulet/utils.py (+25/-3) |
||||
To merge this branch: | bzr merge lp:~james-page/charms/trusty/neutron-openvswitch/lp1531102-trunk | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Liam Young | 2016-01-07 | Approve on 2016-01-12 | |
Review via email:
|
Commit message
Resync helpers
Description of the change
Resync stable helpers to resolve liberty point release issues.
To post a comment you must log in.
charm_lint_check #16743 neutron-openvswitch for james-page mp281865
LINT OK: passed
Build: http://
charm_amulet_test #8566 neutron-openvswitch for james-page mp281865
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/charmhelpers/contrib/openstack/amulet/deployment.py' |
2 | --- hooks/charmhelpers/contrib/openstack/amulet/deployment.py 2015-10-22 13:22:05 +0000 |
3 | +++ hooks/charmhelpers/contrib/openstack/amulet/deployment.py 2016-01-07 14:19:54 +0000 |
4 | @@ -14,12 +14,18 @@ |
5 | # You should have received a copy of the GNU Lesser General Public License |
6 | # along with charm-helpers. If not, see <http://www.gnu.org/licenses/>. |
7 | |
8 | +import logging |
9 | +import re |
10 | +import sys |
11 | import six |
12 | from collections import OrderedDict |
13 | from charmhelpers.contrib.amulet.deployment import ( |
14 | AmuletDeployment |
15 | ) |
16 | |
17 | +DEBUG = logging.DEBUG |
18 | +ERROR = logging.ERROR |
19 | + |
20 | |
21 | class OpenStackAmuletDeployment(AmuletDeployment): |
22 | """OpenStack amulet deployment. |
23 | @@ -28,9 +34,12 @@ |
24 | that is specifically for use by OpenStack charms. |
25 | """ |
26 | |
27 | - def __init__(self, series=None, openstack=None, source=None, stable=True): |
28 | + def __init__(self, series=None, openstack=None, source=None, |
29 | + stable=True, log_level=DEBUG): |
30 | """Initialize the deployment environment.""" |
31 | super(OpenStackAmuletDeployment, self).__init__(series) |
32 | + self.log = self.get_logger(level=log_level) |
33 | + self.log.info('OpenStackAmuletDeployment: init') |
34 | self.openstack = openstack |
35 | self.source = source |
36 | self.stable = stable |
37 | @@ -38,6 +47,22 @@ |
38 | # out. |
39 | self.current_next = "trusty" |
40 | |
41 | + def get_logger(self, name="deployment-logger", level=logging.DEBUG): |
42 | + """Get a logger object that will log to stdout.""" |
43 | + log = logging |
44 | + logger = log.getLogger(name) |
45 | + fmt = log.Formatter("%(asctime)s %(funcName)s " |
46 | + "%(levelname)s: %(message)s") |
47 | + |
48 | + handler = log.StreamHandler(stream=sys.stdout) |
49 | + handler.setLevel(level) |
50 | + handler.setFormatter(fmt) |
51 | + |
52 | + logger.addHandler(handler) |
53 | + logger.setLevel(level) |
54 | + |
55 | + return logger |
56 | + |
57 | def _determine_branch_locations(self, other_services): |
58 | """Determine the branch locations for the other services. |
59 | |
60 | @@ -45,6 +70,8 @@ |
61 | stable or next (dev) branch, and based on this, use the corresonding |
62 | stable or next branches for the other_services.""" |
63 | |
64 | + self.log.info('OpenStackAmuletDeployment: determine branch locations') |
65 | + |
66 | # Charms outside the lp:~openstack-charmers namespace |
67 | base_charms = ['mysql', 'mongodb', 'nrpe'] |
68 | |
69 | @@ -82,6 +109,8 @@ |
70 | |
71 | def _add_services(self, this_service, other_services): |
72 | """Add services to the deployment and set openstack-origin/source.""" |
73 | + self.log.info('OpenStackAmuletDeployment: adding services') |
74 | + |
75 | other_services = self._determine_branch_locations(other_services) |
76 | |
77 | super(OpenStackAmuletDeployment, self)._add_services(this_service, |
78 | @@ -111,9 +140,79 @@ |
79 | |
80 | def _configure_services(self, configs): |
81 | """Configure all of the services.""" |
82 | + self.log.info('OpenStackAmuletDeployment: configure services') |
83 | for service, config in six.iteritems(configs): |
84 | self.d.configure(service, config) |
85 | |
86 | + def _auto_wait_for_status(self, message=None, exclude_services=None, |
87 | + include_only=None, timeout=1800): |
88 | + """Wait for all units to have a specific extended status, except |
89 | + for any defined as excluded. Unless specified via message, any |
90 | + status containing any case of 'ready' will be considered a match. |
91 | + |
92 | + Examples of message usage: |
93 | + |
94 | + Wait for all unit status to CONTAIN any case of 'ready' or 'ok': |
95 | + message = re.compile('.*ready.*|.*ok.*', re.IGNORECASE) |
96 | + |
97 | + Wait for all units to reach this status (exact match): |
98 | + message = re.compile('^Unit is ready and clustered$') |
99 | + |
100 | + Wait for all units to reach any one of these (exact match): |
101 | + message = re.compile('Unit is ready|OK|Ready') |
102 | + |
103 | + Wait for at least one unit to reach this status (exact match): |
104 | + message = {'ready'} |
105 | + |
106 | + See Amulet's sentry.wait_for_messages() for message usage detail. |
107 | + https://github.com/juju/amulet/blob/master/amulet/sentry.py |
108 | + |
109 | + :param message: Expected status match |
110 | + :param exclude_services: List of juju service names to ignore, |
111 | + not to be used in conjuction with include_only. |
112 | + :param include_only: List of juju service names to exclusively check, |
113 | + not to be used in conjuction with exclude_services. |
114 | + :param timeout: Maximum time in seconds to wait for status match |
115 | + :returns: None. Raises if timeout is hit. |
116 | + """ |
117 | + self.log.info('Waiting for extended status on units...') |
118 | + |
119 | + all_services = self.d.services.keys() |
120 | + |
121 | + if exclude_services and include_only: |
122 | + raise ValueError('exclude_services can not be used ' |
123 | + 'with include_only') |
124 | + |
125 | + if message: |
126 | + if isinstance(message, re._pattern_type): |
127 | + match = message.pattern |
128 | + else: |
129 | + match = message |
130 | + |
131 | + self.log.debug('Custom extended status wait match: ' |
132 | + '{}'.format(match)) |
133 | + else: |
134 | + self.log.debug('Default extended status wait match: contains ' |
135 | + 'READY (case-insensitive)') |
136 | + message = re.compile('.*ready.*', re.IGNORECASE) |
137 | + |
138 | + if exclude_services: |
139 | + self.log.debug('Excluding services from extended status match: ' |
140 | + '{}'.format(exclude_services)) |
141 | + else: |
142 | + exclude_services = [] |
143 | + |
144 | + if include_only: |
145 | + services = include_only |
146 | + else: |
147 | + services = list(set(all_services) - set(exclude_services)) |
148 | + |
149 | + self.log.debug('Waiting up to {}s for extended status on services: ' |
150 | + '{}'.format(timeout, services)) |
151 | + service_messages = {service: message for service in services} |
152 | + self.d.sentry.wait_for_messages(service_messages, timeout=timeout) |
153 | + self.log.info('OK') |
154 | + |
155 | def _get_openstack_release(self): |
156 | """Get openstack release. |
157 | |
158 | |
159 | === modified file 'hooks/charmhelpers/contrib/openstack/amulet/utils.py' |
160 | --- hooks/charmhelpers/contrib/openstack/amulet/utils.py 2015-10-22 13:22:05 +0000 |
161 | +++ hooks/charmhelpers/contrib/openstack/amulet/utils.py 2016-01-07 14:19:54 +0000 |
162 | @@ -18,6 +18,7 @@ |
163 | import json |
164 | import logging |
165 | import os |
166 | +import re |
167 | import six |
168 | import time |
169 | import urllib |
170 | @@ -604,7 +605,22 @@ |
171 | '{}'.format(sample_type, samples)) |
172 | return None |
173 | |
174 | -# rabbitmq/amqp specific helpers: |
175 | + # rabbitmq/amqp specific helpers: |
176 | + |
177 | + def rmq_wait_for_cluster(self, deployment, init_sleep=15, timeout=1200): |
178 | + """Wait for rmq units extended status to show cluster readiness, |
179 | + after an optional initial sleep period. Initial sleep is likely |
180 | + necessary to be effective following a config change, as status |
181 | + message may not instantly update to non-ready.""" |
182 | + |
183 | + if init_sleep: |
184 | + time.sleep(init_sleep) |
185 | + |
186 | + message = re.compile('^Unit is ready and clustered$') |
187 | + deployment._auto_wait_for_status(message=message, |
188 | + timeout=timeout, |
189 | + include_only=['rabbitmq-server']) |
190 | + |
191 | def add_rmq_test_user(self, sentry_units, |
192 | username="testuser1", password="changeme"): |
193 | """Add a test user via the first rmq juju unit, check connection as |
194 | @@ -752,7 +768,7 @@ |
195 | self.log.debug('SSL is enabled @{}:{} ' |
196 | '({})'.format(host, port, unit_name)) |
197 | return True |
198 | - elif not port and not conf_ssl: |
199 | + elif not conf_ssl: |
200 | self.log.debug('SSL not enabled @{}:{} ' |
201 | '({})'.format(host, port, unit_name)) |
202 | return False |
203 | @@ -805,7 +821,10 @@ |
204 | if port: |
205 | config['ssl_port'] = port |
206 | |
207 | - deployment.configure('rabbitmq-server', config) |
208 | + deployment.d.configure('rabbitmq-server', config) |
209 | + |
210 | + # Wait for unit status |
211 | + self.rmq_wait_for_cluster(deployment) |
212 | |
213 | # Confirm |
214 | tries = 0 |
215 | @@ -832,7 +851,10 @@ |
216 | |
217 | # Disable RMQ SSL |
218 | config = {'ssl': 'off'} |
219 | - deployment.configure('rabbitmq-server', config) |
220 | + deployment.d.configure('rabbitmq-server', config) |
221 | + |
222 | + # Wait for unit status |
223 | + self.rmq_wait_for_cluster(deployment) |
224 | |
225 | # Confirm |
226 | tries = 0 |
227 | |
228 | === modified file 'hooks/charmhelpers/contrib/openstack/context.py' |
229 | --- hooks/charmhelpers/contrib/openstack/context.py 2015-10-22 13:22:05 +0000 |
230 | +++ hooks/charmhelpers/contrib/openstack/context.py 2016-01-07 14:19:54 +0000 |
231 | @@ -952,6 +952,19 @@ |
232 | 'config': config} |
233 | return ovs_ctxt |
234 | |
235 | + def midonet_ctxt(self): |
236 | + driver = neutron_plugin_attribute(self.plugin, 'driver', |
237 | + self.network_manager) |
238 | + midonet_config = neutron_plugin_attribute(self.plugin, 'config', |
239 | + self.network_manager) |
240 | + mido_ctxt = {'core_plugin': driver, |
241 | + 'neutron_plugin': 'midonet', |
242 | + 'neutron_security_groups': self.neutron_security_groups, |
243 | + 'local_ip': unit_private_ip(), |
244 | + 'config': midonet_config} |
245 | + |
246 | + return mido_ctxt |
247 | + |
248 | def __call__(self): |
249 | if self.network_manager not in ['quantum', 'neutron']: |
250 | return {} |
251 | @@ -973,6 +986,8 @@ |
252 | ctxt.update(self.nuage_ctxt()) |
253 | elif self.plugin == 'plumgrid': |
254 | ctxt.update(self.pg_ctxt()) |
255 | + elif self.plugin == 'midonet': |
256 | + ctxt.update(self.midonet_ctxt()) |
257 | |
258 | alchemy_flags = config('neutron-alchemy-flags') |
259 | if alchemy_flags: |
260 | @@ -1105,7 +1120,7 @@ |
261 | |
262 | ctxt = { |
263 | ... other context ... |
264 | - 'subordinate_config': { |
265 | + 'subordinate_configuration': { |
266 | 'DEFAULT': { |
267 | 'key1': 'value1', |
268 | }, |
269 | @@ -1146,22 +1161,23 @@ |
270 | try: |
271 | sub_config = json.loads(sub_config) |
272 | except: |
273 | - log('Could not parse JSON from subordinate_config ' |
274 | - 'setting from %s' % rid, level=ERROR) |
275 | + log('Could not parse JSON from ' |
276 | + 'subordinate_configuration setting from %s' |
277 | + % rid, level=ERROR) |
278 | continue |
279 | |
280 | for service in self.services: |
281 | if service not in sub_config: |
282 | - log('Found subordinate_config on %s but it contained' |
283 | - 'nothing for %s service' % (rid, service), |
284 | - level=INFO) |
285 | + log('Found subordinate_configuration on %s but it ' |
286 | + 'contained nothing for %s service' |
287 | + % (rid, service), level=INFO) |
288 | continue |
289 | |
290 | sub_config = sub_config[service] |
291 | if self.config_file not in sub_config: |
292 | - log('Found subordinate_config on %s but it contained' |
293 | - 'nothing for %s' % (rid, self.config_file), |
294 | - level=INFO) |
295 | + log('Found subordinate_configuration on %s but it ' |
296 | + 'contained nothing for %s' |
297 | + % (rid, self.config_file), level=INFO) |
298 | continue |
299 | |
300 | sub_config = sub_config[self.config_file] |
301 | |
302 | === modified file 'hooks/charmhelpers/contrib/openstack/neutron.py' |
303 | --- hooks/charmhelpers/contrib/openstack/neutron.py 2015-10-22 13:22:05 +0000 |
304 | +++ hooks/charmhelpers/contrib/openstack/neutron.py 2016-01-07 14:19:54 +0000 |
305 | @@ -209,6 +209,20 @@ |
306 | 'server_packages': ['neutron-server', |
307 | 'neutron-plugin-plumgrid'], |
308 | 'server_services': ['neutron-server'] |
309 | + }, |
310 | + 'midonet': { |
311 | + 'config': '/etc/neutron/plugins/midonet/midonet.ini', |
312 | + 'driver': 'midonet.neutron.plugin.MidonetPluginV2', |
313 | + 'contexts': [ |
314 | + context.SharedDBContext(user=config('neutron-database-user'), |
315 | + database=config('neutron-database'), |
316 | + relation_prefix='neutron', |
317 | + ssl_dir=NEUTRON_CONF_DIR)], |
318 | + 'services': [], |
319 | + 'packages': [[headers_package()] + determine_dkms_package()], |
320 | + 'server_packages': ['neutron-server', |
321 | + 'python-neutron-plugin-midonet'], |
322 | + 'server_services': ['neutron-server'] |
323 | } |
324 | } |
325 | if release >= 'icehouse': |
326 | |
327 | === modified file 'hooks/charmhelpers/contrib/openstack/utils.py' |
328 | --- hooks/charmhelpers/contrib/openstack/utils.py 2015-10-22 13:22:05 +0000 |
329 | +++ hooks/charmhelpers/contrib/openstack/utils.py 2016-01-07 14:19:54 +0000 |
330 | @@ -121,36 +121,37 @@ |
331 | ('2.2.2', 'kilo'), |
332 | ('2.3.0', 'liberty'), |
333 | ('2.4.0', 'liberty'), |
334 | + ('2.5.0', 'liberty'), |
335 | ]) |
336 | |
337 | # >= Liberty version->codename mapping |
338 | PACKAGE_CODENAMES = { |
339 | 'nova-common': OrderedDict([ |
340 | - ('12.0.0', 'liberty'), |
341 | + ('12.0', 'liberty'), |
342 | ]), |
343 | 'neutron-common': OrderedDict([ |
344 | - ('7.0.0', 'liberty'), |
345 | + ('7.0', 'liberty'), |
346 | ]), |
347 | 'cinder-common': OrderedDict([ |
348 | - ('7.0.0', 'liberty'), |
349 | + ('7.0', 'liberty'), |
350 | ]), |
351 | 'keystone': OrderedDict([ |
352 | - ('8.0.0', 'liberty'), |
353 | + ('8.0', 'liberty'), |
354 | ]), |
355 | 'horizon-common': OrderedDict([ |
356 | - ('8.0.0', 'liberty'), |
357 | + ('8.0', 'liberty'), |
358 | ]), |
359 | 'ceilometer-common': OrderedDict([ |
360 | - ('5.0.0', 'liberty'), |
361 | + ('5.0', 'liberty'), |
362 | ]), |
363 | 'heat-common': OrderedDict([ |
364 | - ('5.0.0', 'liberty'), |
365 | + ('5.0', 'liberty'), |
366 | ]), |
367 | 'glance-common': OrderedDict([ |
368 | - ('11.0.0', 'liberty'), |
369 | + ('11.0', 'liberty'), |
370 | ]), |
371 | 'openstack-dashboard': OrderedDict([ |
372 | - ('8.0.0', 'liberty'), |
373 | + ('8.0', 'liberty'), |
374 | ]), |
375 | } |
376 | |
377 | @@ -237,7 +238,14 @@ |
378 | error_out(e) |
379 | |
380 | vers = apt.upstream_version(pkg.current_ver.ver_str) |
381 | - match = re.match('^(\d+)\.(\d+)\.(\d+)', vers) |
382 | + if 'swift' in pkg.name: |
383 | + # Fully x.y.z match for swift versions |
384 | + match = re.match('^(\d+)\.(\d+)\.(\d+)', vers) |
385 | + else: |
386 | + # x.y match only for 20XX.X |
387 | + # and ignore patch level for other packages |
388 | + match = re.match('^(\d+)\.(\d+)', vers) |
389 | + |
390 | if match: |
391 | vers = match.group(0) |
392 | |
393 | @@ -249,13 +257,8 @@ |
394 | # < Liberty co-ordinated project versions |
395 | try: |
396 | if 'swift' in pkg.name: |
397 | - swift_vers = vers[:5] |
398 | - if swift_vers not in SWIFT_CODENAMES: |
399 | - # Deal with 1.10.0 upward |
400 | - swift_vers = vers[:6] |
401 | - return SWIFT_CODENAMES[swift_vers] |
402 | + return SWIFT_CODENAMES[vers] |
403 | else: |
404 | - vers = vers[:6] |
405 | return OPENSTACK_CODENAMES[vers] |
406 | except KeyError: |
407 | if not fatal: |
408 | @@ -858,7 +861,9 @@ |
409 | if charm_state != 'active' and charm_state != 'unknown': |
410 | state = workload_state_compare(state, charm_state) |
411 | if message: |
412 | - message = "{} {}".format(message, charm_message) |
413 | + charm_message = charm_message.replace("Incomplete relations: ", |
414 | + "") |
415 | + message = "{}, {}".format(message, charm_message) |
416 | else: |
417 | message = charm_message |
418 | |
419 | |
420 | === modified file 'hooks/charmhelpers/core/host.py' |
421 | --- hooks/charmhelpers/core/host.py 2015-10-22 13:22:05 +0000 |
422 | +++ hooks/charmhelpers/core/host.py 2016-01-07 14:19:54 +0000 |
423 | @@ -566,7 +566,14 @@ |
424 | os.chdir(cur) |
425 | |
426 | |
427 | -def chownr(path, owner, group, follow_links=True): |
428 | +def chownr(path, owner, group, follow_links=True, chowntopdir=False): |
429 | + """ |
430 | + Recursively change user and group ownership of files and directories |
431 | + in given path. Doesn't chown path itself by default, only its children. |
432 | + |
433 | + :param bool follow_links: Also Chown links if True |
434 | + :param bool chowntopdir: Also chown path itself if True |
435 | + """ |
436 | uid = pwd.getpwnam(owner).pw_uid |
437 | gid = grp.getgrnam(group).gr_gid |
438 | if follow_links: |
439 | @@ -574,6 +581,10 @@ |
440 | else: |
441 | chown = os.lchown |
442 | |
443 | + if chowntopdir: |
444 | + broken_symlink = os.path.lexists(path) and not os.path.exists(path) |
445 | + if not broken_symlink: |
446 | + chown(path, uid, gid) |
447 | for root, dirs, files in os.walk(path): |
448 | for name in dirs + files: |
449 | full = os.path.join(root, name) |
450 | |
451 | === modified file 'hooks/charmhelpers/core/hugepage.py' |
452 | --- hooks/charmhelpers/core/hugepage.py 2015-10-22 13:22:05 +0000 |
453 | +++ hooks/charmhelpers/core/hugepage.py 2016-01-07 14:19:54 +0000 |
454 | @@ -46,6 +46,8 @@ |
455 | group_info = add_group(group) |
456 | gid = group_info.gr_gid |
457 | add_user_to_group(user, group) |
458 | + if max_map_count < 2 * nr_hugepages: |
459 | + max_map_count = 2 * nr_hugepages |
460 | sysctl_settings = { |
461 | 'vm.nr_hugepages': nr_hugepages, |
462 | 'vm.max_map_count': max_map_count, |
463 | |
464 | === modified file 'tests/charmhelpers/contrib/openstack/amulet/deployment.py' |
465 | --- tests/charmhelpers/contrib/openstack/amulet/deployment.py 2015-10-22 13:22:05 +0000 |
466 | +++ tests/charmhelpers/contrib/openstack/amulet/deployment.py 2016-01-07 14:19:54 +0000 |
467 | @@ -14,12 +14,18 @@ |
468 | # You should have received a copy of the GNU Lesser General Public License |
469 | # along with charm-helpers. If not, see <http://www.gnu.org/licenses/>. |
470 | |
471 | +import logging |
472 | +import re |
473 | +import sys |
474 | import six |
475 | from collections import OrderedDict |
476 | from charmhelpers.contrib.amulet.deployment import ( |
477 | AmuletDeployment |
478 | ) |
479 | |
480 | +DEBUG = logging.DEBUG |
481 | +ERROR = logging.ERROR |
482 | + |
483 | |
484 | class OpenStackAmuletDeployment(AmuletDeployment): |
485 | """OpenStack amulet deployment. |
486 | @@ -28,9 +34,12 @@ |
487 | that is specifically for use by OpenStack charms. |
488 | """ |
489 | |
490 | - def __init__(self, series=None, openstack=None, source=None, stable=True): |
491 | + def __init__(self, series=None, openstack=None, source=None, |
492 | + stable=True, log_level=DEBUG): |
493 | """Initialize the deployment environment.""" |
494 | super(OpenStackAmuletDeployment, self).__init__(series) |
495 | + self.log = self.get_logger(level=log_level) |
496 | + self.log.info('OpenStackAmuletDeployment: init') |
497 | self.openstack = openstack |
498 | self.source = source |
499 | self.stable = stable |
500 | @@ -38,6 +47,22 @@ |
501 | # out. |
502 | self.current_next = "trusty" |
503 | |
504 | + def get_logger(self, name="deployment-logger", level=logging.DEBUG): |
505 | + """Get a logger object that will log to stdout.""" |
506 | + log = logging |
507 | + logger = log.getLogger(name) |
508 | + fmt = log.Formatter("%(asctime)s %(funcName)s " |
509 | + "%(levelname)s: %(message)s") |
510 | + |
511 | + handler = log.StreamHandler(stream=sys.stdout) |
512 | + handler.setLevel(level) |
513 | + handler.setFormatter(fmt) |
514 | + |
515 | + logger.addHandler(handler) |
516 | + logger.setLevel(level) |
517 | + |
518 | + return logger |
519 | + |
520 | def _determine_branch_locations(self, other_services): |
521 | """Determine the branch locations for the other services. |
522 | |
523 | @@ -45,6 +70,8 @@ |
524 | stable or next (dev) branch, and based on this, use the corresonding |
525 | stable or next branches for the other_services.""" |
526 | |
527 | + self.log.info('OpenStackAmuletDeployment: determine branch locations') |
528 | + |
529 | # Charms outside the lp:~openstack-charmers namespace |
530 | base_charms = ['mysql', 'mongodb', 'nrpe'] |
531 | |
532 | @@ -82,6 +109,8 @@ |
533 | |
534 | def _add_services(self, this_service, other_services): |
535 | """Add services to the deployment and set openstack-origin/source.""" |
536 | + self.log.info('OpenStackAmuletDeployment: adding services') |
537 | + |
538 | other_services = self._determine_branch_locations(other_services) |
539 | |
540 | super(OpenStackAmuletDeployment, self)._add_services(this_service, |
541 | @@ -111,9 +140,79 @@ |
542 | |
543 | def _configure_services(self, configs): |
544 | """Configure all of the services.""" |
545 | + self.log.info('OpenStackAmuletDeployment: configure services') |
546 | for service, config in six.iteritems(configs): |
547 | self.d.configure(service, config) |
548 | |
549 | + def _auto_wait_for_status(self, message=None, exclude_services=None, |
550 | + include_only=None, timeout=1800): |
551 | + """Wait for all units to have a specific extended status, except |
552 | + for any defined as excluded. Unless specified via message, any |
553 | + status containing any case of 'ready' will be considered a match. |
554 | + |
555 | + Examples of message usage: |
556 | + |
557 | + Wait for all unit status to CONTAIN any case of 'ready' or 'ok': |
558 | + message = re.compile('.*ready.*|.*ok.*', re.IGNORECASE) |
559 | + |
560 | + Wait for all units to reach this status (exact match): |
561 | + message = re.compile('^Unit is ready and clustered$') |
562 | + |
563 | + Wait for all units to reach any one of these (exact match): |
564 | + message = re.compile('Unit is ready|OK|Ready') |
565 | + |
566 | + Wait for at least one unit to reach this status (exact match): |
567 | + message = {'ready'} |
568 | + |
569 | + See Amulet's sentry.wait_for_messages() for message usage detail. |
570 | + https://github.com/juju/amulet/blob/master/amulet/sentry.py |
571 | + |
572 | + :param message: Expected status match |
573 | + :param exclude_services: List of juju service names to ignore, |
574 | + not to be used in conjuction with include_only. |
575 | + :param include_only: List of juju service names to exclusively check, |
576 | + not to be used in conjuction with exclude_services. |
577 | + :param timeout: Maximum time in seconds to wait for status match |
578 | + :returns: None. Raises if timeout is hit. |
579 | + """ |
580 | + self.log.info('Waiting for extended status on units...') |
581 | + |
582 | + all_services = self.d.services.keys() |
583 | + |
584 | + if exclude_services and include_only: |
585 | + raise ValueError('exclude_services can not be used ' |
586 | + 'with include_only') |
587 | + |
588 | + if message: |
589 | + if isinstance(message, re._pattern_type): |
590 | + match = message.pattern |
591 | + else: |
592 | + match = message |
593 | + |
594 | + self.log.debug('Custom extended status wait match: ' |
595 | + '{}'.format(match)) |
596 | + else: |
597 | + self.log.debug('Default extended status wait match: contains ' |
598 | + 'READY (case-insensitive)') |
599 | + message = re.compile('.*ready.*', re.IGNORECASE) |
600 | + |
601 | + if exclude_services: |
602 | + self.log.debug('Excluding services from extended status match: ' |
603 | + '{}'.format(exclude_services)) |
604 | + else: |
605 | + exclude_services = [] |
606 | + |
607 | + if include_only: |
608 | + services = include_only |
609 | + else: |
610 | + services = list(set(all_services) - set(exclude_services)) |
611 | + |
612 | + self.log.debug('Waiting up to {}s for extended status on services: ' |
613 | + '{}'.format(timeout, services)) |
614 | + service_messages = {service: message for service in services} |
615 | + self.d.sentry.wait_for_messages(service_messages, timeout=timeout) |
616 | + self.log.info('OK') |
617 | + |
618 | def _get_openstack_release(self): |
619 | """Get openstack release. |
620 | |
621 | |
622 | === modified file 'tests/charmhelpers/contrib/openstack/amulet/utils.py' |
623 | --- tests/charmhelpers/contrib/openstack/amulet/utils.py 2015-10-22 13:22:05 +0000 |
624 | +++ tests/charmhelpers/contrib/openstack/amulet/utils.py 2016-01-07 14:19:54 +0000 |
625 | @@ -18,6 +18,7 @@ |
626 | import json |
627 | import logging |
628 | import os |
629 | +import re |
630 | import six |
631 | import time |
632 | import urllib |
633 | @@ -604,7 +605,22 @@ |
634 | '{}'.format(sample_type, samples)) |
635 | return None |
636 | |
637 | -# rabbitmq/amqp specific helpers: |
638 | + # rabbitmq/amqp specific helpers: |
639 | + |
640 | + def rmq_wait_for_cluster(self, deployment, init_sleep=15, timeout=1200): |
641 | + """Wait for rmq units extended status to show cluster readiness, |
642 | + after an optional initial sleep period. Initial sleep is likely |
643 | + necessary to be effective following a config change, as status |
644 | + message may not instantly update to non-ready.""" |
645 | + |
646 | + if init_sleep: |
647 | + time.sleep(init_sleep) |
648 | + |
649 | + message = re.compile('^Unit is ready and clustered$') |
650 | + deployment._auto_wait_for_status(message=message, |
651 | + timeout=timeout, |
652 | + include_only=['rabbitmq-server']) |
653 | + |
654 | def add_rmq_test_user(self, sentry_units, |
655 | username="testuser1", password="changeme"): |
656 | """Add a test user via the first rmq juju unit, check connection as |
657 | @@ -805,7 +821,10 @@ |
658 | if port: |
659 | config['ssl_port'] = port |
660 | |
661 | - deployment.configure('rabbitmq-server', config) |
662 | + deployment.d.configure('rabbitmq-server', config) |
663 | + |
664 | + # Wait for unit status |
665 | + self.rmq_wait_for_cluster(deployment) |
666 | |
667 | # Confirm |
668 | tries = 0 |
669 | @@ -832,7 +851,10 @@ |
670 | |
671 | # Disable RMQ SSL |
672 | config = {'ssl': 'off'} |
673 | - deployment.configure('rabbitmq-server', config) |
674 | + deployment.d.configure('rabbitmq-server', config) |
675 | + |
676 | + # Wait for unit status |
677 | + self.rmq_wait_for_cluster(deployment) |
678 | |
679 | # Confirm |
680 | tries = 0 |
charm_unit_test #15630 neutron-openvswitch for james-page mp281865
UNIT OK: passed
Build: http:// 10.245. 162.77: 8080/job/ charm_unit_ test/15630/