Merge lp:~1chb1n/charm-helpers/openstack-amulet-ext-stat-wait-update into lp:charm-helpers

Proposed by Ryan Beisner
Status: Merged
Merged at revision: 467
Proposed branch: lp:~1chb1n/charm-helpers/openstack-amulet-ext-stat-wait-update
Merge into: lp:charm-helpers
Diff against target: 216 lines (+92/-11)
2 files modified
charmhelpers/contrib/openstack/amulet/deployment.py (+67/-8)
charmhelpers/contrib/openstack/amulet/utils.py (+25/-3)
To merge this branch: bzr merge lp:~1chb1n/charm-helpers/openstack-amulet-ext-stat-wait-update
Reviewer Review Type Date Requested Status
Liam Young (community) Approve
Review via email: mp+275117@code.launchpad.net

Description of the change

Add logger to openstack/amulet/deployment.py.

Update _auto_wait_for_status with logging feedback and optional include_only logic.

Update rmq test helpers to use extended status message for a readiness indicator.

To post a comment you must log in.
Revision history for this message
Ryan Beisner (1chb1n) wrote :
Revision history for this message
Liam Young (gnuoy) wrote :

Approve

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'charmhelpers/contrib/openstack/amulet/deployment.py'
2--- charmhelpers/contrib/openstack/amulet/deployment.py 2015-10-15 20:34:50 +0000
3+++ charmhelpers/contrib/openstack/amulet/deployment.py 2015-10-21 03:27:04 +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 'charmhelpers/contrib/openstack/amulet/utils.py'
159--- charmhelpers/contrib/openstack/amulet/utils.py 2015-09-28 18:47:55 +0000
160+++ charmhelpers/contrib/openstack/amulet/utils.py 2015-10-21 03:27:04 +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

Subscribers

People subscribed via source and target branches