Merge lp:~james-page/charms/trusty/neutron-gateway/lp1531102-trunk into lp:~openstack-charmers-archive/charms/trusty/neutron-gateway/trunk

Proposed by James Page on 2016-01-07
Status: Merged
Merged at revision: 136
Proposed branch: lp:~james-page/charms/trusty/neutron-gateway/lp1531102-trunk
Merge into: lp:~openstack-charmers-archive/charms/trusty/neutron-gateway/trunk
Diff against target: 533 lines (+207/-39)
6 files modified
hooks/charmhelpers/contrib/openstack/amulet/deployment.py (+67/-8)
hooks/charmhelpers/contrib/openstack/amulet/utils.py (+25/-3)
hooks/charmhelpers/contrib/openstack/utils.py (+21/-17)
hooks/charmhelpers/core/hugepage.py (+2/-0)
tests/charmhelpers/contrib/openstack/amulet/deployment.py (+67/-8)
tests/charmhelpers/contrib/openstack/amulet/utils.py (+25/-3)
To merge this branch: bzr merge lp:~james-page/charms/trusty/neutron-gateway/lp1531102-trunk
Reviewer Review Type Date Requested Status
charmers 2016-01-07 Pending
Review via email: mp+281864@code.launchpad.net

Commit message

Resync helpers

Description of the change

Resync stable helpers.

To post a comment you must log in.

charm_lint_check #16737 neutron-gateway for james-page mp281864
    LINT OK: passed

Build: http://10.245.162.77:8080/job/charm_lint_check/16737/

charm_unit_test #15634 neutron-gateway for james-page mp281864
    UNIT OK: passed

Build: http://10.245.162.77:8080/job/charm_unit_test/15634/

charm_amulet_test #8561 neutron-gateway for james-page mp281864
    AMULET OK: passed

