Merge lp:~james-page/charms/trusty/ceilometer/lp1531102-trunk into lp:~openstack-charmers-archive/charms/trusty/ceilometer/trunk
- Trusty Tahr (14.04)
- lp1531102-trunk
- Merge into trunk
Proposed by
James Page
Status: | Merged | ||||
---|---|---|---|---|---|
Merged at revision: | 91 | ||||
Proposed branch: | lp:~james-page/charms/trusty/ceilometer/lp1531102-trunk | ||||
Merge into: | lp:~openstack-charmers-archive/charms/trusty/ceilometer/trunk | ||||
Diff against target: |
533 lines (+207/-39) 6 files modified
charmhelpers/contrib/openstack/amulet/deployment.py (+67/-8) charmhelpers/contrib/openstack/amulet/utils.py (+25/-3) charmhelpers/contrib/openstack/utils.py (+21/-17) 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/ceilometer/lp1531102-trunk | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Liam Young (community) | Approve | ||
Review via email: mp+281870@code.launchpad.net |
Commit message
Resync helpers
Description of the change
Resync stable charm helpers to resolve liberty point release issues.
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_amulet_test #8568 ceilometer for james-page mp281870
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 'charmhelpers/contrib/openstack/amulet/deployment.py' | |||
2 | --- charmhelpers/contrib/openstack/amulet/deployment.py 2015-10-22 13:17:02 +0000 | |||
3 | +++ charmhelpers/contrib/openstack/amulet/deployment.py 2016-01-07 14:29:51 +0000 | |||
4 | @@ -14,13 +14,18 @@ | |||
5 | 14 | # You should have received a copy of the GNU Lesser General Public License | 14 | # You should have received a copy of the GNU Lesser General Public License |
6 | 15 | # along with charm-helpers. If not, see <http://www.gnu.org/licenses/>. | 15 | # along with charm-helpers. If not, see <http://www.gnu.org/licenses/>. |
7 | 16 | 16 | ||
8 | 17 | import logging | ||
9 | 17 | import re | 18 | import re |
10 | 19 | import sys | ||
11 | 18 | import six | 20 | import six |
12 | 19 | from collections import OrderedDict | 21 | from collections import OrderedDict |
13 | 20 | from charmhelpers.contrib.amulet.deployment import ( | 22 | from charmhelpers.contrib.amulet.deployment import ( |
14 | 21 | AmuletDeployment | 23 | AmuletDeployment |
15 | 22 | ) | 24 | ) |
16 | 23 | 25 | ||
17 | 26 | DEBUG = logging.DEBUG | ||
18 | 27 | ERROR = logging.ERROR | ||
19 | 28 | |||
20 | 24 | 29 | ||
21 | 25 | class OpenStackAmuletDeployment(AmuletDeployment): | 30 | class OpenStackAmuletDeployment(AmuletDeployment): |
22 | 26 | """OpenStack amulet deployment. | 31 | """OpenStack amulet deployment. |
23 | @@ -29,9 +34,12 @@ | |||
24 | 29 | that is specifically for use by OpenStack charms. | 34 | that is specifically for use by OpenStack charms. |
25 | 30 | """ | 35 | """ |
26 | 31 | 36 | ||
28 | 32 | def __init__(self, series=None, openstack=None, source=None, stable=True): | 37 | def __init__(self, series=None, openstack=None, source=None, |
29 | 38 | stable=True, log_level=DEBUG): | ||
30 | 33 | """Initialize the deployment environment.""" | 39 | """Initialize the deployment environment.""" |
31 | 34 | super(OpenStackAmuletDeployment, self).__init__(series) | 40 | super(OpenStackAmuletDeployment, self).__init__(series) |
32 | 41 | self.log = self.get_logger(level=log_level) | ||
33 | 42 | self.log.info('OpenStackAmuletDeployment: init') | ||
34 | 35 | self.openstack = openstack | 43 | self.openstack = openstack |
35 | 36 | self.source = source | 44 | self.source = source |
36 | 37 | self.stable = stable | 45 | self.stable = stable |
37 | @@ -39,6 +47,22 @@ | |||
38 | 39 | # out. | 47 | # out. |
39 | 40 | self.current_next = "trusty" | 48 | self.current_next = "trusty" |
40 | 41 | 49 | ||
41 | 50 | def get_logger(self, name="deployment-logger", level=logging.DEBUG): | ||
42 | 51 | """Get a logger object that will log to stdout.""" | ||
43 | 52 | log = logging | ||
44 | 53 | logger = log.getLogger(name) | ||
45 | 54 | fmt = log.Formatter("%(asctime)s %(funcName)s " | ||
46 | 55 | "%(levelname)s: %(message)s") | ||
47 | 56 | |||
48 | 57 | handler = log.StreamHandler(stream=sys.stdout) | ||
49 | 58 | handler.setLevel(level) | ||
50 | 59 | handler.setFormatter(fmt) | ||
51 | 60 | |||
52 | 61 | logger.addHandler(handler) | ||
53 | 62 | logger.setLevel(level) | ||
54 | 63 | |||
55 | 64 | return logger | ||
56 | 65 | |||
57 | 42 | def _determine_branch_locations(self, other_services): | 66 | def _determine_branch_locations(self, other_services): |
58 | 43 | """Determine the branch locations for the other services. | 67 | """Determine the branch locations for the other services. |
59 | 44 | 68 | ||
60 | @@ -46,6 +70,8 @@ | |||
61 | 46 | stable or next (dev) branch, and based on this, use the corresonding | 70 | stable or next (dev) branch, and based on this, use the corresonding |
62 | 47 | stable or next branches for the other_services.""" | 71 | stable or next branches for the other_services.""" |
63 | 48 | 72 | ||
64 | 73 | self.log.info('OpenStackAmuletDeployment: determine branch locations') | ||
65 | 74 | |||
66 | 49 | # Charms outside the lp:~openstack-charmers namespace | 75 | # Charms outside the lp:~openstack-charmers namespace |
67 | 50 | base_charms = ['mysql', 'mongodb', 'nrpe'] | 76 | base_charms = ['mysql', 'mongodb', 'nrpe'] |
68 | 51 | 77 | ||
69 | @@ -83,6 +109,8 @@ | |||
70 | 83 | 109 | ||
71 | 84 | def _add_services(self, this_service, other_services): | 110 | def _add_services(self, this_service, other_services): |
72 | 85 | """Add services to the deployment and set openstack-origin/source.""" | 111 | """Add services to the deployment and set openstack-origin/source.""" |
73 | 112 | self.log.info('OpenStackAmuletDeployment: adding services') | ||
74 | 113 | |||
75 | 86 | other_services = self._determine_branch_locations(other_services) | 114 | other_services = self._determine_branch_locations(other_services) |
76 | 87 | 115 | ||
77 | 88 | super(OpenStackAmuletDeployment, self)._add_services(this_service, | 116 | super(OpenStackAmuletDeployment, self)._add_services(this_service, |
78 | @@ -112,11 +140,12 @@ | |||
79 | 112 | 140 | ||
80 | 113 | def _configure_services(self, configs): | 141 | def _configure_services(self, configs): |
81 | 114 | """Configure all of the services.""" | 142 | """Configure all of the services.""" |
82 | 143 | self.log.info('OpenStackAmuletDeployment: configure services') | ||
83 | 115 | for service, config in six.iteritems(configs): | 144 | for service, config in six.iteritems(configs): |
84 | 116 | self.d.configure(service, config) | 145 | self.d.configure(service, config) |
85 | 117 | 146 | ||
86 | 118 | def _auto_wait_for_status(self, message=None, exclude_services=None, | 147 | def _auto_wait_for_status(self, message=None, exclude_services=None, |
88 | 119 | timeout=1800): | 148 | include_only=None, timeout=1800): |
89 | 120 | """Wait for all units to have a specific extended status, except | 149 | """Wait for all units to have a specific extended status, except |
90 | 121 | for any defined as excluded. Unless specified via message, any | 150 | for any defined as excluded. Unless specified via message, any |
91 | 122 | status containing any case of 'ready' will be considered a match. | 151 | status containing any case of 'ready' will be considered a match. |
92 | @@ -127,7 +156,7 @@ | |||
93 | 127 | message = re.compile('.*ready.*|.*ok.*', re.IGNORECASE) | 156 | message = re.compile('.*ready.*|.*ok.*', re.IGNORECASE) |
94 | 128 | 157 | ||
95 | 129 | Wait for all units to reach this status (exact match): | 158 | Wait for all units to reach this status (exact match): |
97 | 130 | message = 'Unit is ready' | 159 | message = re.compile('^Unit is ready and clustered$') |
98 | 131 | 160 | ||
99 | 132 | Wait for all units to reach any one of these (exact match): | 161 | Wait for all units to reach any one of these (exact match): |
100 | 133 | message = re.compile('Unit is ready|OK|Ready') | 162 | message = re.compile('Unit is ready|OK|Ready') |
101 | @@ -139,20 +168,50 @@ | |||
102 | 139 | https://github.com/juju/amulet/blob/master/amulet/sentry.py | 168 | https://github.com/juju/amulet/blob/master/amulet/sentry.py |
103 | 140 | 169 | ||
104 | 141 | :param message: Expected status match | 170 | :param message: Expected status match |
106 | 142 | :param exclude_services: List of juju service names to ignore | 171 | :param exclude_services: List of juju service names to ignore, |
107 | 172 | not to be used in conjuction with include_only. | ||
108 | 173 | :param include_only: List of juju service names to exclusively check, | ||
109 | 174 | not to be used in conjuction with exclude_services. | ||
110 | 143 | :param timeout: Maximum time in seconds to wait for status match | 175 | :param timeout: Maximum time in seconds to wait for status match |
111 | 144 | :returns: None. Raises if timeout is hit. | 176 | :returns: None. Raises if timeout is hit. |
112 | 145 | """ | 177 | """ |
115 | 146 | 178 | self.log.info('Waiting for extended status on units...') | |
116 | 147 | if not message: | 179 | |
117 | 180 | all_services = self.d.services.keys() | ||
118 | 181 | |||
119 | 182 | if exclude_services and include_only: | ||
120 | 183 | raise ValueError('exclude_services can not be used ' | ||
121 | 184 | 'with include_only') | ||
122 | 185 | |||
123 | 186 | if message: | ||
124 | 187 | if isinstance(message, re._pattern_type): | ||
125 | 188 | match = message.pattern | ||
126 | 189 | else: | ||
127 | 190 | match = message | ||
128 | 191 | |||
129 | 192 | self.log.debug('Custom extended status wait match: ' | ||
130 | 193 | '{}'.format(match)) | ||
131 | 194 | else: | ||
132 | 195 | self.log.debug('Default extended status wait match: contains ' | ||
133 | 196 | 'READY (case-insensitive)') | ||
134 | 148 | message = re.compile('.*ready.*', re.IGNORECASE) | 197 | message = re.compile('.*ready.*', re.IGNORECASE) |
135 | 149 | 198 | ||
137 | 150 | if not exclude_services: | 199 | if exclude_services: |
138 | 200 | self.log.debug('Excluding services from extended status match: ' | ||
139 | 201 | '{}'.format(exclude_services)) | ||
140 | 202 | else: | ||
141 | 151 | exclude_services = [] | 203 | exclude_services = [] |
142 | 152 | 204 | ||
144 | 153 | services = list(set(self.d.services.keys()) - set(exclude_services)) | 205 | if include_only: |
145 | 206 | services = include_only | ||
146 | 207 | else: | ||
147 | 208 | services = list(set(all_services) - set(exclude_services)) | ||
148 | 209 | |||
149 | 210 | self.log.debug('Waiting up to {}s for extended status on services: ' | ||
150 | 211 | '{}'.format(timeout, services)) | ||
151 | 154 | service_messages = {service: message for service in services} | 212 | service_messages = {service: message for service in services} |
152 | 155 | self.d.sentry.wait_for_messages(service_messages, timeout=timeout) | 213 | self.d.sentry.wait_for_messages(service_messages, timeout=timeout) |
153 | 214 | self.log.info('OK') | ||
154 | 156 | 215 | ||
155 | 157 | def _get_openstack_release(self): | 216 | def _get_openstack_release(self): |
156 | 158 | """Get openstack release. | 217 | """Get openstack release. |
157 | 159 | 218 | ||
158 | === modified file 'charmhelpers/contrib/openstack/amulet/utils.py' | |||
159 | --- charmhelpers/contrib/openstack/amulet/utils.py 2015-10-22 13:17:02 +0000 | |||
160 | +++ charmhelpers/contrib/openstack/amulet/utils.py 2016-01-07 14:29:51 +0000 | |||
161 | @@ -18,6 +18,7 @@ | |||
162 | 18 | import json | 18 | import json |
163 | 19 | import logging | 19 | import logging |
164 | 20 | import os | 20 | import os |
165 | 21 | import re | ||
166 | 21 | import six | 22 | import six |
167 | 22 | import time | 23 | import time |
168 | 23 | import urllib | 24 | import urllib |
169 | @@ -604,7 +605,22 @@ | |||
170 | 604 | '{}'.format(sample_type, samples)) | 605 | '{}'.format(sample_type, samples)) |
171 | 605 | return None | 606 | return None |
172 | 606 | 607 | ||
174 | 607 | # rabbitmq/amqp specific helpers: | 608 | # rabbitmq/amqp specific helpers: |
175 | 609 | |||
176 | 610 | def rmq_wait_for_cluster(self, deployment, init_sleep=15, timeout=1200): | ||
177 | 611 | """Wait for rmq units extended status to show cluster readiness, | ||
178 | 612 | after an optional initial sleep period. Initial sleep is likely | ||
179 | 613 | necessary to be effective following a config change, as status | ||
180 | 614 | message may not instantly update to non-ready.""" | ||
181 | 615 | |||
182 | 616 | if init_sleep: | ||
183 | 617 | time.sleep(init_sleep) | ||
184 | 618 | |||
185 | 619 | message = re.compile('^Unit is ready and clustered$') | ||
186 | 620 | deployment._auto_wait_for_status(message=message, | ||
187 | 621 | timeout=timeout, | ||
188 | 622 | include_only=['rabbitmq-server']) | ||
189 | 623 | |||
190 | 608 | def add_rmq_test_user(self, sentry_units, | 624 | def add_rmq_test_user(self, sentry_units, |
191 | 609 | username="testuser1", password="changeme"): | 625 | username="testuser1", password="changeme"): |
192 | 610 | """Add a test user via the first rmq juju unit, check connection as | 626 | """Add a test user via the first rmq juju unit, check connection as |
193 | @@ -805,7 +821,10 @@ | |||
194 | 805 | if port: | 821 | if port: |
195 | 806 | config['ssl_port'] = port | 822 | config['ssl_port'] = port |
196 | 807 | 823 | ||
198 | 808 | deployment.configure('rabbitmq-server', config) | 824 | deployment.d.configure('rabbitmq-server', config) |
199 | 825 | |||
200 | 826 | # Wait for unit status | ||
201 | 827 | self.rmq_wait_for_cluster(deployment) | ||
202 | 809 | 828 | ||
203 | 810 | # Confirm | 829 | # Confirm |
204 | 811 | tries = 0 | 830 | tries = 0 |
205 | @@ -832,7 +851,10 @@ | |||
206 | 832 | 851 | ||
207 | 833 | # Disable RMQ SSL | 852 | # Disable RMQ SSL |
208 | 834 | config = {'ssl': 'off'} | 853 | config = {'ssl': 'off'} |
210 | 835 | deployment.configure('rabbitmq-server', config) | 854 | deployment.d.configure('rabbitmq-server', config) |
211 | 855 | |||
212 | 856 | # Wait for unit status | ||
213 | 857 | self.rmq_wait_for_cluster(deployment) | ||
214 | 836 | 858 | ||
215 | 837 | # Confirm | 859 | # Confirm |
216 | 838 | tries = 0 | 860 | tries = 0 |
217 | 839 | 861 | ||
218 | === modified file 'charmhelpers/contrib/openstack/utils.py' | |||
219 | --- charmhelpers/contrib/openstack/utils.py 2015-10-22 13:17:02 +0000 | |||
220 | +++ charmhelpers/contrib/openstack/utils.py 2016-01-07 14:29:51 +0000 | |||
221 | @@ -127,31 +127,31 @@ | |||
222 | 127 | # >= Liberty version->codename mapping | 127 | # >= Liberty version->codename mapping |
223 | 128 | PACKAGE_CODENAMES = { | 128 | PACKAGE_CODENAMES = { |
224 | 129 | 'nova-common': OrderedDict([ | 129 | 'nova-common': OrderedDict([ |
226 | 130 | ('12.0.0', 'liberty'), | 130 | ('12.0', 'liberty'), |
227 | 131 | ]), | 131 | ]), |
228 | 132 | 'neutron-common': OrderedDict([ | 132 | 'neutron-common': OrderedDict([ |
230 | 133 | ('7.0.0', 'liberty'), | 133 | ('7.0', 'liberty'), |
231 | 134 | ]), | 134 | ]), |
232 | 135 | 'cinder-common': OrderedDict([ | 135 | 'cinder-common': OrderedDict([ |
234 | 136 | ('7.0.0', 'liberty'), | 136 | ('7.0', 'liberty'), |
235 | 137 | ]), | 137 | ]), |
236 | 138 | 'keystone': OrderedDict([ | 138 | 'keystone': OrderedDict([ |
238 | 139 | ('8.0.0', 'liberty'), | 139 | ('8.0', 'liberty'), |
239 | 140 | ]), | 140 | ]), |
240 | 141 | 'horizon-common': OrderedDict([ | 141 | 'horizon-common': OrderedDict([ |
242 | 142 | ('8.0.0', 'liberty'), | 142 | ('8.0', 'liberty'), |
243 | 143 | ]), | 143 | ]), |
244 | 144 | 'ceilometer-common': OrderedDict([ | 144 | 'ceilometer-common': OrderedDict([ |
246 | 145 | ('5.0.0', 'liberty'), | 145 | ('5.0', 'liberty'), |
247 | 146 | ]), | 146 | ]), |
248 | 147 | 'heat-common': OrderedDict([ | 147 | 'heat-common': OrderedDict([ |
250 | 148 | ('5.0.0', 'liberty'), | 148 | ('5.0', 'liberty'), |
251 | 149 | ]), | 149 | ]), |
252 | 150 | 'glance-common': OrderedDict([ | 150 | 'glance-common': OrderedDict([ |
254 | 151 | ('11.0.0', 'liberty'), | 151 | ('11.0', 'liberty'), |
255 | 152 | ]), | 152 | ]), |
256 | 153 | 'openstack-dashboard': OrderedDict([ | 153 | 'openstack-dashboard': OrderedDict([ |
258 | 154 | ('8.0.0', 'liberty'), | 154 | ('8.0', 'liberty'), |
259 | 155 | ]), | 155 | ]), |
260 | 156 | } | 156 | } |
261 | 157 | 157 | ||
262 | @@ -238,7 +238,14 @@ | |||
263 | 238 | error_out(e) | 238 | error_out(e) |
264 | 239 | 239 | ||
265 | 240 | vers = apt.upstream_version(pkg.current_ver.ver_str) | 240 | vers = apt.upstream_version(pkg.current_ver.ver_str) |
267 | 241 | match = re.match('^(\d+)\.(\d+)\.(\d+)', vers) | 241 | if 'swift' in pkg.name: |
268 | 242 | # Fully x.y.z match for swift versions | ||
269 | 243 | match = re.match('^(\d+)\.(\d+)\.(\d+)', vers) | ||
270 | 244 | else: | ||
271 | 245 | # x.y match only for 20XX.X | ||
272 | 246 | # and ignore patch level for other packages | ||
273 | 247 | match = re.match('^(\d+)\.(\d+)', vers) | ||
274 | 248 | |||
275 | 242 | if match: | 249 | if match: |
276 | 243 | vers = match.group(0) | 250 | vers = match.group(0) |
277 | 244 | 251 | ||
278 | @@ -250,13 +257,8 @@ | |||
279 | 250 | # < Liberty co-ordinated project versions | 257 | # < Liberty co-ordinated project versions |
280 | 251 | try: | 258 | try: |
281 | 252 | if 'swift' in pkg.name: | 259 | if 'swift' in pkg.name: |
287 | 253 | swift_vers = vers[:5] | 260 | return SWIFT_CODENAMES[vers] |
283 | 254 | if swift_vers not in SWIFT_CODENAMES: | ||
284 | 255 | # Deal with 1.10.0 upward | ||
285 | 256 | swift_vers = vers[:6] | ||
286 | 257 | return SWIFT_CODENAMES[swift_vers] | ||
288 | 258 | else: | 261 | else: |
289 | 259 | vers = vers[:6] | ||
290 | 260 | return OPENSTACK_CODENAMES[vers] | 262 | return OPENSTACK_CODENAMES[vers] |
291 | 261 | except KeyError: | 263 | except KeyError: |
292 | 262 | if not fatal: | 264 | if not fatal: |
293 | @@ -859,7 +861,9 @@ | |||
294 | 859 | if charm_state != 'active' and charm_state != 'unknown': | 861 | if charm_state != 'active' and charm_state != 'unknown': |
295 | 860 | state = workload_state_compare(state, charm_state) | 862 | state = workload_state_compare(state, charm_state) |
296 | 861 | if message: | 863 | if message: |
298 | 862 | message = "{} {}".format(message, charm_message) | 864 | charm_message = charm_message.replace("Incomplete relations: ", |
299 | 865 | "") | ||
300 | 866 | message = "{}, {}".format(message, charm_message) | ||
301 | 863 | else: | 867 | else: |
302 | 864 | message = charm_message | 868 | message = charm_message |
303 | 865 | 869 | ||
304 | 866 | 870 | ||
305 | === modified file 'charmhelpers/core/hugepage.py' | |||
306 | --- charmhelpers/core/hugepage.py 2015-10-22 13:17:02 +0000 | |||
307 | +++ charmhelpers/core/hugepage.py 2016-01-07 14:29:51 +0000 | |||
308 | @@ -46,6 +46,8 @@ | |||
309 | 46 | group_info = add_group(group) | 46 | group_info = add_group(group) |
310 | 47 | gid = group_info.gr_gid | 47 | gid = group_info.gr_gid |
311 | 48 | add_user_to_group(user, group) | 48 | add_user_to_group(user, group) |
312 | 49 | if max_map_count < 2 * nr_hugepages: | ||
313 | 50 | max_map_count = 2 * nr_hugepages | ||
314 | 49 | sysctl_settings = { | 51 | sysctl_settings = { |
315 | 50 | 'vm.nr_hugepages': nr_hugepages, | 52 | 'vm.nr_hugepages': nr_hugepages, |
316 | 51 | 'vm.max_map_count': max_map_count, | 53 | 'vm.max_map_count': max_map_count, |
317 | 52 | 54 | ||
318 | === modified file 'tests/charmhelpers/contrib/openstack/amulet/deployment.py' | |||
319 | --- tests/charmhelpers/contrib/openstack/amulet/deployment.py 2015-10-22 13:17:02 +0000 | |||
320 | +++ tests/charmhelpers/contrib/openstack/amulet/deployment.py 2016-01-07 14:29:51 +0000 | |||
321 | @@ -14,13 +14,18 @@ | |||
322 | 14 | # You should have received a copy of the GNU Lesser General Public License | 14 | # You should have received a copy of the GNU Lesser General Public License |
323 | 15 | # along with charm-helpers. If not, see <http://www.gnu.org/licenses/>. | 15 | # along with charm-helpers. If not, see <http://www.gnu.org/licenses/>. |
324 | 16 | 16 | ||
325 | 17 | import logging | ||
326 | 17 | import re | 18 | import re |
327 | 19 | import sys | ||
328 | 18 | import six | 20 | import six |
329 | 19 | from collections import OrderedDict | 21 | from collections import OrderedDict |
330 | 20 | from charmhelpers.contrib.amulet.deployment import ( | 22 | from charmhelpers.contrib.amulet.deployment import ( |
331 | 21 | AmuletDeployment | 23 | AmuletDeployment |
332 | 22 | ) | 24 | ) |
333 | 23 | 25 | ||
334 | 26 | DEBUG = logging.DEBUG | ||
335 | 27 | ERROR = logging.ERROR | ||
336 | 28 | |||
337 | 24 | 29 | ||
338 | 25 | class OpenStackAmuletDeployment(AmuletDeployment): | 30 | class OpenStackAmuletDeployment(AmuletDeployment): |
339 | 26 | """OpenStack amulet deployment. | 31 | """OpenStack amulet deployment. |
340 | @@ -29,9 +34,12 @@ | |||
341 | 29 | that is specifically for use by OpenStack charms. | 34 | that is specifically for use by OpenStack charms. |
342 | 30 | """ | 35 | """ |
343 | 31 | 36 | ||
345 | 32 | def __init__(self, series=None, openstack=None, source=None, stable=True): | 37 | def __init__(self, series=None, openstack=None, source=None, |
346 | 38 | stable=True, log_level=DEBUG): | ||
347 | 33 | """Initialize the deployment environment.""" | 39 | """Initialize the deployment environment.""" |
348 | 34 | super(OpenStackAmuletDeployment, self).__init__(series) | 40 | super(OpenStackAmuletDeployment, self).__init__(series) |
349 | 41 | self.log = self.get_logger(level=log_level) | ||
350 | 42 | self.log.info('OpenStackAmuletDeployment: init') | ||
351 | 35 | self.openstack = openstack | 43 | self.openstack = openstack |
352 | 36 | self.source = source | 44 | self.source = source |
353 | 37 | self.stable = stable | 45 | self.stable = stable |
354 | @@ -39,6 +47,22 @@ | |||
355 | 39 | # out. | 47 | # out. |
356 | 40 | self.current_next = "trusty" | 48 | self.current_next = "trusty" |
357 | 41 | 49 | ||
358 | 50 | def get_logger(self, name="deployment-logger", level=logging.DEBUG): | ||
359 | 51 | """Get a logger object that will log to stdout.""" | ||
360 | 52 | log = logging | ||
361 | 53 | logger = log.getLogger(name) | ||
362 | 54 | fmt = log.Formatter("%(asctime)s %(funcName)s " | ||
363 | 55 | "%(levelname)s: %(message)s") | ||
364 | 56 | |||
365 | 57 | handler = log.StreamHandler(stream=sys.stdout) | ||
366 | 58 | handler.setLevel(level) | ||
367 | 59 | handler.setFormatter(fmt) | ||
368 | 60 | |||
369 | 61 | logger.addHandler(handler) | ||
370 | 62 | logger.setLevel(level) | ||
371 | 63 | |||
372 | 64 | return logger | ||
373 | 65 | |||
374 | 42 | def _determine_branch_locations(self, other_services): | 66 | def _determine_branch_locations(self, other_services): |
375 | 43 | """Determine the branch locations for the other services. | 67 | """Determine the branch locations for the other services. |
376 | 44 | 68 | ||
377 | @@ -46,6 +70,8 @@ | |||
378 | 46 | stable or next (dev) branch, and based on this, use the corresonding | 70 | stable or next (dev) branch, and based on this, use the corresonding |
379 | 47 | stable or next branches for the other_services.""" | 71 | stable or next branches for the other_services.""" |
380 | 48 | 72 | ||
381 | 73 | self.log.info('OpenStackAmuletDeployment: determine branch locations') | ||
382 | 74 | |||
383 | 49 | # Charms outside the lp:~openstack-charmers namespace | 75 | # Charms outside the lp:~openstack-charmers namespace |
384 | 50 | base_charms = ['mysql', 'mongodb', 'nrpe'] | 76 | base_charms = ['mysql', 'mongodb', 'nrpe'] |
385 | 51 | 77 | ||
386 | @@ -83,6 +109,8 @@ | |||
387 | 83 | 109 | ||
388 | 84 | def _add_services(self, this_service, other_services): | 110 | def _add_services(self, this_service, other_services): |
389 | 85 | """Add services to the deployment and set openstack-origin/source.""" | 111 | """Add services to the deployment and set openstack-origin/source.""" |
390 | 112 | self.log.info('OpenStackAmuletDeployment: adding services') | ||
391 | 113 | |||
392 | 86 | other_services = self._determine_branch_locations(other_services) | 114 | other_services = self._determine_branch_locations(other_services) |
393 | 87 | 115 | ||
394 | 88 | super(OpenStackAmuletDeployment, self)._add_services(this_service, | 116 | super(OpenStackAmuletDeployment, self)._add_services(this_service, |
395 | @@ -112,11 +140,12 @@ | |||
396 | 112 | 140 | ||
397 | 113 | def _configure_services(self, configs): | 141 | def _configure_services(self, configs): |
398 | 114 | """Configure all of the services.""" | 142 | """Configure all of the services.""" |
399 | 143 | self.log.info('OpenStackAmuletDeployment: configure services') | ||
400 | 115 | for service, config in six.iteritems(configs): | 144 | for service, config in six.iteritems(configs): |
401 | 116 | self.d.configure(service, config) | 145 | self.d.configure(service, config) |
402 | 117 | 146 | ||
403 | 118 | def _auto_wait_for_status(self, message=None, exclude_services=None, | 147 | def _auto_wait_for_status(self, message=None, exclude_services=None, |
405 | 119 | timeout=1800): | 148 | include_only=None, timeout=1800): |
406 | 120 | """Wait for all units to have a specific extended status, except | 149 | """Wait for all units to have a specific extended status, except |
407 | 121 | for any defined as excluded. Unless specified via message, any | 150 | for any defined as excluded. Unless specified via message, any |
408 | 122 | status containing any case of 'ready' will be considered a match. | 151 | status containing any case of 'ready' will be considered a match. |
409 | @@ -127,7 +156,7 @@ | |||
410 | 127 | message = re.compile('.*ready.*|.*ok.*', re.IGNORECASE) | 156 | message = re.compile('.*ready.*|.*ok.*', re.IGNORECASE) |
411 | 128 | 157 | ||
412 | 129 | Wait for all units to reach this status (exact match): | 158 | Wait for all units to reach this status (exact match): |
414 | 130 | message = 'Unit is ready' | 159 | message = re.compile('^Unit is ready and clustered$') |
415 | 131 | 160 | ||
416 | 132 | Wait for all units to reach any one of these (exact match): | 161 | Wait for all units to reach any one of these (exact match): |
417 | 133 | message = re.compile('Unit is ready|OK|Ready') | 162 | message = re.compile('Unit is ready|OK|Ready') |
418 | @@ -139,20 +168,50 @@ | |||
419 | 139 | https://github.com/juju/amulet/blob/master/amulet/sentry.py | 168 | https://github.com/juju/amulet/blob/master/amulet/sentry.py |
420 | 140 | 169 | ||
421 | 141 | :param message: Expected status match | 170 | :param message: Expected status match |
423 | 142 | :param exclude_services: List of juju service names to ignore | 171 | :param exclude_services: List of juju service names to ignore, |
424 | 172 | not to be used in conjuction with include_only. | ||
425 | 173 | :param include_only: List of juju service names to exclusively check, | ||
426 | 174 | not to be used in conjuction with exclude_services. | ||
427 | 143 | :param timeout: Maximum time in seconds to wait for status match | 175 | :param timeout: Maximum time in seconds to wait for status match |
428 | 144 | :returns: None. Raises if timeout is hit. | 176 | :returns: None. Raises if timeout is hit. |
429 | 145 | """ | 177 | """ |
432 | 146 | 178 | self.log.info('Waiting for extended status on units...') | |
433 | 147 | if not message: | 179 | |
434 | 180 | all_services = self.d.services.keys() | ||
435 | 181 | |||
436 | 182 | if exclude_services and include_only: | ||
437 | 183 | raise ValueError('exclude_services can not be used ' | ||
438 | 184 | 'with include_only') | ||
439 | 185 | |||
440 | 186 | if message: | ||
441 | 187 | if isinstance(message, re._pattern_type): | ||
442 | 188 | match = message.pattern | ||
443 | 189 | else: | ||
444 | 190 | match = message | ||
445 | 191 | |||
446 | 192 | self.log.debug('Custom extended status wait match: ' | ||
447 | 193 | '{}'.format(match)) | ||
448 | 194 | else: | ||
449 | 195 | self.log.debug('Default extended status wait match: contains ' | ||
450 | 196 | 'READY (case-insensitive)') | ||
451 | 148 | message = re.compile('.*ready.*', re.IGNORECASE) | 197 | message = re.compile('.*ready.*', re.IGNORECASE) |
452 | 149 | 198 | ||
454 | 150 | if not exclude_services: | 199 | if exclude_services: |
455 | 200 | self.log.debug('Excluding services from extended status match: ' | ||
456 | 201 | '{}'.format(exclude_services)) | ||
457 | 202 | else: | ||
458 | 151 | exclude_services = [] | 203 | exclude_services = [] |
459 | 152 | 204 | ||
461 | 153 | services = list(set(self.d.services.keys()) - set(exclude_services)) | 205 | if include_only: |
462 | 206 | services = include_only | ||
463 | 207 | else: | ||
464 | 208 | services = list(set(all_services) - set(exclude_services)) | ||
465 | 209 | |||
466 | 210 | self.log.debug('Waiting up to {}s for extended status on services: ' | ||
467 | 211 | '{}'.format(timeout, services)) | ||
468 | 154 | service_messages = {service: message for service in services} | 212 | service_messages = {service: message for service in services} |
469 | 155 | self.d.sentry.wait_for_messages(service_messages, timeout=timeout) | 213 | self.d.sentry.wait_for_messages(service_messages, timeout=timeout) |
470 | 214 | self.log.info('OK') | ||
471 | 156 | 215 | ||
472 | 157 | def _get_openstack_release(self): | 216 | def _get_openstack_release(self): |
473 | 158 | """Get openstack release. | 217 | """Get openstack release. |
474 | 159 | 218 | ||
475 | === modified file 'tests/charmhelpers/contrib/openstack/amulet/utils.py' | |||
476 | --- tests/charmhelpers/contrib/openstack/amulet/utils.py 2015-10-22 13:17:02 +0000 | |||
477 | +++ tests/charmhelpers/contrib/openstack/amulet/utils.py 2016-01-07 14:29:51 +0000 | |||
478 | @@ -18,6 +18,7 @@ | |||
479 | 18 | import json | 18 | import json |
480 | 19 | import logging | 19 | import logging |
481 | 20 | import os | 20 | import os |
482 | 21 | import re | ||
483 | 21 | import six | 22 | import six |
484 | 22 | import time | 23 | import time |
485 | 23 | import urllib | 24 | import urllib |
486 | @@ -604,7 +605,22 @@ | |||
487 | 604 | '{}'.format(sample_type, samples)) | 605 | '{}'.format(sample_type, samples)) |
488 | 605 | return None | 606 | return None |
489 | 606 | 607 | ||
491 | 607 | # rabbitmq/amqp specific helpers: | 608 | # rabbitmq/amqp specific helpers: |
492 | 609 | |||
493 | 610 | def rmq_wait_for_cluster(self, deployment, init_sleep=15, timeout=1200): | ||
494 | 611 | """Wait for rmq units extended status to show cluster readiness, | ||
495 | 612 | after an optional initial sleep period. Initial sleep is likely | ||
496 | 613 | necessary to be effective following a config change, as status | ||
497 | 614 | message may not instantly update to non-ready.""" | ||
498 | 615 | |||
499 | 616 | if init_sleep: | ||
500 | 617 | time.sleep(init_sleep) | ||
501 | 618 | |||
502 | 619 | message = re.compile('^Unit is ready and clustered$') | ||
503 | 620 | deployment._auto_wait_for_status(message=message, | ||
504 | 621 | timeout=timeout, | ||
505 | 622 | include_only=['rabbitmq-server']) | ||
506 | 623 | |||
507 | 608 | def add_rmq_test_user(self, sentry_units, | 624 | def add_rmq_test_user(self, sentry_units, |
508 | 609 | username="testuser1", password="changeme"): | 625 | username="testuser1", password="changeme"): |
509 | 610 | """Add a test user via the first rmq juju unit, check connection as | 626 | """Add a test user via the first rmq juju unit, check connection as |
510 | @@ -805,7 +821,10 @@ | |||
511 | 805 | if port: | 821 | if port: |
512 | 806 | config['ssl_port'] = port | 822 | config['ssl_port'] = port |
513 | 807 | 823 | ||
515 | 808 | deployment.configure('rabbitmq-server', config) | 824 | deployment.d.configure('rabbitmq-server', config) |
516 | 825 | |||
517 | 826 | # Wait for unit status | ||
518 | 827 | self.rmq_wait_for_cluster(deployment) | ||
519 | 809 | 828 | ||
520 | 810 | # Confirm | 829 | # Confirm |
521 | 811 | tries = 0 | 830 | tries = 0 |
522 | @@ -832,7 +851,10 @@ | |||
523 | 832 | 851 | ||
524 | 833 | # Disable RMQ SSL | 852 | # Disable RMQ SSL |
525 | 834 | config = {'ssl': 'off'} | 853 | config = {'ssl': 'off'} |
527 | 835 | deployment.configure('rabbitmq-server', config) | 854 | deployment.d.configure('rabbitmq-server', config) |
528 | 855 | |||
529 | 856 | # Wait for unit status | ||
530 | 857 | self.rmq_wait_for_cluster(deployment) | ||
531 | 836 | 858 | ||
532 | 837 | # Confirm | 859 | # Confirm |
533 | 838 | tries = 0 | 860 | tries = 0 |
charm_lint_check #16738 ceilometer for james-page mp281870
LINT OK: passed
Build: http:// 10.245. 162.77: 8080/job/ charm_lint_ check/16738/