Merge lp:~fcorrea/charms/trusty/glance/fix-pause-action into lp:~openstack-charmers-archive/charms/trusty/glance/next
- Trusty Tahr (14.04)
- fix-pause-action
- Merge into next
Status: | Merged |
---|---|
Merge reported by: | James Page |
Merged at revision: | not available |
Proposed branch: | lp:~fcorrea/charms/trusty/glance/fix-pause-action |
Merge into: | lp:~openstack-charmers-archive/charms/trusty/glance/next |
Diff against target: |
1327 lines (+543/-93) 20 files modified
actions/actions.py (+6/-3) charmhelpers/cli/__init__.py (+3/-3) charmhelpers/contrib/charmsupport/nrpe.py (+44/-8) charmhelpers/contrib/openstack/amulet/deployment.py (+102/-2) charmhelpers/contrib/openstack/amulet/utils.py (+25/-3) charmhelpers/contrib/openstack/context.py (+39/-9) charmhelpers/contrib/openstack/neutron.py (+16/-2) charmhelpers/contrib/openstack/utils.py (+22/-1) charmhelpers/contrib/storage/linux/ceph.py (+51/-35) charmhelpers/core/hookenv.py (+16/-2) charmhelpers/core/host.py (+34/-3) charmhelpers/core/hugepage.py (+2/-0) charmhelpers/core/services/helpers.py (+5/-2) charmhelpers/core/templating.py (+13/-6) charmhelpers/fetch/__init__.py (+1/-1) charmhelpers/fetch/bzrurl.py (+7/-3) hooks/glance_utils.py (+20/-0) tests/charmhelpers/contrib/openstack/amulet/deployment.py (+102/-2) tests/charmhelpers/contrib/openstack/amulet/utils.py (+25/-3) unit_tests/test_actions.py (+10/-5) |
To merge this branch: | bzr merge lp:~fcorrea/charms/trusty/glance/fix-pause-action |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Chad Smith | Pending | ||
Review via email: mp+278505@code.launchpad.net |
This proposal supersedes a proposal from 2015-11-24.
Commit message
Description of the change
This branch changes the pause action to change the kv database instead of calling set_os_
This prevents the charm from immediately bouncing back to active after a 'pause' action was performed.
A follow up branch will add a bit more logic to deal with hacluster so it stops sending requests for the unit.
uosci-testing-bot (uosci-testing-bot) wrote : Posted in a previous version of this proposal | # |
uosci-testing-bot (uosci-testing-bot) wrote : Posted in a previous version of this proposal | # |
charm_unit_test #13339 glance for fcorrea mp278498
UNIT OK: passed
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_lint_check #14312 glance-next for fcorrea mp278505
LINT OK: passed
Build: http://
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_unit_test #13340 glance-next for fcorrea mp278505
UNIT OK: passed
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_amulet_test #8030 glance-next for fcorrea mp278505
AMULET FAIL: amulet-test failed
AMULET Results (max last 2 lines):
make: *** [functional_test] Error 1
ERROR:root:Make target returned non-zero.
Full amulet test output: http://
Build: http://
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_amulet_test #8031 glance-next for fcorrea mp278505
AMULET FAIL: amulet-test failed
AMULET Results (max last 2 lines):
make: *** [functional_test] Error 1
ERROR:root:Make target returned non-zero.
Full amulet test output: http://
Build: http://
Ryan Beisner (1chb1n) wrote : | # |
FYI, undercloud issue caused the last amulet failure. Rerunning...
machine
3 error pending trusty
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_amulet_test #8050 glance-next for fcorrea mp278505
AMULET FAIL: amulet-test failed
AMULET Results (max last 2 lines):
make: *** [functional_test] Error 1
ERROR:root:Make target returned non-zero.
Full amulet test output: http://
Build: http://
James Page (james-page) wrote : | # |
Same change already found in /next - assuming that someone else got to it first.
Thanks for your work on this!
Preview Diff
1 | === modified file 'actions/actions.py' | |||
2 | --- actions/actions.py 2015-08-26 13:16:31 +0000 | |||
3 | +++ actions/actions.py 2015-11-24 20:07:18 +0000 | |||
4 | @@ -5,8 +5,9 @@ | |||
5 | 5 | 5 | ||
6 | 6 | from charmhelpers.core.host import service_pause, service_resume | 6 | from charmhelpers.core.host import service_pause, service_resume |
7 | 7 | from charmhelpers.core.hookenv import action_fail, status_set | 7 | from charmhelpers.core.hookenv import action_fail, status_set |
8 | 8 | from charmhelpers.core.unitdata import HookData, kv | ||
9 | 8 | 9 | ||
11 | 9 | from hooks.glance_utils import services | 10 | from hooks.glance_utils import services, assess_status |
12 | 10 | 11 | ||
13 | 11 | 12 | ||
14 | 12 | def pause(args): | 13 | def pause(args): |
15 | @@ -18,8 +19,10 @@ | |||
16 | 18 | stopped = service_pause(service) | 19 | stopped = service_pause(service) |
17 | 19 | if not stopped: | 20 | if not stopped: |
18 | 20 | raise Exception("{} didn't stop cleanly.".format(service)) | 21 | raise Exception("{} didn't stop cleanly.".format(service)) |
21 | 21 | status_set( | 22 | with HookData()(): |
22 | 22 | "maintenance", "Paused. Use 'resume' action to resume normal service.") | 23 | kv().set('unit-paused', True) |
23 | 24 | state, message = assess_status() | ||
24 | 25 | status_set(state, message) | ||
25 | 23 | 26 | ||
26 | 24 | 27 | ||
27 | 25 | def resume(args): | 28 | def resume(args): |
28 | 26 | 29 | ||
29 | === modified file 'charmhelpers/cli/__init__.py' | |||
30 | --- charmhelpers/cli/__init__.py 2015-08-18 17:34:34 +0000 | |||
31 | +++ charmhelpers/cli/__init__.py 2015-11-24 20:07:18 +0000 | |||
32 | @@ -20,7 +20,7 @@ | |||
33 | 20 | 20 | ||
34 | 21 | from six.moves import zip | 21 | from six.moves import zip |
35 | 22 | 22 | ||
37 | 23 | from charmhelpers.core import unitdata | 23 | import charmhelpers.core.unitdata |
38 | 24 | 24 | ||
39 | 25 | 25 | ||
40 | 26 | class OutputFormatter(object): | 26 | class OutputFormatter(object): |
41 | @@ -163,8 +163,8 @@ | |||
42 | 163 | if getattr(arguments.func, '_cli_no_output', False): | 163 | if getattr(arguments.func, '_cli_no_output', False): |
43 | 164 | output = '' | 164 | output = '' |
44 | 165 | self.formatter.format_output(output, arguments.format) | 165 | self.formatter.format_output(output, arguments.format) |
47 | 166 | if unitdata._KV: | 166 | if charmhelpers.core.unitdata._KV: |
48 | 167 | unitdata._KV.flush() | 167 | charmhelpers.core.unitdata._KV.flush() |
49 | 168 | 168 | ||
50 | 169 | 169 | ||
51 | 170 | cmdline = CommandLine() | 170 | cmdline = CommandLine() |
52 | 171 | 171 | ||
53 | === modified file 'charmhelpers/contrib/charmsupport/nrpe.py' | |||
54 | --- charmhelpers/contrib/charmsupport/nrpe.py 2015-04-19 09:00:04 +0000 | |||
55 | +++ charmhelpers/contrib/charmsupport/nrpe.py 2015-11-24 20:07:18 +0000 | |||
56 | @@ -148,6 +148,13 @@ | |||
57 | 148 | self.description = description | 148 | self.description = description |
58 | 149 | self.check_cmd = self._locate_cmd(check_cmd) | 149 | self.check_cmd = self._locate_cmd(check_cmd) |
59 | 150 | 150 | ||
60 | 151 | def _get_check_filename(self): | ||
61 | 152 | return os.path.join(NRPE.nrpe_confdir, '{}.cfg'.format(self.command)) | ||
62 | 153 | |||
63 | 154 | def _get_service_filename(self, hostname): | ||
64 | 155 | return os.path.join(NRPE.nagios_exportdir, | ||
65 | 156 | 'service__{}_{}.cfg'.format(hostname, self.command)) | ||
66 | 157 | |||
67 | 151 | def _locate_cmd(self, check_cmd): | 158 | def _locate_cmd(self, check_cmd): |
68 | 152 | search_path = ( | 159 | search_path = ( |
69 | 153 | '/usr/lib/nagios/plugins', | 160 | '/usr/lib/nagios/plugins', |
70 | @@ -163,9 +170,21 @@ | |||
71 | 163 | log('Check command not found: {}'.format(parts[0])) | 170 | log('Check command not found: {}'.format(parts[0])) |
72 | 164 | return '' | 171 | return '' |
73 | 165 | 172 | ||
74 | 173 | def _remove_service_files(self): | ||
75 | 174 | if not os.path.exists(NRPE.nagios_exportdir): | ||
76 | 175 | return | ||
77 | 176 | for f in os.listdir(NRPE.nagios_exportdir): | ||
78 | 177 | if f.endswith('_{}.cfg'.format(self.command)): | ||
79 | 178 | os.remove(os.path.join(NRPE.nagios_exportdir, f)) | ||
80 | 179 | |||
81 | 180 | def remove(self, hostname): | ||
82 | 181 | nrpe_check_file = self._get_check_filename() | ||
83 | 182 | if os.path.exists(nrpe_check_file): | ||
84 | 183 | os.remove(nrpe_check_file) | ||
85 | 184 | self._remove_service_files() | ||
86 | 185 | |||
87 | 166 | def write(self, nagios_context, hostname, nagios_servicegroups): | 186 | def write(self, nagios_context, hostname, nagios_servicegroups): |
90 | 167 | nrpe_check_file = '/etc/nagios/nrpe.d/{}.cfg'.format( | 187 | nrpe_check_file = self._get_check_filename() |
89 | 168 | self.command) | ||
91 | 169 | with open(nrpe_check_file, 'w') as nrpe_check_config: | 188 | with open(nrpe_check_file, 'w') as nrpe_check_config: |
92 | 170 | nrpe_check_config.write("# check {}\n".format(self.shortname)) | 189 | nrpe_check_config.write("# check {}\n".format(self.shortname)) |
93 | 171 | nrpe_check_config.write("command[{}]={}\n".format( | 190 | nrpe_check_config.write("command[{}]={}\n".format( |
94 | @@ -180,9 +199,7 @@ | |||
95 | 180 | 199 | ||
96 | 181 | def write_service_config(self, nagios_context, hostname, | 200 | def write_service_config(self, nagios_context, hostname, |
97 | 182 | nagios_servicegroups): | 201 | nagios_servicegroups): |
101 | 183 | for f in os.listdir(NRPE.nagios_exportdir): | 202 | self._remove_service_files() |
99 | 184 | if re.search('.*{}.cfg'.format(self.command), f): | ||
100 | 185 | os.remove(os.path.join(NRPE.nagios_exportdir, f)) | ||
102 | 186 | 203 | ||
103 | 187 | templ_vars = { | 204 | templ_vars = { |
104 | 188 | 'nagios_hostname': hostname, | 205 | 'nagios_hostname': hostname, |
105 | @@ -192,8 +209,7 @@ | |||
106 | 192 | 'command': self.command, | 209 | 'command': self.command, |
107 | 193 | } | 210 | } |
108 | 194 | nrpe_service_text = Check.service_template.format(**templ_vars) | 211 | nrpe_service_text = Check.service_template.format(**templ_vars) |
111 | 195 | nrpe_service_file = '{}/service__{}_{}.cfg'.format( | 212 | nrpe_service_file = self._get_service_filename(hostname) |
110 | 196 | NRPE.nagios_exportdir, hostname, self.command) | ||
112 | 197 | with open(nrpe_service_file, 'w') as nrpe_service_config: | 213 | with open(nrpe_service_file, 'w') as nrpe_service_config: |
113 | 198 | nrpe_service_config.write(str(nrpe_service_text)) | 214 | nrpe_service_config.write(str(nrpe_service_text)) |
114 | 199 | 215 | ||
115 | @@ -218,12 +234,32 @@ | |||
116 | 218 | if hostname: | 234 | if hostname: |
117 | 219 | self.hostname = hostname | 235 | self.hostname = hostname |
118 | 220 | else: | 236 | else: |
120 | 221 | self.hostname = "{}-{}".format(self.nagios_context, self.unit_name) | 237 | nagios_hostname = get_nagios_hostname() |
121 | 238 | if nagios_hostname: | ||
122 | 239 | self.hostname = nagios_hostname | ||
123 | 240 | else: | ||
124 | 241 | self.hostname = "{}-{}".format(self.nagios_context, self.unit_name) | ||
125 | 222 | self.checks = [] | 242 | self.checks = [] |
126 | 223 | 243 | ||
127 | 224 | def add_check(self, *args, **kwargs): | 244 | def add_check(self, *args, **kwargs): |
128 | 225 | self.checks.append(Check(*args, **kwargs)) | 245 | self.checks.append(Check(*args, **kwargs)) |
129 | 226 | 246 | ||
130 | 247 | def remove_check(self, *args, **kwargs): | ||
131 | 248 | if kwargs.get('shortname') is None: | ||
132 | 249 | raise ValueError('shortname of check must be specified') | ||
133 | 250 | |||
134 | 251 | # Use sensible defaults if they're not specified - these are not | ||
135 | 252 | # actually used during removal, but they're required for constructing | ||
136 | 253 | # the Check object; check_disk is chosen because it's part of the | ||
137 | 254 | # nagios-plugins-basic package. | ||
138 | 255 | if kwargs.get('check_cmd') is None: | ||
139 | 256 | kwargs['check_cmd'] = 'check_disk' | ||
140 | 257 | if kwargs.get('description') is None: | ||
141 | 258 | kwargs['description'] = '' | ||
142 | 259 | |||
143 | 260 | check = Check(*args, **kwargs) | ||
144 | 261 | check.remove(self.hostname) | ||
145 | 262 | |||
146 | 227 | def write(self): | 263 | def write(self): |
147 | 228 | try: | 264 | try: |
148 | 229 | nagios_uid = pwd.getpwnam('nagios').pw_uid | 265 | nagios_uid = pwd.getpwnam('nagios').pw_uid |
149 | 230 | 266 | ||
150 | === modified file 'charmhelpers/contrib/openstack/amulet/deployment.py' | |||
151 | --- charmhelpers/contrib/openstack/amulet/deployment.py 2015-09-30 15:01:18 +0000 | |||
152 | +++ charmhelpers/contrib/openstack/amulet/deployment.py 2015-11-24 20:07:18 +0000 | |||
153 | @@ -14,12 +14,18 @@ | |||
154 | 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 |
155 | 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/>. |
156 | 16 | 16 | ||
157 | 17 | import logging | ||
158 | 18 | import re | ||
159 | 19 | import sys | ||
160 | 17 | import six | 20 | import six |
161 | 18 | from collections import OrderedDict | 21 | from collections import OrderedDict |
162 | 19 | from charmhelpers.contrib.amulet.deployment import ( | 22 | from charmhelpers.contrib.amulet.deployment import ( |
163 | 20 | AmuletDeployment | 23 | AmuletDeployment |
164 | 21 | ) | 24 | ) |
165 | 22 | 25 | ||
166 | 26 | DEBUG = logging.DEBUG | ||
167 | 27 | ERROR = logging.ERROR | ||
168 | 28 | |||
169 | 23 | 29 | ||
170 | 24 | class OpenStackAmuletDeployment(AmuletDeployment): | 30 | class OpenStackAmuletDeployment(AmuletDeployment): |
171 | 25 | """OpenStack amulet deployment. | 31 | """OpenStack amulet deployment. |
172 | @@ -28,9 +34,12 @@ | |||
173 | 28 | that is specifically for use by OpenStack charms. | 34 | that is specifically for use by OpenStack charms. |
174 | 29 | """ | 35 | """ |
175 | 30 | 36 | ||
177 | 31 | def __init__(self, series=None, openstack=None, source=None, stable=True): | 37 | def __init__(self, series=None, openstack=None, source=None, |
178 | 38 | stable=True, log_level=DEBUG): | ||
179 | 32 | """Initialize the deployment environment.""" | 39 | """Initialize the deployment environment.""" |
180 | 33 | super(OpenStackAmuletDeployment, self).__init__(series) | 40 | super(OpenStackAmuletDeployment, self).__init__(series) |
181 | 41 | self.log = self.get_logger(level=log_level) | ||
182 | 42 | self.log.info('OpenStackAmuletDeployment: init') | ||
183 | 34 | self.openstack = openstack | 43 | self.openstack = openstack |
184 | 35 | self.source = source | 44 | self.source = source |
185 | 36 | self.stable = stable | 45 | self.stable = stable |
186 | @@ -38,6 +47,22 @@ | |||
187 | 38 | # out. | 47 | # out. |
188 | 39 | self.current_next = "trusty" | 48 | self.current_next = "trusty" |
189 | 40 | 49 | ||
190 | 50 | def get_logger(self, name="deployment-logger", level=logging.DEBUG): | ||
191 | 51 | """Get a logger object that will log to stdout.""" | ||
192 | 52 | log = logging | ||
193 | 53 | logger = log.getLogger(name) | ||
194 | 54 | fmt = log.Formatter("%(asctime)s %(funcName)s " | ||
195 | 55 | "%(levelname)s: %(message)s") | ||
196 | 56 | |||
197 | 57 | handler = log.StreamHandler(stream=sys.stdout) | ||
198 | 58 | handler.setLevel(level) | ||
199 | 59 | handler.setFormatter(fmt) | ||
200 | 60 | |||
201 | 61 | logger.addHandler(handler) | ||
202 | 62 | logger.setLevel(level) | ||
203 | 63 | |||
204 | 64 | return logger | ||
205 | 65 | |||
206 | 41 | def _determine_branch_locations(self, other_services): | 66 | def _determine_branch_locations(self, other_services): |
207 | 42 | """Determine the branch locations for the other services. | 67 | """Determine the branch locations for the other services. |
208 | 43 | 68 | ||
209 | @@ -45,6 +70,8 @@ | |||
210 | 45 | 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 |
211 | 46 | stable or next branches for the other_services.""" | 71 | stable or next branches for the other_services.""" |
212 | 47 | 72 | ||
213 | 73 | self.log.info('OpenStackAmuletDeployment: determine branch locations') | ||
214 | 74 | |||
215 | 48 | # Charms outside the lp:~openstack-charmers namespace | 75 | # Charms outside the lp:~openstack-charmers namespace |
216 | 49 | base_charms = ['mysql', 'mongodb', 'nrpe'] | 76 | base_charms = ['mysql', 'mongodb', 'nrpe'] |
217 | 50 | 77 | ||
218 | @@ -82,6 +109,8 @@ | |||
219 | 82 | 109 | ||
220 | 83 | def _add_services(self, this_service, other_services): | 110 | def _add_services(self, this_service, other_services): |
221 | 84 | """Add services to the deployment and set openstack-origin/source.""" | 111 | """Add services to the deployment and set openstack-origin/source.""" |
222 | 112 | self.log.info('OpenStackAmuletDeployment: adding services') | ||
223 | 113 | |||
224 | 85 | other_services = self._determine_branch_locations(other_services) | 114 | other_services = self._determine_branch_locations(other_services) |
225 | 86 | 115 | ||
226 | 87 | super(OpenStackAmuletDeployment, self)._add_services(this_service, | 116 | super(OpenStackAmuletDeployment, self)._add_services(this_service, |
227 | @@ -95,7 +124,8 @@ | |||
228 | 95 | 'ceph-osd', 'ceph-radosgw'] | 124 | 'ceph-osd', 'ceph-radosgw'] |
229 | 96 | 125 | ||
230 | 97 | # Charms which can not use openstack-origin, ie. many subordinates | 126 | # Charms which can not use openstack-origin, ie. many subordinates |
232 | 98 | no_origin = ['cinder-ceph', 'hacluster', 'neutron-openvswitch', 'nrpe'] | 127 | no_origin = ['cinder-ceph', 'hacluster', 'neutron-openvswitch', 'nrpe', |
233 | 128 | 'openvswitch-odl', 'neutron-api-odl', 'odl-controller'] | ||
234 | 99 | 129 | ||
235 | 100 | if self.openstack: | 130 | if self.openstack: |
236 | 101 | for svc in services: | 131 | for svc in services: |
237 | @@ -111,9 +141,79 @@ | |||
238 | 111 | 141 | ||
239 | 112 | def _configure_services(self, configs): | 142 | def _configure_services(self, configs): |
240 | 113 | """Configure all of the services.""" | 143 | """Configure all of the services.""" |
241 | 144 | self.log.info('OpenStackAmuletDeployment: configure services') | ||
242 | 114 | for service, config in six.iteritems(configs): | 145 | for service, config in six.iteritems(configs): |
243 | 115 | self.d.configure(service, config) | 146 | self.d.configure(service, config) |
244 | 116 | 147 | ||
245 | 148 | def _auto_wait_for_status(self, message=None, exclude_services=None, | ||
246 | 149 | include_only=None, timeout=1800): | ||
247 | 150 | """Wait for all units to have a specific extended status, except | ||
248 | 151 | for any defined as excluded. Unless specified via message, any | ||
249 | 152 | status containing any case of 'ready' will be considered a match. | ||
250 | 153 | |||
251 | 154 | Examples of message usage: | ||
252 | 155 | |||
253 | 156 | Wait for all unit status to CONTAIN any case of 'ready' or 'ok': | ||
254 | 157 | message = re.compile('.*ready.*|.*ok.*', re.IGNORECASE) | ||
255 | 158 | |||
256 | 159 | Wait for all units to reach this status (exact match): | ||
257 | 160 | message = re.compile('^Unit is ready and clustered$') | ||
258 | 161 | |||
259 | 162 | Wait for all units to reach any one of these (exact match): | ||
260 | 163 | message = re.compile('Unit is ready|OK|Ready') | ||
261 | 164 | |||
262 | 165 | Wait for at least one unit to reach this status (exact match): | ||
263 | 166 | message = {'ready'} | ||
264 | 167 | |||
265 | 168 | See Amulet's sentry.wait_for_messages() for message usage detail. | ||
266 | 169 | https://github.com/juju/amulet/blob/master/amulet/sentry.py | ||
267 | 170 | |||
268 | 171 | :param message: Expected status match | ||
269 | 172 | :param exclude_services: List of juju service names to ignore, | ||
270 | 173 | not to be used in conjuction with include_only. | ||
271 | 174 | :param include_only: List of juju service names to exclusively check, | ||
272 | 175 | not to be used in conjuction with exclude_services. | ||
273 | 176 | :param timeout: Maximum time in seconds to wait for status match | ||
274 | 177 | :returns: None. Raises if timeout is hit. | ||
275 | 178 | """ | ||
276 | 179 | self.log.info('Waiting for extended status on units...') | ||
277 | 180 | |||
278 | 181 | all_services = self.d.services.keys() | ||
279 | 182 | |||
280 | 183 | if exclude_services and include_only: | ||
281 | 184 | raise ValueError('exclude_services can not be used ' | ||
282 | 185 | 'with include_only') | ||
283 | 186 | |||
284 | 187 | if message: | ||
285 | 188 | if isinstance(message, re._pattern_type): | ||
286 | 189 | match = message.pattern | ||
287 | 190 | else: | ||
288 | 191 | match = message | ||
289 | 192 | |||
290 | 193 | self.log.debug('Custom extended status wait match: ' | ||
291 | 194 | '{}'.format(match)) | ||
292 | 195 | else: | ||
293 | 196 | self.log.debug('Default extended status wait match: contains ' | ||
294 | 197 | 'READY (case-insensitive)') | ||
295 | 198 | message = re.compile('.*ready.*', re.IGNORECASE) | ||
296 | 199 | |||
297 | 200 | if exclude_services: | ||
298 | 201 | self.log.debug('Excluding services from extended status match: ' | ||
299 | 202 | '{}'.format(exclude_services)) | ||
300 | 203 | else: | ||
301 | 204 | exclude_services = [] | ||
302 | 205 | |||
303 | 206 | if include_only: | ||
304 | 207 | services = include_only | ||
305 | 208 | else: | ||
306 | 209 | services = list(set(all_services) - set(exclude_services)) | ||
307 | 210 | |||
308 | 211 | self.log.debug('Waiting up to {}s for extended status on services: ' | ||
309 | 212 | '{}'.format(timeout, services)) | ||
310 | 213 | service_messages = {service: message for service in services} | ||
311 | 214 | self.d.sentry.wait_for_messages(service_messages, timeout=timeout) | ||
312 | 215 | self.log.info('OK') | ||
313 | 216 | |||
314 | 117 | def _get_openstack_release(self): | 217 | def _get_openstack_release(self): |
315 | 118 | """Get openstack release. | 218 | """Get openstack release. |
316 | 119 | 219 | ||
317 | 120 | 220 | ||
318 | === modified file 'charmhelpers/contrib/openstack/amulet/utils.py' | |||
319 | --- charmhelpers/contrib/openstack/amulet/utils.py 2015-09-30 15:01:18 +0000 | |||
320 | +++ charmhelpers/contrib/openstack/amulet/utils.py 2015-11-24 20:07:18 +0000 | |||
321 | @@ -18,6 +18,7 @@ | |||
322 | 18 | import json | 18 | import json |
323 | 19 | import logging | 19 | import logging |
324 | 20 | import os | 20 | import os |
325 | 21 | import re | ||
326 | 21 | import six | 22 | import six |
327 | 22 | import time | 23 | import time |
328 | 23 | import urllib | 24 | import urllib |
329 | @@ -604,7 +605,22 @@ | |||
330 | 604 | '{}'.format(sample_type, samples)) | 605 | '{}'.format(sample_type, samples)) |
331 | 605 | return None | 606 | return None |
332 | 606 | 607 | ||
334 | 607 | # rabbitmq/amqp specific helpers: | 608 | # rabbitmq/amqp specific helpers: |
335 | 609 | |||
336 | 610 | def rmq_wait_for_cluster(self, deployment, init_sleep=15, timeout=1200): | ||
337 | 611 | """Wait for rmq units extended status to show cluster readiness, | ||
338 | 612 | after an optional initial sleep period. Initial sleep is likely | ||
339 | 613 | necessary to be effective following a config change, as status | ||
340 | 614 | message may not instantly update to non-ready.""" | ||
341 | 615 | |||
342 | 616 | if init_sleep: | ||
343 | 617 | time.sleep(init_sleep) | ||
344 | 618 | |||
345 | 619 | message = re.compile('^Unit is ready and clustered$') | ||
346 | 620 | deployment._auto_wait_for_status(message=message, | ||
347 | 621 | timeout=timeout, | ||
348 | 622 | include_only=['rabbitmq-server']) | ||
349 | 623 | |||
350 | 608 | def add_rmq_test_user(self, sentry_units, | 624 | def add_rmq_test_user(self, sentry_units, |
351 | 609 | username="testuser1", password="changeme"): | 625 | username="testuser1", password="changeme"): |
352 | 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 |
353 | @@ -805,7 +821,10 @@ | |||
354 | 805 | if port: | 821 | if port: |
355 | 806 | config['ssl_port'] = port | 822 | config['ssl_port'] = port |
356 | 807 | 823 | ||
358 | 808 | deployment.configure('rabbitmq-server', config) | 824 | deployment.d.configure('rabbitmq-server', config) |
359 | 825 | |||
360 | 826 | # Wait for unit status | ||
361 | 827 | self.rmq_wait_for_cluster(deployment) | ||
362 | 809 | 828 | ||
363 | 810 | # Confirm | 829 | # Confirm |
364 | 811 | tries = 0 | 830 | tries = 0 |
365 | @@ -832,7 +851,10 @@ | |||
366 | 832 | 851 | ||
367 | 833 | # Disable RMQ SSL | 852 | # Disable RMQ SSL |
368 | 834 | config = {'ssl': 'off'} | 853 | config = {'ssl': 'off'} |
370 | 835 | deployment.configure('rabbitmq-server', config) | 854 | deployment.d.configure('rabbitmq-server', config) |
371 | 855 | |||
372 | 856 | # Wait for unit status | ||
373 | 857 | self.rmq_wait_for_cluster(deployment) | ||
374 | 836 | 858 | ||
375 | 837 | # Confirm | 859 | # Confirm |
376 | 838 | tries = 0 | 860 | tries = 0 |
377 | 839 | 861 | ||
378 | === modified file 'charmhelpers/contrib/openstack/context.py' | |||
379 | --- charmhelpers/contrib/openstack/context.py 2015-09-30 15:01:18 +0000 | |||
380 | +++ charmhelpers/contrib/openstack/context.py 2015-11-24 20:07:18 +0000 | |||
381 | @@ -952,6 +952,19 @@ | |||
382 | 952 | 'config': config} | 952 | 'config': config} |
383 | 953 | return ovs_ctxt | 953 | return ovs_ctxt |
384 | 954 | 954 | ||
385 | 955 | def midonet_ctxt(self): | ||
386 | 956 | driver = neutron_plugin_attribute(self.plugin, 'driver', | ||
387 | 957 | self.network_manager) | ||
388 | 958 | midonet_config = neutron_plugin_attribute(self.plugin, 'config', | ||
389 | 959 | self.network_manager) | ||
390 | 960 | mido_ctxt = {'core_plugin': driver, | ||
391 | 961 | 'neutron_plugin': 'midonet', | ||
392 | 962 | 'neutron_security_groups': self.neutron_security_groups, | ||
393 | 963 | 'local_ip': unit_private_ip(), | ||
394 | 964 | 'config': midonet_config} | ||
395 | 965 | |||
396 | 966 | return mido_ctxt | ||
397 | 967 | |||
398 | 955 | def __call__(self): | 968 | def __call__(self): |
399 | 956 | if self.network_manager not in ['quantum', 'neutron']: | 969 | if self.network_manager not in ['quantum', 'neutron']: |
400 | 957 | return {} | 970 | return {} |
401 | @@ -973,6 +986,8 @@ | |||
402 | 973 | ctxt.update(self.nuage_ctxt()) | 986 | ctxt.update(self.nuage_ctxt()) |
403 | 974 | elif self.plugin == 'plumgrid': | 987 | elif self.plugin == 'plumgrid': |
404 | 975 | ctxt.update(self.pg_ctxt()) | 988 | ctxt.update(self.pg_ctxt()) |
405 | 989 | elif self.plugin == 'midonet': | ||
406 | 990 | ctxt.update(self.midonet_ctxt()) | ||
407 | 976 | 991 | ||
408 | 977 | alchemy_flags = config('neutron-alchemy-flags') | 992 | alchemy_flags = config('neutron-alchemy-flags') |
409 | 978 | if alchemy_flags: | 993 | if alchemy_flags: |
410 | @@ -1073,6 +1088,20 @@ | |||
411 | 1073 | config_flags_parser(config_flags)} | 1088 | config_flags_parser(config_flags)} |
412 | 1074 | 1089 | ||
413 | 1075 | 1090 | ||
414 | 1091 | class LibvirtConfigFlagsContext(OSContextGenerator): | ||
415 | 1092 | """ | ||
416 | 1093 | This context provides support for extending | ||
417 | 1094 | the libvirt section through user-defined flags. | ||
418 | 1095 | """ | ||
419 | 1096 | def __call__(self): | ||
420 | 1097 | ctxt = {} | ||
421 | 1098 | libvirt_flags = config('libvirt-flags') | ||
422 | 1099 | if libvirt_flags: | ||
423 | 1100 | ctxt['libvirt_flags'] = config_flags_parser( | ||
424 | 1101 | libvirt_flags) | ||
425 | 1102 | return ctxt | ||
426 | 1103 | |||
427 | 1104 | |||
428 | 1076 | class SubordinateConfigContext(OSContextGenerator): | 1105 | class SubordinateConfigContext(OSContextGenerator): |
429 | 1077 | 1106 | ||
430 | 1078 | """ | 1107 | """ |
431 | @@ -1105,7 +1134,7 @@ | |||
432 | 1105 | 1134 | ||
433 | 1106 | ctxt = { | 1135 | ctxt = { |
434 | 1107 | ... other context ... | 1136 | ... other context ... |
436 | 1108 | 'subordinate_config': { | 1137 | 'subordinate_configuration': { |
437 | 1109 | 'DEFAULT': { | 1138 | 'DEFAULT': { |
438 | 1110 | 'key1': 'value1', | 1139 | 'key1': 'value1', |
439 | 1111 | }, | 1140 | }, |
440 | @@ -1146,22 +1175,23 @@ | |||
441 | 1146 | try: | 1175 | try: |
442 | 1147 | sub_config = json.loads(sub_config) | 1176 | sub_config = json.loads(sub_config) |
443 | 1148 | except: | 1177 | except: |
446 | 1149 | log('Could not parse JSON from subordinate_config ' | 1178 | log('Could not parse JSON from ' |
447 | 1150 | 'setting from %s' % rid, level=ERROR) | 1179 | 'subordinate_configuration setting from %s' |
448 | 1180 | % rid, level=ERROR) | ||
449 | 1151 | continue | 1181 | continue |
450 | 1152 | 1182 | ||
451 | 1153 | for service in self.services: | 1183 | for service in self.services: |
452 | 1154 | if service not in sub_config: | 1184 | if service not in sub_config: |
456 | 1155 | log('Found subordinate_config on %s but it contained' | 1185 | log('Found subordinate_configuration on %s but it ' |
457 | 1156 | 'nothing for %s service' % (rid, service), | 1186 | 'contained nothing for %s service' |
458 | 1157 | level=INFO) | 1187 | % (rid, service), level=INFO) |
459 | 1158 | continue | 1188 | continue |
460 | 1159 | 1189 | ||
461 | 1160 | sub_config = sub_config[service] | 1190 | sub_config = sub_config[service] |
462 | 1161 | if self.config_file not in sub_config: | 1191 | if self.config_file not in sub_config: |
466 | 1162 | log('Found subordinate_config on %s but it contained' | 1192 | log('Found subordinate_configuration on %s but it ' |
467 | 1163 | 'nothing for %s' % (rid, self.config_file), | 1193 | 'contained nothing for %s' |
468 | 1164 | level=INFO) | 1194 | % (rid, self.config_file), level=INFO) |
469 | 1165 | continue | 1195 | continue |
470 | 1166 | 1196 | ||
471 | 1167 | sub_config = sub_config[self.config_file] | 1197 | sub_config = sub_config[self.config_file] |
472 | 1168 | 1198 | ||
473 | === modified file 'charmhelpers/contrib/openstack/neutron.py' | |||
474 | --- charmhelpers/contrib/openstack/neutron.py 2015-09-30 15:01:18 +0000 | |||
475 | +++ charmhelpers/contrib/openstack/neutron.py 2015-11-24 20:07:18 +0000 | |||
476 | @@ -204,11 +204,25 @@ | |||
477 | 204 | database=config('database'), | 204 | database=config('database'), |
478 | 205 | ssl_dir=NEUTRON_CONF_DIR)], | 205 | ssl_dir=NEUTRON_CONF_DIR)], |
479 | 206 | 'services': [], | 206 | 'services': [], |
482 | 207 | 'packages': [['plumgrid-lxc'], | 207 | 'packages': ['plumgrid-lxc', |
483 | 208 | ['iovisor-dkms']], | 208 | 'iovisor-dkms'], |
484 | 209 | 'server_packages': ['neutron-server', | 209 | 'server_packages': ['neutron-server', |
485 | 210 | 'neutron-plugin-plumgrid'], | 210 | 'neutron-plugin-plumgrid'], |
486 | 211 | 'server_services': ['neutron-server'] | 211 | 'server_services': ['neutron-server'] |
487 | 212 | }, | ||
488 | 213 | 'midonet': { | ||
489 | 214 | 'config': '/etc/neutron/plugins/midonet/midonet.ini', | ||
490 | 215 | 'driver': 'midonet.neutron.plugin.MidonetPluginV2', | ||
491 | 216 | 'contexts': [ | ||
492 | 217 | context.SharedDBContext(user=config('neutron-database-user'), | ||
493 | 218 | database=config('neutron-database'), | ||
494 | 219 | relation_prefix='neutron', | ||
495 | 220 | ssl_dir=NEUTRON_CONF_DIR)], | ||
496 | 221 | 'services': [], | ||
497 | 222 | 'packages': [[headers_package()] + determine_dkms_package()], | ||
498 | 223 | 'server_packages': ['neutron-server', | ||
499 | 224 | 'python-neutron-plugin-midonet'], | ||
500 | 225 | 'server_services': ['neutron-server'] | ||
501 | 212 | } | 226 | } |
502 | 213 | } | 227 | } |
503 | 214 | if release >= 'icehouse': | 228 | if release >= 'icehouse': |
504 | 215 | 229 | ||
505 | === modified file 'charmhelpers/contrib/openstack/utils.py' | |||
506 | --- charmhelpers/contrib/openstack/utils.py 2015-09-30 15:01:18 +0000 | |||
507 | +++ charmhelpers/contrib/openstack/utils.py 2015-11-24 20:07:18 +0000 | |||
508 | @@ -26,6 +26,7 @@ | |||
509 | 26 | 26 | ||
510 | 27 | import six | 27 | import six |
511 | 28 | import traceback | 28 | import traceback |
512 | 29 | import uuid | ||
513 | 29 | import yaml | 30 | import yaml |
514 | 30 | 31 | ||
515 | 31 | from charmhelpers.contrib.network import ip | 32 | from charmhelpers.contrib.network import ip |
516 | @@ -41,6 +42,7 @@ | |||
517 | 41 | log as juju_log, | 42 | log as juju_log, |
518 | 42 | charm_dir, | 43 | charm_dir, |
519 | 43 | INFO, | 44 | INFO, |
520 | 45 | related_units, | ||
521 | 44 | relation_ids, | 46 | relation_ids, |
522 | 45 | relation_set, | 47 | relation_set, |
523 | 46 | status_set, | 48 | status_set, |
524 | @@ -121,6 +123,7 @@ | |||
525 | 121 | ('2.2.2', 'kilo'), | 123 | ('2.2.2', 'kilo'), |
526 | 122 | ('2.3.0', 'liberty'), | 124 | ('2.3.0', 'liberty'), |
527 | 123 | ('2.4.0', 'liberty'), | 125 | ('2.4.0', 'liberty'), |
528 | 126 | ('2.5.0', 'liberty'), | ||
529 | 124 | ]) | 127 | ]) |
530 | 125 | 128 | ||
531 | 126 | # >= Liberty version->codename mapping | 129 | # >= Liberty version->codename mapping |
532 | @@ -858,7 +861,9 @@ | |||
533 | 858 | if charm_state != 'active' and charm_state != 'unknown': | 861 | if charm_state != 'active' and charm_state != 'unknown': |
534 | 859 | state = workload_state_compare(state, charm_state) | 862 | state = workload_state_compare(state, charm_state) |
535 | 860 | if message: | 863 | if message: |
537 | 861 | message = "{} {}".format(message, charm_message) | 864 | charm_message = charm_message.replace("Incomplete relations: ", |
538 | 865 | "") | ||
539 | 866 | message = "{}, {}".format(message, charm_message) | ||
540 | 862 | else: | 867 | else: |
541 | 863 | message = charm_message | 868 | message = charm_message |
542 | 864 | 869 | ||
543 | @@ -975,3 +980,19 @@ | |||
544 | 975 | action_set({'outcome': 'no upgrade available.'}) | 980 | action_set({'outcome': 'no upgrade available.'}) |
545 | 976 | 981 | ||
546 | 977 | return ret | 982 | return ret |
547 | 983 | |||
548 | 984 | |||
549 | 985 | def remote_restart(rel_name, remote_service=None): | ||
550 | 986 | trigger = { | ||
551 | 987 | 'restart-trigger': str(uuid.uuid4()), | ||
552 | 988 | } | ||
553 | 989 | if remote_service: | ||
554 | 990 | trigger['remote-service'] = remote_service | ||
555 | 991 | for rid in relation_ids(rel_name): | ||
556 | 992 | # This subordinate can be related to two seperate services using | ||
557 | 993 | # different subordinate relations so only issue the restart if | ||
558 | 994 | # the principle is conencted down the relation we think it is | ||
559 | 995 | if related_units(relid=rid): | ||
560 | 996 | relation_set(relation_id=rid, | ||
561 | 997 | relation_settings=trigger, | ||
562 | 998 | ) | ||
563 | 978 | 999 | ||
564 | === modified file 'charmhelpers/contrib/storage/linux/ceph.py' | |||
565 | --- charmhelpers/contrib/storage/linux/ceph.py 2015-09-30 15:01:18 +0000 | |||
566 | +++ charmhelpers/contrib/storage/linux/ceph.py 2015-11-24 20:07:18 +0000 | |||
567 | @@ -26,6 +26,7 @@ | |||
568 | 26 | 26 | ||
569 | 27 | import os | 27 | import os |
570 | 28 | import shutil | 28 | import shutil |
571 | 29 | import six | ||
572 | 29 | import json | 30 | import json |
573 | 30 | import time | 31 | import time |
574 | 31 | import uuid | 32 | import uuid |
575 | @@ -125,29 +126,37 @@ | |||
576 | 125 | return None | 126 | return None |
577 | 126 | 127 | ||
578 | 127 | 128 | ||
580 | 128 | def create_pool(service, name, replicas=3): | 129 | def update_pool(client, pool, settings): |
581 | 130 | cmd = ['ceph', '--id', client, 'osd', 'pool', 'set', pool] | ||
582 | 131 | for k, v in six.iteritems(settings): | ||
583 | 132 | cmd.append(k) | ||
584 | 133 | cmd.append(v) | ||
585 | 134 | |||
586 | 135 | check_call(cmd) | ||
587 | 136 | |||
588 | 137 | |||
589 | 138 | def create_pool(service, name, replicas=3, pg_num=None): | ||
590 | 129 | """Create a new RADOS pool.""" | 139 | """Create a new RADOS pool.""" |
591 | 130 | if pool_exists(service, name): | 140 | if pool_exists(service, name): |
592 | 131 | log("Ceph pool {} already exists, skipping creation".format(name), | 141 | log("Ceph pool {} already exists, skipping creation".format(name), |
593 | 132 | level=WARNING) | 142 | level=WARNING) |
594 | 133 | return | 143 | return |
595 | 134 | 144 | ||
612 | 135 | # Calculate the number of placement groups based | 145 | if not pg_num: |
613 | 136 | # on upstream recommended best practices. | 146 | # Calculate the number of placement groups based |
614 | 137 | osds = get_osds(service) | 147 | # on upstream recommended best practices. |
615 | 138 | if osds: | 148 | osds = get_osds(service) |
616 | 139 | pgnum = (len(osds) * 100 // replicas) | 149 | if osds: |
617 | 140 | else: | 150 | pg_num = (len(osds) * 100 // replicas) |
618 | 141 | # NOTE(james-page): Default to 200 for older ceph versions | 151 | else: |
619 | 142 | # which don't support OSD query from cli | 152 | # NOTE(james-page): Default to 200 for older ceph versions |
620 | 143 | pgnum = 200 | 153 | # which don't support OSD query from cli |
621 | 144 | 154 | pg_num = 200 | |
622 | 145 | cmd = ['ceph', '--id', service, 'osd', 'pool', 'create', name, str(pgnum)] | 155 | |
623 | 146 | check_call(cmd) | 156 | cmd = ['ceph', '--id', service, 'osd', 'pool', 'create', name, str(pg_num)] |
624 | 147 | 157 | check_call(cmd) | |
625 | 148 | cmd = ['ceph', '--id', service, 'osd', 'pool', 'set', name, 'size', | 158 | |
626 | 149 | str(replicas)] | 159 | update_pool(service, name, settings={'size': str(replicas)}) |
611 | 150 | check_call(cmd) | ||
627 | 151 | 160 | ||
628 | 152 | 161 | ||
629 | 153 | def delete_pool(service, name): | 162 | def delete_pool(service, name): |
630 | @@ -202,10 +211,10 @@ | |||
631 | 202 | log('Created new keyfile at %s.' % keyfile, level=INFO) | 211 | log('Created new keyfile at %s.' % keyfile, level=INFO) |
632 | 203 | 212 | ||
633 | 204 | 213 | ||
636 | 205 | def get_ceph_nodes(): | 214 | def get_ceph_nodes(relation='ceph'): |
637 | 206 | """Query named relation 'ceph' to determine current nodes.""" | 215 | """Query named relation to determine current nodes.""" |
638 | 207 | hosts = [] | 216 | hosts = [] |
640 | 208 | for r_id in relation_ids('ceph'): | 217 | for r_id in relation_ids(relation): |
641 | 209 | for unit in related_units(r_id): | 218 | for unit in related_units(r_id): |
642 | 210 | hosts.append(relation_get('private-address', unit=unit, rid=r_id)) | 219 | hosts.append(relation_get('private-address', unit=unit, rid=r_id)) |
643 | 211 | 220 | ||
644 | @@ -357,14 +366,14 @@ | |||
645 | 357 | service_start(svc) | 366 | service_start(svc) |
646 | 358 | 367 | ||
647 | 359 | 368 | ||
649 | 360 | def ensure_ceph_keyring(service, user=None, group=None): | 369 | def ensure_ceph_keyring(service, user=None, group=None, relation='ceph'): |
650 | 361 | """Ensures a ceph keyring is created for a named service and optionally | 370 | """Ensures a ceph keyring is created for a named service and optionally |
651 | 362 | ensures user and group ownership. | 371 | ensures user and group ownership. |
652 | 363 | 372 | ||
653 | 364 | Returns False if no ceph key is available in relation state. | 373 | Returns False if no ceph key is available in relation state. |
654 | 365 | """ | 374 | """ |
655 | 366 | key = None | 375 | key = None |
657 | 367 | for rid in relation_ids('ceph'): | 376 | for rid in relation_ids(relation): |
658 | 368 | for unit in related_units(rid): | 377 | for unit in related_units(rid): |
659 | 369 | key = relation_get('key', rid=rid, unit=unit) | 378 | key = relation_get('key', rid=rid, unit=unit) |
660 | 370 | if key: | 379 | if key: |
661 | @@ -413,9 +422,16 @@ | |||
662 | 413 | self.request_id = str(uuid.uuid1()) | 422 | self.request_id = str(uuid.uuid1()) |
663 | 414 | self.ops = [] | 423 | self.ops = [] |
664 | 415 | 424 | ||
666 | 416 | def add_op_create_pool(self, name, replica_count=3): | 425 | def add_op_create_pool(self, name, replica_count=3, pg_num=None): |
667 | 426 | """Adds an operation to create a pool. | ||
668 | 427 | |||
669 | 428 | @param pg_num setting: optional setting. If not provided, this value | ||
670 | 429 | will be calculated by the broker based on how many OSDs are in the | ||
671 | 430 | cluster at the time of creation. Note that, if provided, this value | ||
672 | 431 | will be capped at the current available maximum. | ||
673 | 432 | """ | ||
674 | 417 | self.ops.append({'op': 'create-pool', 'name': name, | 433 | self.ops.append({'op': 'create-pool', 'name': name, |
676 | 418 | 'replicas': replica_count}) | 434 | 'replicas': replica_count, 'pg_num': pg_num}) |
677 | 419 | 435 | ||
678 | 420 | def set_ops(self, ops): | 436 | def set_ops(self, ops): |
679 | 421 | """Set request ops to provided value. | 437 | """Set request ops to provided value. |
680 | @@ -433,8 +449,8 @@ | |||
681 | 433 | def _ops_equal(self, other): | 449 | def _ops_equal(self, other): |
682 | 434 | if len(self.ops) == len(other.ops): | 450 | if len(self.ops) == len(other.ops): |
683 | 435 | for req_no in range(0, len(self.ops)): | 451 | for req_no in range(0, len(self.ops)): |
686 | 436 | for key in ['replicas', 'name', 'op']: | 452 | for key in ['replicas', 'name', 'op', 'pg_num']: |
687 | 437 | if self.ops[req_no][key] != other.ops[req_no][key]: | 453 | if self.ops[req_no].get(key) != other.ops[req_no].get(key): |
688 | 438 | return False | 454 | return False |
689 | 439 | else: | 455 | else: |
690 | 440 | return False | 456 | return False |
691 | @@ -540,7 +556,7 @@ | |||
692 | 540 | return request | 556 | return request |
693 | 541 | 557 | ||
694 | 542 | 558 | ||
696 | 543 | def get_request_states(request): | 559 | def get_request_states(request, relation='ceph'): |
697 | 544 | """Return a dict of requests per relation id with their corresponding | 560 | """Return a dict of requests per relation id with their corresponding |
698 | 545 | completion state. | 561 | completion state. |
699 | 546 | 562 | ||
700 | @@ -552,7 +568,7 @@ | |||
701 | 552 | """ | 568 | """ |
702 | 553 | complete = [] | 569 | complete = [] |
703 | 554 | requests = {} | 570 | requests = {} |
705 | 555 | for rid in relation_ids('ceph'): | 571 | for rid in relation_ids(relation): |
706 | 556 | complete = False | 572 | complete = False |
707 | 557 | previous_request = get_previous_request(rid) | 573 | previous_request = get_previous_request(rid) |
708 | 558 | if request == previous_request: | 574 | if request == previous_request: |
709 | @@ -570,14 +586,14 @@ | |||
710 | 570 | return requests | 586 | return requests |
711 | 571 | 587 | ||
712 | 572 | 588 | ||
714 | 573 | def is_request_sent(request): | 589 | def is_request_sent(request, relation='ceph'): |
715 | 574 | """Check to see if a functionally equivalent request has already been sent | 590 | """Check to see if a functionally equivalent request has already been sent |
716 | 575 | 591 | ||
717 | 576 | Returns True if a similair request has been sent | 592 | Returns True if a similair request has been sent |
718 | 577 | 593 | ||
719 | 578 | @param request: A CephBrokerRq object | 594 | @param request: A CephBrokerRq object |
720 | 579 | """ | 595 | """ |
722 | 580 | states = get_request_states(request) | 596 | states = get_request_states(request, relation=relation) |
723 | 581 | for rid in states.keys(): | 597 | for rid in states.keys(): |
724 | 582 | if not states[rid]['sent']: | 598 | if not states[rid]['sent']: |
725 | 583 | return False | 599 | return False |
726 | @@ -585,7 +601,7 @@ | |||
727 | 585 | return True | 601 | return True |
728 | 586 | 602 | ||
729 | 587 | 603 | ||
731 | 588 | def is_request_complete(request): | 604 | def is_request_complete(request, relation='ceph'): |
732 | 589 | """Check to see if a functionally equivalent request has already been | 605 | """Check to see if a functionally equivalent request has already been |
733 | 590 | completed | 606 | completed |
734 | 591 | 607 | ||
735 | @@ -593,7 +609,7 @@ | |||
736 | 593 | 609 | ||
737 | 594 | @param request: A CephBrokerRq object | 610 | @param request: A CephBrokerRq object |
738 | 595 | """ | 611 | """ |
740 | 596 | states = get_request_states(request) | 612 | states = get_request_states(request, relation=relation) |
741 | 597 | for rid in states.keys(): | 613 | for rid in states.keys(): |
742 | 598 | if not states[rid]['complete']: | 614 | if not states[rid]['complete']: |
743 | 599 | return False | 615 | return False |
744 | @@ -643,15 +659,15 @@ | |||
745 | 643 | return 'broker-rsp-' + local_unit().replace('/', '-') | 659 | return 'broker-rsp-' + local_unit().replace('/', '-') |
746 | 644 | 660 | ||
747 | 645 | 661 | ||
749 | 646 | def send_request_if_needed(request): | 662 | def send_request_if_needed(request, relation='ceph'): |
750 | 647 | """Send broker request if an equivalent request has not already been sent | 663 | """Send broker request if an equivalent request has not already been sent |
751 | 648 | 664 | ||
752 | 649 | @param request: A CephBrokerRq object | 665 | @param request: A CephBrokerRq object |
753 | 650 | """ | 666 | """ |
755 | 651 | if is_request_sent(request): | 667 | if is_request_sent(request, relation=relation): |
756 | 652 | log('Request already sent but not complete, not sending new request', | 668 | log('Request already sent but not complete, not sending new request', |
757 | 653 | level=DEBUG) | 669 | level=DEBUG) |
758 | 654 | else: | 670 | else: |
760 | 655 | for rid in relation_ids('ceph'): | 671 | for rid in relation_ids(relation): |
761 | 656 | log('Sending request {}'.format(request.request_id), level=DEBUG) | 672 | log('Sending request {}'.format(request.request_id), level=DEBUG) |
762 | 657 | relation_set(relation_id=rid, broker_req=request.request) | 673 | relation_set(relation_id=rid, broker_req=request.request) |
763 | 658 | 674 | ||
764 | === modified file 'charmhelpers/core/hookenv.py' | |||
765 | --- charmhelpers/core/hookenv.py 2015-09-30 15:01:18 +0000 | |||
766 | +++ charmhelpers/core/hookenv.py 2015-11-24 20:07:18 +0000 | |||
767 | @@ -491,6 +491,19 @@ | |||
768 | 491 | 491 | ||
769 | 492 | 492 | ||
770 | 493 | @cached | 493 | @cached |
771 | 494 | def peer_relation_id(): | ||
772 | 495 | '''Get a peer relation id if a peer relation has been joined, else None.''' | ||
773 | 496 | md = metadata() | ||
774 | 497 | section = md.get('peers') | ||
775 | 498 | if section: | ||
776 | 499 | for key in section: | ||
777 | 500 | relids = relation_ids(key) | ||
778 | 501 | if relids: | ||
779 | 502 | return relids[0] | ||
780 | 503 | return None | ||
781 | 504 | |||
782 | 505 | |||
783 | 506 | @cached | ||
784 | 494 | def relation_to_interface(relation_name): | 507 | def relation_to_interface(relation_name): |
785 | 495 | """ | 508 | """ |
786 | 496 | Given the name of a relation, return the interface that relation uses. | 509 | Given the name of a relation, return the interface that relation uses. |
787 | @@ -624,7 +637,7 @@ | |||
788 | 624 | 637 | ||
789 | 625 | 638 | ||
790 | 626 | @cached | 639 | @cached |
792 | 627 | def storage_get(attribute="", storage_id=""): | 640 | def storage_get(attribute=None, storage_id=None): |
793 | 628 | """Get storage attributes""" | 641 | """Get storage attributes""" |
794 | 629 | _args = ['storage-get', '--format=json'] | 642 | _args = ['storage-get', '--format=json'] |
795 | 630 | if storage_id: | 643 | if storage_id: |
796 | @@ -638,7 +651,7 @@ | |||
797 | 638 | 651 | ||
798 | 639 | 652 | ||
799 | 640 | @cached | 653 | @cached |
801 | 641 | def storage_list(storage_name=""): | 654 | def storage_list(storage_name=None): |
802 | 642 | """List the storage IDs for the unit""" | 655 | """List the storage IDs for the unit""" |
803 | 643 | _args = ['storage-list', '--format=json'] | 656 | _args = ['storage-list', '--format=json'] |
804 | 644 | if storage_name: | 657 | if storage_name: |
805 | @@ -820,6 +833,7 @@ | |||
806 | 820 | 833 | ||
807 | 821 | def translate_exc(from_exc, to_exc): | 834 | def translate_exc(from_exc, to_exc): |
808 | 822 | def inner_translate_exc1(f): | 835 | def inner_translate_exc1(f): |
809 | 836 | @wraps(f) | ||
810 | 823 | def inner_translate_exc2(*args, **kwargs): | 837 | def inner_translate_exc2(*args, **kwargs): |
811 | 824 | try: | 838 | try: |
812 | 825 | return f(*args, **kwargs) | 839 | return f(*args, **kwargs) |
813 | 826 | 840 | ||
814 | === modified file 'charmhelpers/core/host.py' | |||
815 | --- charmhelpers/core/host.py 2015-09-30 15:01:18 +0000 | |||
816 | +++ charmhelpers/core/host.py 2015-11-24 20:07:18 +0000 | |||
817 | @@ -67,7 +67,9 @@ | |||
818 | 67 | """Pause a system service. | 67 | """Pause a system service. |
819 | 68 | 68 | ||
820 | 69 | Stop it, and prevent it from starting again at boot.""" | 69 | Stop it, and prevent it from starting again at boot.""" |
822 | 70 | stopped = service_stop(service_name) | 70 | stopped = True |
823 | 71 | if service_running(service_name): | ||
824 | 72 | stopped = service_stop(service_name) | ||
825 | 71 | upstart_file = os.path.join(init_dir, "{}.conf".format(service_name)) | 73 | upstart_file = os.path.join(init_dir, "{}.conf".format(service_name)) |
826 | 72 | sysv_file = os.path.join(initd_dir, service_name) | 74 | sysv_file = os.path.join(initd_dir, service_name) |
827 | 73 | if os.path.exists(upstart_file): | 75 | if os.path.exists(upstart_file): |
828 | @@ -105,7 +107,9 @@ | |||
829 | 105 | "Unable to detect {0} as either Upstart {1} or SysV {2}".format( | 107 | "Unable to detect {0} as either Upstart {1} or SysV {2}".format( |
830 | 106 | service_name, upstart_file, sysv_file)) | 108 | service_name, upstart_file, sysv_file)) |
831 | 107 | 109 | ||
833 | 108 | started = service_start(service_name) | 110 | started = service_running(service_name) |
834 | 111 | if not started: | ||
835 | 112 | started = service_start(service_name) | ||
836 | 109 | return started | 113 | return started |
837 | 110 | 114 | ||
838 | 111 | 115 | ||
839 | @@ -566,7 +570,14 @@ | |||
840 | 566 | os.chdir(cur) | 570 | os.chdir(cur) |
841 | 567 | 571 | ||
842 | 568 | 572 | ||
844 | 569 | def chownr(path, owner, group, follow_links=True): | 573 | def chownr(path, owner, group, follow_links=True, chowntopdir=False): |
845 | 574 | """ | ||
846 | 575 | Recursively change user and group ownership of files and directories | ||
847 | 576 | in given path. Doesn't chown path itself by default, only its children. | ||
848 | 577 | |||
849 | 578 | :param bool follow_links: Also Chown links if True | ||
850 | 579 | :param bool chowntopdir: Also chown path itself if True | ||
851 | 580 | """ | ||
852 | 570 | uid = pwd.getpwnam(owner).pw_uid | 581 | uid = pwd.getpwnam(owner).pw_uid |
853 | 571 | gid = grp.getgrnam(group).gr_gid | 582 | gid = grp.getgrnam(group).gr_gid |
854 | 572 | if follow_links: | 583 | if follow_links: |
855 | @@ -574,6 +585,10 @@ | |||
856 | 574 | else: | 585 | else: |
857 | 575 | chown = os.lchown | 586 | chown = os.lchown |
858 | 576 | 587 | ||
859 | 588 | if chowntopdir: | ||
860 | 589 | broken_symlink = os.path.lexists(path) and not os.path.exists(path) | ||
861 | 590 | if not broken_symlink: | ||
862 | 591 | chown(path, uid, gid) | ||
863 | 577 | for root, dirs, files in os.walk(path): | 592 | for root, dirs, files in os.walk(path): |
864 | 578 | for name in dirs + files: | 593 | for name in dirs + files: |
865 | 579 | full = os.path.join(root, name) | 594 | full = os.path.join(root, name) |
866 | @@ -584,3 +599,19 @@ | |||
867 | 584 | 599 | ||
868 | 585 | def lchownr(path, owner, group): | 600 | def lchownr(path, owner, group): |
869 | 586 | chownr(path, owner, group, follow_links=False) | 601 | chownr(path, owner, group, follow_links=False) |
870 | 602 | |||
871 | 603 | |||
872 | 604 | def get_total_ram(): | ||
873 | 605 | '''The total amount of system RAM in bytes. | ||
874 | 606 | |||
875 | 607 | This is what is reported by the OS, and may be overcommitted when | ||
876 | 608 | there are multiple containers hosted on the same machine. | ||
877 | 609 | ''' | ||
878 | 610 | with open('/proc/meminfo', 'r') as f: | ||
879 | 611 | for line in f.readlines(): | ||
880 | 612 | if line: | ||
881 | 613 | key, value, unit = line.split() | ||
882 | 614 | if key == 'MemTotal:': | ||
883 | 615 | assert unit == 'kB', 'Unknown unit' | ||
884 | 616 | return int(value) * 1024 # Classic, not KiB. | ||
885 | 617 | raise NotImplementedError() | ||
886 | 587 | 618 | ||
887 | === modified file 'charmhelpers/core/hugepage.py' | |||
888 | --- charmhelpers/core/hugepage.py 2015-09-30 15:01:18 +0000 | |||
889 | +++ charmhelpers/core/hugepage.py 2015-11-24 20:07:18 +0000 | |||
890 | @@ -46,6 +46,8 @@ | |||
891 | 46 | group_info = add_group(group) | 46 | group_info = add_group(group) |
892 | 47 | gid = group_info.gr_gid | 47 | gid = group_info.gr_gid |
893 | 48 | add_user_to_group(user, group) | 48 | add_user_to_group(user, group) |
894 | 49 | if max_map_count < 2 * nr_hugepages: | ||
895 | 50 | max_map_count = 2 * nr_hugepages | ||
896 | 49 | sysctl_settings = { | 51 | sysctl_settings = { |
897 | 50 | 'vm.nr_hugepages': nr_hugepages, | 52 | 'vm.nr_hugepages': nr_hugepages, |
898 | 51 | 'vm.max_map_count': max_map_count, | 53 | 'vm.max_map_count': max_map_count, |
899 | 52 | 54 | ||
900 | === modified file 'charmhelpers/core/services/helpers.py' | |||
901 | --- charmhelpers/core/services/helpers.py 2015-08-18 17:34:34 +0000 | |||
902 | +++ charmhelpers/core/services/helpers.py 2015-11-24 20:07:18 +0000 | |||
903 | @@ -249,16 +249,18 @@ | |||
904 | 249 | :param int perms: The permissions of the rendered file | 249 | :param int perms: The permissions of the rendered file |
905 | 250 | :param partial on_change_action: functools partial to be executed when | 250 | :param partial on_change_action: functools partial to be executed when |
906 | 251 | rendered file changes | 251 | rendered file changes |
907 | 252 | :param jinja2 loader template_loader: A jinja2 template loader | ||
908 | 252 | """ | 253 | """ |
909 | 253 | def __init__(self, source, target, | 254 | def __init__(self, source, target, |
910 | 254 | owner='root', group='root', perms=0o444, | 255 | owner='root', group='root', perms=0o444, |
912 | 255 | on_change_action=None): | 256 | on_change_action=None, template_loader=None): |
913 | 256 | self.source = source | 257 | self.source = source |
914 | 257 | self.target = target | 258 | self.target = target |
915 | 258 | self.owner = owner | 259 | self.owner = owner |
916 | 259 | self.group = group | 260 | self.group = group |
917 | 260 | self.perms = perms | 261 | self.perms = perms |
918 | 261 | self.on_change_action = on_change_action | 262 | self.on_change_action = on_change_action |
919 | 263 | self.template_loader = template_loader | ||
920 | 262 | 264 | ||
921 | 263 | def __call__(self, manager, service_name, event_name): | 265 | def __call__(self, manager, service_name, event_name): |
922 | 264 | pre_checksum = '' | 266 | pre_checksum = '' |
923 | @@ -269,7 +271,8 @@ | |||
924 | 269 | for ctx in service.get('required_data', []): | 271 | for ctx in service.get('required_data', []): |
925 | 270 | context.update(ctx) | 272 | context.update(ctx) |
926 | 271 | templating.render(self.source, self.target, context, | 273 | templating.render(self.source, self.target, context, |
928 | 272 | self.owner, self.group, self.perms) | 274 | self.owner, self.group, self.perms, |
929 | 275 | template_loader=self.template_loader) | ||
930 | 273 | if self.on_change_action: | 276 | if self.on_change_action: |
931 | 274 | if pre_checksum == host.file_hash(self.target): | 277 | if pre_checksum == host.file_hash(self.target): |
932 | 275 | hookenv.log( | 278 | hookenv.log( |
933 | 276 | 279 | ||
934 | === modified file 'charmhelpers/core/templating.py' | |||
935 | --- charmhelpers/core/templating.py 2015-03-20 17:15:02 +0000 | |||
936 | +++ charmhelpers/core/templating.py 2015-11-24 20:07:18 +0000 | |||
937 | @@ -21,7 +21,7 @@ | |||
938 | 21 | 21 | ||
939 | 22 | 22 | ||
940 | 23 | def render(source, target, context, owner='root', group='root', | 23 | def render(source, target, context, owner='root', group='root', |
942 | 24 | perms=0o444, templates_dir=None, encoding='UTF-8'): | 24 | perms=0o444, templates_dir=None, encoding='UTF-8', template_loader=None): |
943 | 25 | """ | 25 | """ |
944 | 26 | Render a template. | 26 | Render a template. |
945 | 27 | 27 | ||
946 | @@ -52,17 +52,24 @@ | |||
947 | 52 | apt_install('python-jinja2', fatal=True) | 52 | apt_install('python-jinja2', fatal=True) |
948 | 53 | from jinja2 import FileSystemLoader, Environment, exceptions | 53 | from jinja2 import FileSystemLoader, Environment, exceptions |
949 | 54 | 54 | ||
953 | 55 | if templates_dir is None: | 55 | if template_loader: |
954 | 56 | templates_dir = os.path.join(hookenv.charm_dir(), 'templates') | 56 | template_env = Environment(loader=template_loader) |
955 | 57 | loader = Environment(loader=FileSystemLoader(templates_dir)) | 57 | else: |
956 | 58 | if templates_dir is None: | ||
957 | 59 | templates_dir = os.path.join(hookenv.charm_dir(), 'templates') | ||
958 | 60 | template_env = Environment(loader=FileSystemLoader(templates_dir)) | ||
959 | 58 | try: | 61 | try: |
960 | 59 | source = source | 62 | source = source |
962 | 60 | template = loader.get_template(source) | 63 | template = template_env.get_template(source) |
963 | 61 | except exceptions.TemplateNotFound as e: | 64 | except exceptions.TemplateNotFound as e: |
964 | 62 | hookenv.log('Could not load template %s from %s.' % | 65 | hookenv.log('Could not load template %s from %s.' % |
965 | 63 | (source, templates_dir), | 66 | (source, templates_dir), |
966 | 64 | level=hookenv.ERROR) | 67 | level=hookenv.ERROR) |
967 | 65 | raise e | 68 | raise e |
968 | 66 | content = template.render(context) | 69 | content = template.render(context) |
970 | 67 | host.mkdir(os.path.dirname(target), owner, group, perms=0o755) | 70 | target_dir = os.path.dirname(target) |
971 | 71 | if not os.path.exists(target_dir): | ||
972 | 72 | # This is a terrible default directory permission, as the file | ||
973 | 73 | # or its siblings will often contain secrets. | ||
974 | 74 | host.mkdir(os.path.dirname(target), owner, group, perms=0o755) | ||
975 | 68 | host.write_file(target, content.encode(encoding), owner, group, perms) | 75 | host.write_file(target, content.encode(encoding), owner, group, perms) |
976 | 69 | 76 | ||
977 | === modified file 'charmhelpers/fetch/__init__.py' | |||
978 | --- charmhelpers/fetch/__init__.py 2015-08-18 17:34:34 +0000 | |||
979 | +++ charmhelpers/fetch/__init__.py 2015-11-24 20:07:18 +0000 | |||
980 | @@ -225,12 +225,12 @@ | |||
981 | 225 | 225 | ||
982 | 226 | def apt_mark(packages, mark, fatal=False): | 226 | def apt_mark(packages, mark, fatal=False): |
983 | 227 | """Flag one or more packages using apt-mark""" | 227 | """Flag one or more packages using apt-mark""" |
984 | 228 | log("Marking {} as {}".format(packages, mark)) | ||
985 | 228 | cmd = ['apt-mark', mark] | 229 | cmd = ['apt-mark', mark] |
986 | 229 | if isinstance(packages, six.string_types): | 230 | if isinstance(packages, six.string_types): |
987 | 230 | cmd.append(packages) | 231 | cmd.append(packages) |
988 | 231 | else: | 232 | else: |
989 | 232 | cmd.extend(packages) | 233 | cmd.extend(packages) |
990 | 233 | log("Holding {}".format(packages)) | ||
991 | 234 | 234 | ||
992 | 235 | if fatal: | 235 | if fatal: |
993 | 236 | subprocess.check_call(cmd, universal_newlines=True) | 236 | subprocess.check_call(cmd, universal_newlines=True) |
994 | 237 | 237 | ||
995 | === modified file 'charmhelpers/fetch/bzrurl.py' | |||
996 | --- charmhelpers/fetch/bzrurl.py 2015-03-20 17:15:02 +0000 | |||
997 | +++ charmhelpers/fetch/bzrurl.py 2015-11-24 20:07:18 +0000 | |||
998 | @@ -64,11 +64,15 @@ | |||
999 | 64 | except Exception as e: | 64 | except Exception as e: |
1000 | 65 | raise e | 65 | raise e |
1001 | 66 | 66 | ||
1003 | 67 | def install(self, source): | 67 | def install(self, source, dest=None): |
1004 | 68 | url_parts = self.parse_url(source) | 68 | url_parts = self.parse_url(source) |
1005 | 69 | branch_name = url_parts.path.strip("/").split("/")[-1] | 69 | branch_name = url_parts.path.strip("/").split("/")[-1] |
1008 | 70 | dest_dir = os.path.join(os.environ.get('CHARM_DIR'), "fetched", | 70 | if dest: |
1009 | 71 | branch_name) | 71 | dest_dir = os.path.join(dest, branch_name) |
1010 | 72 | else: | ||
1011 | 73 | dest_dir = os.path.join(os.environ.get('CHARM_DIR'), "fetched", | ||
1012 | 74 | branch_name) | ||
1013 | 75 | |||
1014 | 72 | if not os.path.exists(dest_dir): | 76 | if not os.path.exists(dest_dir): |
1015 | 73 | mkdir(dest_dir, perms=0o755) | 77 | mkdir(dest_dir, perms=0o755) |
1016 | 74 | try: | 78 | try: |
1017 | 75 | 79 | ||
1018 | === modified file 'hooks/glance_utils.py' | |||
1019 | --- hooks/glance_utils.py 2015-10-30 22:11:38 +0000 | |||
1020 | +++ hooks/glance_utils.py 2015-11-24 20:07:18 +0000 | |||
1021 | @@ -70,6 +70,8 @@ | |||
1022 | 70 | retry_on_exception, | 70 | retry_on_exception, |
1023 | 71 | ) | 71 | ) |
1024 | 72 | 72 | ||
1025 | 73 | from charmhelpers.core.unitdata import HookData, kv | ||
1026 | 74 | |||
1027 | 73 | 75 | ||
1028 | 74 | CLUSTER_RES = "grp_glance_vips" | 76 | CLUSTER_RES = "grp_glance_vips" |
1029 | 75 | 77 | ||
1030 | @@ -491,3 +493,21 @@ | |||
1031 | 491 | swift_connection.post_account(headers={'x-account-meta-temp-url-key': | 493 | swift_connection.post_account(headers={'x-account-meta-temp-url-key': |
1032 | 492 | temp_url_key}) | 494 | temp_url_key}) |
1033 | 493 | return temp_url_key | 495 | return temp_url_key |
1034 | 496 | |||
1035 | 497 | |||
1036 | 498 | def assess_status(): | ||
1037 | 499 | """Assess status of current unit""" | ||
1038 | 500 | if is_paused(): | ||
1039 | 501 | return ("maintenance", | ||
1040 | 502 | "Paused. Use 'resume' action to resume normal service.") | ||
1041 | 503 | else: | ||
1042 | 504 | return ("active", "Unit is ready") | ||
1043 | 505 | |||
1044 | 506 | |||
1045 | 507 | def is_paused(): | ||
1046 | 508 | """Is the unit paused?""" | ||
1047 | 509 | with HookData()(): | ||
1048 | 510 | if kv().get('unit-paused'): | ||
1049 | 511 | return True | ||
1050 | 512 | else: | ||
1051 | 513 | return False | ||
1052 | 494 | 514 | ||
1053 | === modified file 'tests/charmhelpers/contrib/openstack/amulet/deployment.py' | |||
1054 | --- tests/charmhelpers/contrib/openstack/amulet/deployment.py 2015-09-30 15:01:18 +0000 | |||
1055 | +++ tests/charmhelpers/contrib/openstack/amulet/deployment.py 2015-11-24 20:07:18 +0000 | |||
1056 | @@ -14,12 +14,18 @@ | |||
1057 | 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 |
1058 | 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/>. |
1059 | 16 | 16 | ||
1060 | 17 | import logging | ||
1061 | 18 | import re | ||
1062 | 19 | import sys | ||
1063 | 17 | import six | 20 | import six |
1064 | 18 | from collections import OrderedDict | 21 | from collections import OrderedDict |
1065 | 19 | from charmhelpers.contrib.amulet.deployment import ( | 22 | from charmhelpers.contrib.amulet.deployment import ( |
1066 | 20 | AmuletDeployment | 23 | AmuletDeployment |
1067 | 21 | ) | 24 | ) |
1068 | 22 | 25 | ||
1069 | 26 | DEBUG = logging.DEBUG | ||
1070 | 27 | ERROR = logging.ERROR | ||
1071 | 28 | |||
1072 | 23 | 29 | ||
1073 | 24 | class OpenStackAmuletDeployment(AmuletDeployment): | 30 | class OpenStackAmuletDeployment(AmuletDeployment): |
1074 | 25 | """OpenStack amulet deployment. | 31 | """OpenStack amulet deployment. |
1075 | @@ -28,9 +34,12 @@ | |||
1076 | 28 | that is specifically for use by OpenStack charms. | 34 | that is specifically for use by OpenStack charms. |
1077 | 29 | """ | 35 | """ |
1078 | 30 | 36 | ||
1080 | 31 | def __init__(self, series=None, openstack=None, source=None, stable=True): | 37 | def __init__(self, series=None, openstack=None, source=None, |
1081 | 38 | stable=True, log_level=DEBUG): | ||
1082 | 32 | """Initialize the deployment environment.""" | 39 | """Initialize the deployment environment.""" |
1083 | 33 | super(OpenStackAmuletDeployment, self).__init__(series) | 40 | super(OpenStackAmuletDeployment, self).__init__(series) |
1084 | 41 | self.log = self.get_logger(level=log_level) | ||
1085 | 42 | self.log.info('OpenStackAmuletDeployment: init') | ||
1086 | 34 | self.openstack = openstack | 43 | self.openstack = openstack |
1087 | 35 | self.source = source | 44 | self.source = source |
1088 | 36 | self.stable = stable | 45 | self.stable = stable |
1089 | @@ -38,6 +47,22 @@ | |||
1090 | 38 | # out. | 47 | # out. |
1091 | 39 | self.current_next = "trusty" | 48 | self.current_next = "trusty" |
1092 | 40 | 49 | ||
1093 | 50 | def get_logger(self, name="deployment-logger", level=logging.DEBUG): | ||
1094 | 51 | """Get a logger object that will log to stdout.""" | ||
1095 | 52 | log = logging | ||
1096 | 53 | logger = log.getLogger(name) | ||
1097 | 54 | fmt = log.Formatter("%(asctime)s %(funcName)s " | ||
1098 | 55 | "%(levelname)s: %(message)s") | ||
1099 | 56 | |||
1100 | 57 | handler = log.StreamHandler(stream=sys.stdout) | ||
1101 | 58 | handler.setLevel(level) | ||
1102 | 59 | handler.setFormatter(fmt) | ||
1103 | 60 | |||
1104 | 61 | logger.addHandler(handler) | ||
1105 | 62 | logger.setLevel(level) | ||
1106 | 63 | |||
1107 | 64 | return logger | ||
1108 | 65 | |||
1109 | 41 | def _determine_branch_locations(self, other_services): | 66 | def _determine_branch_locations(self, other_services): |
1110 | 42 | """Determine the branch locations for the other services. | 67 | """Determine the branch locations for the other services. |
1111 | 43 | 68 | ||
1112 | @@ -45,6 +70,8 @@ | |||
1113 | 45 | 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 |
1114 | 46 | stable or next branches for the other_services.""" | 71 | stable or next branches for the other_services.""" |
1115 | 47 | 72 | ||
1116 | 73 | self.log.info('OpenStackAmuletDeployment: determine branch locations') | ||
1117 | 74 | |||
1118 | 48 | # Charms outside the lp:~openstack-charmers namespace | 75 | # Charms outside the lp:~openstack-charmers namespace |
1119 | 49 | base_charms = ['mysql', 'mongodb', 'nrpe'] | 76 | base_charms = ['mysql', 'mongodb', 'nrpe'] |
1120 | 50 | 77 | ||
1121 | @@ -82,6 +109,8 @@ | |||
1122 | 82 | 109 | ||
1123 | 83 | def _add_services(self, this_service, other_services): | 110 | def _add_services(self, this_service, other_services): |
1124 | 84 | """Add services to the deployment and set openstack-origin/source.""" | 111 | """Add services to the deployment and set openstack-origin/source.""" |
1125 | 112 | self.log.info('OpenStackAmuletDeployment: adding services') | ||
1126 | 113 | |||
1127 | 85 | other_services = self._determine_branch_locations(other_services) | 114 | other_services = self._determine_branch_locations(other_services) |
1128 | 86 | 115 | ||
1129 | 87 | super(OpenStackAmuletDeployment, self)._add_services(this_service, | 116 | super(OpenStackAmuletDeployment, self)._add_services(this_service, |
1130 | @@ -95,7 +124,8 @@ | |||
1131 | 95 | 'ceph-osd', 'ceph-radosgw'] | 124 | 'ceph-osd', 'ceph-radosgw'] |
1132 | 96 | 125 | ||
1133 | 97 | # Charms which can not use openstack-origin, ie. many subordinates | 126 | # Charms which can not use openstack-origin, ie. many subordinates |
1135 | 98 | no_origin = ['cinder-ceph', 'hacluster', 'neutron-openvswitch', 'nrpe'] | 127 | no_origin = ['cinder-ceph', 'hacluster', 'neutron-openvswitch', 'nrpe', |
1136 | 128 | 'openvswitch-odl', 'neutron-api-odl', 'odl-controller'] | ||
1137 | 99 | 129 | ||
1138 | 100 | if self.openstack: | 130 | if self.openstack: |
1139 | 101 | for svc in services: | 131 | for svc in services: |
1140 | @@ -111,9 +141,79 @@ | |||
1141 | 111 | 141 | ||
1142 | 112 | def _configure_services(self, configs): | 142 | def _configure_services(self, configs): |
1143 | 113 | """Configure all of the services.""" | 143 | """Configure all of the services.""" |
1144 | 144 | self.log.info('OpenStackAmuletDeployment: configure services') | ||
1145 | 114 | for service, config in six.iteritems(configs): | 145 | for service, config in six.iteritems(configs): |
1146 | 115 | self.d.configure(service, config) | 146 | self.d.configure(service, config) |
1147 | 116 | 147 | ||
1148 | 148 | def _auto_wait_for_status(self, message=None, exclude_services=None, | ||
1149 | 149 | include_only=None, timeout=1800): | ||
1150 | 150 | """Wait for all units to have a specific extended status, except | ||
1151 | 151 | for any defined as excluded. Unless specified via message, any | ||
1152 | 152 | status containing any case of 'ready' will be considered a match. | ||
1153 | 153 | |||
1154 | 154 | Examples of message usage: | ||
1155 | 155 | |||
1156 | 156 | Wait for all unit status to CONTAIN any case of 'ready' or 'ok': | ||
1157 | 157 | message = re.compile('.*ready.*|.*ok.*', re.IGNORECASE) | ||
1158 | 158 | |||
1159 | 159 | Wait for all units to reach this status (exact match): | ||
1160 | 160 | message = re.compile('^Unit is ready and clustered$') | ||
1161 | 161 | |||
1162 | 162 | Wait for all units to reach any one of these (exact match): | ||
1163 | 163 | message = re.compile('Unit is ready|OK|Ready') | ||
1164 | 164 | |||
1165 | 165 | Wait for at least one unit to reach this status (exact match): | ||
1166 | 166 | message = {'ready'} | ||
1167 | 167 | |||
1168 | 168 | See Amulet's sentry.wait_for_messages() for message usage detail. | ||
1169 | 169 | https://github.com/juju/amulet/blob/master/amulet/sentry.py | ||
1170 | 170 | |||
1171 | 171 | :param message: Expected status match | ||
1172 | 172 | :param exclude_services: List of juju service names to ignore, | ||
1173 | 173 | not to be used in conjuction with include_only. | ||
1174 | 174 | :param include_only: List of juju service names to exclusively check, | ||
1175 | 175 | not to be used in conjuction with exclude_services. | ||
1176 | 176 | :param timeout: Maximum time in seconds to wait for status match | ||
1177 | 177 | :returns: None. Raises if timeout is hit. | ||
1178 | 178 | """ | ||
1179 | 179 | self.log.info('Waiting for extended status on units...') | ||
1180 | 180 | |||
1181 | 181 | all_services = self.d.services.keys() | ||
1182 | 182 | |||
1183 | 183 | if exclude_services and include_only: | ||
1184 | 184 | raise ValueError('exclude_services can not be used ' | ||
1185 | 185 | 'with include_only') | ||
1186 | 186 | |||
1187 | 187 | if message: | ||
1188 | 188 | if isinstance(message, re._pattern_type): | ||
1189 | 189 | match = message.pattern | ||
1190 | 190 | else: | ||
1191 | 191 | match = message | ||
1192 | 192 | |||
1193 | 193 | self.log.debug('Custom extended status wait match: ' | ||
1194 | 194 | '{}'.format(match)) | ||
1195 | 195 | else: | ||
1196 | 196 | self.log.debug('Default extended status wait match: contains ' | ||
1197 | 197 | 'READY (case-insensitive)') | ||
1198 | 198 | message = re.compile('.*ready.*', re.IGNORECASE) | ||
1199 | 199 | |||
1200 | 200 | if exclude_services: | ||
1201 | 201 | self.log.debug('Excluding services from extended status match: ' | ||
1202 | 202 | '{}'.format(exclude_services)) | ||
1203 | 203 | else: | ||
1204 | 204 | exclude_services = [] | ||
1205 | 205 | |||
1206 | 206 | if include_only: | ||
1207 | 207 | services = include_only | ||
1208 | 208 | else: | ||
1209 | 209 | services = list(set(all_services) - set(exclude_services)) | ||
1210 | 210 | |||
1211 | 211 | self.log.debug('Waiting up to {}s for extended status on services: ' | ||
1212 | 212 | '{}'.format(timeout, services)) | ||
1213 | 213 | service_messages = {service: message for service in services} | ||
1214 | 214 | self.d.sentry.wait_for_messages(service_messages, timeout=timeout) | ||
1215 | 215 | self.log.info('OK') | ||
1216 | 216 | |||
1217 | 117 | def _get_openstack_release(self): | 217 | def _get_openstack_release(self): |
1218 | 118 | """Get openstack release. | 218 | """Get openstack release. |
1219 | 119 | 219 | ||
1220 | 120 | 220 | ||
1221 | === modified file 'tests/charmhelpers/contrib/openstack/amulet/utils.py' | |||
1222 | --- tests/charmhelpers/contrib/openstack/amulet/utils.py 2015-09-30 15:01:18 +0000 | |||
1223 | +++ tests/charmhelpers/contrib/openstack/amulet/utils.py 2015-11-24 20:07:18 +0000 | |||
1224 | @@ -18,6 +18,7 @@ | |||
1225 | 18 | import json | 18 | import json |
1226 | 19 | import logging | 19 | import logging |
1227 | 20 | import os | 20 | import os |
1228 | 21 | import re | ||
1229 | 21 | import six | 22 | import six |
1230 | 22 | import time | 23 | import time |
1231 | 23 | import urllib | 24 | import urllib |
1232 | @@ -604,7 +605,22 @@ | |||
1233 | 604 | '{}'.format(sample_type, samples)) | 605 | '{}'.format(sample_type, samples)) |
1234 | 605 | return None | 606 | return None |
1235 | 606 | 607 | ||
1237 | 607 | # rabbitmq/amqp specific helpers: | 608 | # rabbitmq/amqp specific helpers: |
1238 | 609 | |||
1239 | 610 | def rmq_wait_for_cluster(self, deployment, init_sleep=15, timeout=1200): | ||
1240 | 611 | """Wait for rmq units extended status to show cluster readiness, | ||
1241 | 612 | after an optional initial sleep period. Initial sleep is likely | ||
1242 | 613 | necessary to be effective following a config change, as status | ||
1243 | 614 | message may not instantly update to non-ready.""" | ||
1244 | 615 | |||
1245 | 616 | if init_sleep: | ||
1246 | 617 | time.sleep(init_sleep) | ||
1247 | 618 | |||
1248 | 619 | message = re.compile('^Unit is ready and clustered$') | ||
1249 | 620 | deployment._auto_wait_for_status(message=message, | ||
1250 | 621 | timeout=timeout, | ||
1251 | 622 | include_only=['rabbitmq-server']) | ||
1252 | 623 | |||
1253 | 608 | def add_rmq_test_user(self, sentry_units, | 624 | def add_rmq_test_user(self, sentry_units, |
1254 | 609 | username="testuser1", password="changeme"): | 625 | username="testuser1", password="changeme"): |
1255 | 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 |
1256 | @@ -805,7 +821,10 @@ | |||
1257 | 805 | if port: | 821 | if port: |
1258 | 806 | config['ssl_port'] = port | 822 | config['ssl_port'] = port |
1259 | 807 | 823 | ||
1261 | 808 | deployment.configure('rabbitmq-server', config) | 824 | deployment.d.configure('rabbitmq-server', config) |
1262 | 825 | |||
1263 | 826 | # Wait for unit status | ||
1264 | 827 | self.rmq_wait_for_cluster(deployment) | ||
1265 | 809 | 828 | ||
1266 | 810 | # Confirm | 829 | # Confirm |
1267 | 811 | tries = 0 | 830 | tries = 0 |
1268 | @@ -832,7 +851,10 @@ | |||
1269 | 832 | 851 | ||
1270 | 833 | # Disable RMQ SSL | 852 | # Disable RMQ SSL |
1271 | 834 | config = {'ssl': 'off'} | 853 | config = {'ssl': 'off'} |
1273 | 835 | deployment.configure('rabbitmq-server', config) | 854 | deployment.d.configure('rabbitmq-server', config) |
1274 | 855 | |||
1275 | 856 | # Wait for unit status | ||
1276 | 857 | self.rmq_wait_for_cluster(deployment) | ||
1277 | 836 | 858 | ||
1278 | 837 | # Confirm | 859 | # Confirm |
1279 | 838 | tries = 0 | 860 | tries = 0 |
1280 | 839 | 861 | ||
1281 | === modified file 'unit_tests/test_actions.py' | |||
1282 | --- unit_tests/test_actions.py 2015-09-02 11:40:06 +0000 | |||
1283 | +++ unit_tests/test_actions.py 2015-11-24 20:07:18 +0000 | |||
1284 | @@ -12,7 +12,8 @@ | |||
1285 | 12 | 12 | ||
1286 | 13 | def setUp(self): | 13 | def setUp(self): |
1287 | 14 | super(PauseTestCase, self).setUp( | 14 | super(PauseTestCase, self).setUp( |
1289 | 15 | actions.actions, ["service_pause", "status_set"]) | 15 | actions.actions, ["service_pause", "status_set", |
1290 | 16 | "HookData", "kv", "assess_status"]) | ||
1291 | 16 | 17 | ||
1292 | 17 | def test_pauses_services(self): | 18 | def test_pauses_services(self): |
1293 | 18 | """Pause action pauses all Glance services.""" | 19 | """Pause action pauses all Glance services.""" |
1294 | @@ -23,6 +24,7 @@ | |||
1295 | 23 | return True | 24 | return True |
1296 | 24 | 25 | ||
1297 | 25 | self.service_pause.side_effect = fake_service_pause | 26 | self.service_pause.side_effect = fake_service_pause |
1298 | 27 | self.assess_status.return_value = ("maintenance", "Foo",) | ||
1299 | 26 | 28 | ||
1300 | 27 | actions.actions.pause([]) | 29 | actions.actions.pause([]) |
1301 | 28 | self.assertItemsEqual( | 30 | self.assertItemsEqual( |
1302 | @@ -48,18 +50,21 @@ | |||
1303 | 48 | 50 | ||
1304 | 49 | def test_status_mode(self): | 51 | def test_status_mode(self): |
1305 | 50 | """Pause action sets the status to maintenance.""" | 52 | """Pause action sets the status to maintenance.""" |
1309 | 51 | status_calls = [] | 53 | self.HookData()().return_value = True |
1310 | 52 | self.status_set.side_effect = lambda state, msg: status_calls.append( | 54 | self.assess_status.return_value = ("maintenance", "Foo",) |
1308 | 53 | state) | ||
1311 | 54 | 55 | ||
1312 | 55 | actions.actions.pause([]) | 56 | actions.actions.pause([]) |
1314 | 56 | self.assertEqual(status_calls, ["maintenance"]) | 57 | self.kv().set.assert_called_with('unit-paused', True) |
1315 | 57 | 58 | ||
1316 | 58 | def test_status_message(self): | 59 | def test_status_message(self): |
1317 | 59 | """Pause action sets a status message reflecting that it's paused.""" | 60 | """Pause action sets a status message reflecting that it's paused.""" |
1318 | 60 | status_calls = [] | 61 | status_calls = [] |
1319 | 61 | self.status_set.side_effect = lambda state, msg: status_calls.append( | 62 | self.status_set.side_effect = lambda state, msg: status_calls.append( |
1320 | 62 | msg) | 63 | msg) |
1321 | 64 | self.HookData()().return_value = True | ||
1322 | 65 | self.assess_status.return_value = ( | ||
1323 | 66 | "maintenance", "Paused. Use 'resume' action to resume normal" | ||
1324 | 67 | " service.") | ||
1325 | 63 | 68 | ||
1326 | 64 | actions.actions.pause([]) | 69 | actions.actions.pause([]) |
1327 | 65 | self.assertEqual( | 70 | self.assertEqual( |
charm_lint_check #14311 glance for fcorrea mp278498
LINT OK: passed
Build: http:// 10.245. 162.77: 8080/job/ charm_lint_ check/14311/