Build: http://10.245.162.77:8080/job/charm_amulet_test/8561/

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:23:58 +0000
3+++ hooks/charmhelpers/contrib/openstack/amulet/deployment.py 2016-01-07 14:18:30 +0000
4@@ -14,13 +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@@ -29,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@@ -39,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@@ -46,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@@ -83,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@@ -112,11 +140,12 @@
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- timeout=1800):
88+ include_only=None, timeout=1800):
89 """Wait for all units to have a specific extended status, except
90 for any defined as excluded. Unless specified via message, any
91 status containing any case of 'ready' will be considered a match.
92@@ -127,7 +156,7 @@
93 message = re.compile('.*ready.*|.*ok.*', re.IGNORECASE)
94
95 Wait for all units to reach this status (exact match):
96- message = 'Unit is ready'
97+ message = re.compile('^Unit is ready and clustered$')
98
99 Wait for all units to reach any one of these (exact match):
100 message = re.compile('Unit is ready|OK|Ready')
101@@ -139,20 +168,50 @@
102 https://github.com/juju/amulet/blob/master/amulet/sentry.py
103
104 :param message: Expected status match
105- :param exclude_services: List of juju service names to ignore
106+ :param exclude_services: List of juju service names to ignore,
107+ not to be used in conjuction with include_only.
108+ :param include_only: List of juju service names to exclusively check,
109+ not to be used in conjuction with exclude_services.
110 :param timeout: Maximum time in seconds to wait for status match
111 :returns: None. Raises if timeout is hit.
112 """
113-
114- if not message:
115+ self.log.info('Waiting for extended status on units...')
116+
117+ all_services = self.d.services.keys()
118+
119+ if exclude_services and include_only:
120+ raise ValueError('exclude_services can not be used '
121+ 'with include_only')
122+
123+ if message:
124+ if isinstance(message, re._pattern_type):
125+ match = message.pattern
126+ else:
127+ match = message
128+
129+ self.log.debug('Custom extended status wait match: '
130+ '{}'.format(match))
131+ else:
132+ self.log.debug('Default extended status wait match: contains '
133+ 'READY (case-insensitive)')
134 message = re.compile('.*ready.*', re.IGNORECASE)
135
136- if not exclude_services:
137+ if exclude_services:
138+ self.log.debug('Excluding services from extended status match: '
139+ '{}'.format(exclude_services))
140+ else:
141 exclude_services = []
142
143- services = list(set(self.d.services.keys()) - set(exclude_services))
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=== modified file 'hooks/charmhelpers/contrib/openstack/amulet/utils.py'
159--- hooks/charmhelpers/contrib/openstack/amulet/utils.py 2015-10-22 13:23:58 +0000
160+++ hooks/charmhelpers/contrib/openstack/amulet/utils.py 2016-01-07 14:18:30 +0000
161@@ -18,6 +18,7 @@
162 import json
163 import logging
164 import os
165+import re
166 import six
167 import time
168 import urllib
169@@ -604,7 +605,22 @@
170 '{}'.format(sample_type, samples))
171 return None
172
173-# rabbitmq/amqp specific helpers:
174+ # rabbitmq/amqp specific helpers:
175+
176+ def rmq_wait_for_cluster(self, deployment, init_sleep=15, timeout=1200):
177+ """Wait for rmq units extended status to show cluster readiness,
178+ after an optional initial sleep period. Initial sleep is likely
179+ necessary to be effective following a config change, as status
180+ message may not instantly update to non-ready."""
181+
182+ if init_sleep:
183+ time.sleep(init_sleep)
184+
185+ message = re.compile('^Unit is ready and clustered$')
186+ deployment._auto_wait_for_status(message=message,
187+ timeout=timeout,
188+ include_only=['rabbitmq-server'])
189+
190 def add_rmq_test_user(self, sentry_units,
191 username="testuser1", password="changeme"):
192 """Add a test user via the first rmq juju unit, check connection as
193@@ -805,7 +821,10 @@
194 if port:
195 config['ssl_port'] = port
196
197- deployment.configure('rabbitmq-server', config)
198+ deployment.d.configure('rabbitmq-server', config)
199+
200+ # Wait for unit status
201+ self.rmq_wait_for_cluster(deployment)
202
203 # Confirm
204 tries = 0
205@@ -832,7 +851,10 @@
206
207 # Disable RMQ SSL
208 config = {'ssl': 'off'}
209- deployment.configure('rabbitmq-server', config)
210+ deployment.d.configure('rabbitmq-server', config)
211+
212+ # Wait for unit status
213+ self.rmq_wait_for_cluster(deployment)
214
215 # Confirm
216 tries = 0
217
218=== modified file 'hooks/charmhelpers/contrib/openstack/utils.py'
219--- hooks/charmhelpers/contrib/openstack/utils.py 2015-10-22 13:23:58 +0000
220+++ hooks/charmhelpers/contrib/openstack/utils.py 2016-01-07 14:18:30 +0000
221@@ -127,31 +127,31 @@
222 # >= Liberty version->codename mapping
223 PACKAGE_CODENAMES = {
224 'nova-common': OrderedDict([
225- ('12.0.0', 'liberty'),
226+ ('12.0', 'liberty'),
227 ]),
228 'neutron-common': OrderedDict([
229- ('7.0.0', 'liberty'),
230+ ('7.0', 'liberty'),
231 ]),
232 'cinder-common': OrderedDict([
233- ('7.0.0', 'liberty'),
234+ ('7.0', 'liberty'),
235 ]),
236 'keystone': OrderedDict([
237- ('8.0.0', 'liberty'),
238+ ('8.0', 'liberty'),
239 ]),
240 'horizon-common': OrderedDict([
241- ('8.0.0', 'liberty'),
242+ ('8.0', 'liberty'),
243 ]),
244 'ceilometer-common': OrderedDict([
245- ('5.0.0', 'liberty'),
246+ ('5.0', 'liberty'),
247 ]),
248 'heat-common': OrderedDict([
249- ('5.0.0', 'liberty'),
250+ ('5.0', 'liberty'),
251 ]),
252 'glance-common': OrderedDict([
253- ('11.0.0', 'liberty'),
254+ ('11.0', 'liberty'),
255 ]),
256 'openstack-dashboard': OrderedDict([
257- ('8.0.0', 'liberty'),
258+ ('8.0', 'liberty'),
259 ]),
260 }
261
262@@ -238,7 +238,14 @@
263 error_out(e)
264
265 vers = apt.upstream_version(pkg.current_ver.ver_str)
266- match = re.match('^(\d+)\.(\d+)\.(\d+)', vers)
267+ if 'swift' in pkg.name:
268+ # Fully x.y.z match for swift versions
269+ match = re.match('^(\d+)\.(\d+)\.(\d+)', vers)
270+ else:
271+ # x.y match only for 20XX.X
272+ # and ignore patch level for other packages
273+ match = re.match('^(\d+)\.(\d+)', vers)
274+
275 if match:
276 vers = match.group(0)
277
278@@ -250,13 +257,8 @@
279 # < Liberty co-ordinated project versions
280 try:
281 if 'swift' in pkg.name:
282- swift_vers = vers[:5]
283- if swift_vers not in SWIFT_CODENAMES:
284- # Deal with 1.10.0 upward
285- swift_vers = vers[:6]
286- return SWIFT_CODENAMES[swift_vers]
287+ return SWIFT_CODENAMES[vers]
288 else:
289- vers = vers[:6]
290 return OPENSTACK_CODENAMES[vers]
291 except KeyError:
292 if not fatal:
293@@ -859,7 +861,9 @@
294 if charm_state != 'active' and charm_state != 'unknown':
295 state = workload_state_compare(state, charm_state)
296 if message:
297- message = "{} {}".format(message, charm_message)
298+ charm_message = charm_message.replace("Incomplete relations: ",
299+ "")
300+ message = "{}, {}".format(message, charm_message)
301 else:
302 message = charm_message
303
304
305=== modified file 'hooks/charmhelpers/core/hugepage.py'
306--- hooks/charmhelpers/core/hugepage.py 2015-10-22 13:23:58 +0000
307+++ hooks/charmhelpers/core/hugepage.py 2016-01-07 14:18:30 +0000
308@@ -46,6 +46,8 @@
309 group_info = add_group(group)
310 gid = group_info.gr_gid
311 add_user_to_group(user, group)
312+ if max_map_count < 2 * nr_hugepages:
313+ max_map_count = 2 * nr_hugepages
314 sysctl_settings = {
315 'vm.nr_hugepages': nr_hugepages,
316 'vm.max_map_count': max_map_count,
317
318=== modified file 'tests/charmhelpers/contrib/openstack/amulet/deployment.py'
319--- tests/charmhelpers/contrib/openstack/amulet/deployment.py 2015-10-22 13:23:58 +0000
320+++ tests/charmhelpers/contrib/openstack/amulet/deployment.py 2016-01-07 14:18:30 +0000
321@@ -14,13 +14,18 @@
322 # You should have received a copy of the GNU Lesser General Public License
323 # along with charm-helpers. If not, see <http://www.gnu.org/licenses/>.
324
325+import logging
326 import re
327+import sys
328 import six
329 from collections import OrderedDict
330 from charmhelpers.contrib.amulet.deployment import (
331 AmuletDeployment
332 )
333
334+DEBUG = logging.DEBUG
335+ERROR = logging.ERROR
336+
337
338 class OpenStackAmuletDeployment(AmuletDeployment):
339 """OpenStack amulet deployment.
340@@ -29,9 +34,12 @@
341 that is specifically for use by OpenStack charms.
342 """
343
344- def __init__(self, series=None, openstack=None, source=None, stable=True):
345+ def __init__(self, series=None, openstack=None, source=None,
346+ stable=True, log_level=DEBUG):
347 """Initialize the deployment environment."""
348 super(OpenStackAmuletDeployment, self).__init__(series)
349+ self.log = self.get_logger(level=log_level)
350+ self.log.info('OpenStackAmuletDeployment: init')
351 self.openstack = openstack
352 self.source = source
353 self.stable = stable
354@@ -39,6 +47,22 @@
355 # out.
356 self.current_next = "trusty"
357
358+ def get_logger(self, name="deployment-logger", level=logging.DEBUG):
359+ """Get a logger object that will log to stdout."""
360+ log = logging
361+ logger = log.getLogger(name)
362+ fmt = log.Formatter("%(asctime)s %(funcName)s "
363+ "%(levelname)s: %(message)s")
364+
365+ handler = log.StreamHandler(stream=sys.stdout)
366+ handler.setLevel(level)
367+ handler.setFormatter(fmt)
368+
369+ logger.addHandler(handler)
370+ logger.setLevel(level)
371+
372+ return logger
373+
374 def _determine_branch_locations(self, other_services):
375 """Determine the branch locations for the other services.
376
377@@ -46,6 +70,8 @@
378 stable or next (dev) branch, and based on this, use the corresonding
379 stable or next branches for the other_services."""
380
381+ self.log.info('OpenStackAmuletDeployment: determine branch locations')
382+
383 # Charms outside the lp:~openstack-charmers namespace
384 base_charms = ['mysql', 'mongodb', 'nrpe']
385
386@@ -83,6 +109,8 @@
387
388 def _add_services(self, this_service, other_services):
389 """Add services to the deployment and set openstack-origin/source."""
390+ self.log.info('OpenStackAmuletDeployment: adding services')
391+
392 other_services = self._determine_branch_locations(other_services)
393
394 super(OpenStackAmuletDeployment, self)._add_services(this_service,
395@@ -112,11 +140,12 @@
396
397 def _configure_services(self, configs):
398 """Configure all of the services."""
399+ self.log.info('OpenStackAmuletDeployment: configure services')
400 for service, config in six.iteritems(configs):
401 self.d.configure(service, config)
402
403 def _auto_wait_for_status(self, message=None, exclude_services=None,
404- timeout=1800):
405+ include_only=None, timeout=1800):
406 """Wait for all units to have a specific extended status, except
407 for any defined as excluded. Unless specified via message, any
408 status containing any case of 'ready' will be considered a match.
409@@ -127,7 +156,7 @@
410 message = re.compile('.*ready.*|.*ok.*', re.IGNORECASE)
411
412 Wait for all units to reach this status (exact match):
413- message = 'Unit is ready'
414+ message = re.compile('^Unit is ready and clustered$')
415
416 Wait for all units to reach any one of these (exact match):
417 message = re.compile('Unit is ready|OK|Ready')
418@@ -139,20 +168,50 @@
419 https://github.com/juju/amulet/blob/master/amulet/sentry.py
420
421 :param message: Expected status match
422- :param exclude_services: List of juju service names to ignore
423+ :param exclude_services: List of juju service names to ignore,
424+ not to be used in conjuction with include_only.
425+ :param include_only: List of juju service names to exclusively check,
426+ not to be used in conjuction with exclude_services.
427 :param timeout: Maximum time in seconds to wait for status match
428 :returns: None. Raises if timeout is hit.
429 """
430-
431- if not message:
432+ self.log.info('Waiting for extended status on units...')
433+
434+ all_services = self.d.services.keys()
435+
436+ if exclude_services and include_only:
437+ raise ValueError('exclude_services can not be used '
438+ 'with include_only')
439+
440+ if message:
441+ if isinstance(message, re._pattern_type):
442+ match = message.pattern
443+ else:
444+ match = message
445+
446+ self.log.debug('Custom extended status wait match: '
447+ '{}'.format(match))
448+ else:
449+ self.log.debug('Default extended status wait match: contains '
450+ 'READY (case-insensitive)')
451 message = re.compile('.*ready.*', re.IGNORECASE)
452
453- if not exclude_services:
454+ if exclude_services:
455+ self.log.debug('Excluding services from extended status match: '
456+ '{}'.format(exclude_services))
457+ else:
458 exclude_services = []
459
460- services = list(set(self.d.services.keys()) - set(exclude_services))
461+ if include_only:
462+ services = include_only
463+ else:
464+ services = list(set(all_services) - set(exclude_services))
465+
466+ self.log.debug('Waiting up to {}s for extended status on services: '
467+ '{}'.format(timeout, services))
468 service_messages = {service: message for service in services}
469 self.d.sentry.wait_for_messages(service_messages, timeout=timeout)
470+ self.log.info('OK')
471
472 def _get_openstack_release(self):
473 """Get openstack release.
474
475=== modified file 'tests/charmhelpers/contrib/openstack/amulet/utils.py'
476--- tests/charmhelpers/contrib/openstack/amulet/utils.py 2015-10-22 13:23:58 +0000
477+++ tests/charmhelpers/contrib/openstack/amulet/utils.py 2016-01-07 14:18:30 +0000
478@@ -18,6 +18,7 @@
479 import json
480 import logging
481 import os
482+import re
483 import six
484 import time
485 import urllib
486@@ -604,7 +605,22 @@
487 '{}'.format(sample_type, samples))
488 return None
489
490-# rabbitmq/amqp specific helpers:
491+ # rabbitmq/amqp specific helpers:
492+
493+ def rmq_wait_for_cluster(self, deployment, init_sleep=15, timeout=1200):
494+ """Wait for rmq units extended status to show cluster readiness,
495+ after an optional initial sleep period. Initial sleep is likely
496+ necessary to be effective following a config change, as status
497+ message may not instantly update to non-ready."""
498+
499+ if init_sleep:
500+ time.sleep(init_sleep)
501+
502+ message = re.compile('^Unit is ready and clustered$')
503+ deployment._auto_wait_for_status(message=message,
504+ timeout=timeout,
505+ include_only=['rabbitmq-server'])
506+
507 def add_rmq_test_user(self, sentry_units,
508 username="testuser1", password="changeme"):
509 """Add a test user via the first rmq juju unit, check connection as
510@@ -805,7 +821,10 @@
511 if port:
512 config['ssl_port'] = port
513
514- deployment.configure('rabbitmq-server', config)
515+ deployment.d.configure('rabbitmq-server', config)
516+
517+ # Wait for unit status
518+ self.rmq_wait_for_cluster(deployment)
519
520 # Confirm
521 tries = 0
522@@ -832,7 +851,10 @@
523
524 # Disable RMQ SSL
525 config = {'ssl': 'off'}
526- deployment.configure('rabbitmq-server', config)
527+ deployment.d.configure('rabbitmq-server', config)
528+
529+ # Wait for unit status
530+ self.rmq_wait_for_cluster(deployment)
531
532 # Confirm
533 tries = 0

Subscribers

People subscribed via source and target branches