summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCorey Bryant <corey.bryant@canonical.com>2019-01-08 15:15:41 +0000
committerCorey Bryant <corey.bryant@canonical.com>2019-01-08 15:15:45 +0000
commit609631e658578b4d0ee4b3ce2e1fac8fcd120aaf (patch)
tree1c510a3e6013d8a24c896a959b5f92732147cafe
parentacd93c43959c3c2e927d130b926447b874f00d76 (diff)
Sync charm-helpers
Notes
Notes (review): Verified+1: Canonical CI <uosci-testing-bot@ubuntu.com> Code-Review+2: Frode Nordahl <frode.nordahl@canonical.com> Workflow+1: Frode Nordahl <frode.nordahl@canonical.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Wed, 09 Jan 2019 08:40:39 +0000 Reviewed-on: https://review.openstack.org/629210 Project: openstack/charm-ceph-proxy Branch: refs/heads/master
-rw-r--r--hooks/charmhelpers/contrib/charmsupport/nrpe.py25
-rw-r--r--hooks/charmhelpers/contrib/openstack/utils.py113
-rw-r--r--hooks/charmhelpers/contrib/storage/linux/loopback.py6
-rw-r--r--hooks/charmhelpers/fetch/ubuntu.py8
4 files changed, 111 insertions, 41 deletions
diff --git a/hooks/charmhelpers/contrib/charmsupport/nrpe.py b/hooks/charmhelpers/contrib/charmsupport/nrpe.py
index e3d10c1..f59fdd6 100644
--- a/hooks/charmhelpers/contrib/charmsupport/nrpe.py
+++ b/hooks/charmhelpers/contrib/charmsupport/nrpe.py
@@ -305,7 +305,7 @@ class NRPE(object):
305 305
306 # update-status hooks are configured to firing every 5 minutes by 306 # update-status hooks are configured to firing every 5 minutes by
307 # default. When nagios-nrpe-server is restarted, the nagios server 307 # default. When nagios-nrpe-server is restarted, the nagios server
308 # reports checks failing causing unneccessary alerts. Let's not restart 308 # reports checks failing causing unnecessary alerts. Let's not restart
309 # on update-status hooks. 309 # on update-status hooks.
310 if not hook_name() == 'update-status': 310 if not hook_name() == 'update-status':
311 service('restart', 'nagios-nrpe-server') 311 service('restart', 'nagios-nrpe-server')
@@ -416,15 +416,20 @@ def copy_nrpe_checks(nrpe_files_dir=None):
416 416
417 """ 417 """
418 NAGIOS_PLUGINS = '/usr/local/lib/nagios/plugins' 418 NAGIOS_PLUGINS = '/usr/local/lib/nagios/plugins'
419 default_nrpe_files_dir = os.path.join( 419 if nrpe_files_dir is None:
420 os.getenv('CHARM_DIR'), 420 # determine if "charmhelpers" is in CHARMDIR or CHARMDIR/hooks
421 'hooks', 421 for segment in ['.', 'hooks']:
422 'charmhelpers', 422 nrpe_files_dir = os.path.abspath(os.path.join(
423 'contrib', 423 os.getenv('CHARM_DIR'),
424 'openstack', 424 segment,
425 'files') 425 'charmhelpers',
426 if not nrpe_files_dir: 426 'contrib',
427 nrpe_files_dir = default_nrpe_files_dir 427 'openstack',
428 'files'))
429 if os.path.isdir(nrpe_files_dir):
430 break
431 else:
432 raise RuntimeError("Couldn't find charmhelpers directory")
428 if not os.path.exists(NAGIOS_PLUGINS): 433 if not os.path.exists(NAGIOS_PLUGINS):
429 os.makedirs(NAGIOS_PLUGINS) 434 os.makedirs(NAGIOS_PLUGINS)
430 for fname in glob.glob(os.path.join(nrpe_files_dir, "check_*")): 435 for fname in glob.glob(os.path.join(nrpe_files_dir, "check_*")):
diff --git a/hooks/charmhelpers/contrib/openstack/utils.py b/hooks/charmhelpers/contrib/openstack/utils.py
index 29cad08..4e432a2 100644
--- a/hooks/charmhelpers/contrib/openstack/utils.py
+++ b/hooks/charmhelpers/contrib/openstack/utils.py
@@ -73,6 +73,8 @@ from charmhelpers.core.host import (
73 service_running, 73 service_running,
74 service_pause, 74 service_pause,
75 service_resume, 75 service_resume,
76 service_stop,
77 service_start,
76 restart_on_change_helper, 78 restart_on_change_helper,
77) 79)
78from charmhelpers.fetch import ( 80from charmhelpers.fetch import (
@@ -116,6 +118,7 @@ OPENSTACK_RELEASES = (
116 'pike', 118 'pike',
117 'queens', 119 'queens',
118 'rocky', 120 'rocky',
121 'stein',
119) 122)
120 123
121UBUNTU_OPENSTACK_RELEASE = OrderedDict([ 124UBUNTU_OPENSTACK_RELEASE = OrderedDict([
@@ -134,6 +137,7 @@ UBUNTU_OPENSTACK_RELEASE = OrderedDict([
134 ('artful', 'pike'), 137 ('artful', 'pike'),
135 ('bionic', 'queens'), 138 ('bionic', 'queens'),
136 ('cosmic', 'rocky'), 139 ('cosmic', 'rocky'),
140 ('disco', 'stein'),
137]) 141])
138 142
139 143
@@ -153,6 +157,7 @@ OPENSTACK_CODENAMES = OrderedDict([
153 ('2017.2', 'pike'), 157 ('2017.2', 'pike'),
154 ('2018.1', 'queens'), 158 ('2018.1', 'queens'),
155 ('2018.2', 'rocky'), 159 ('2018.2', 'rocky'),
160 ('2019.1', 'stein'),
156]) 161])
157 162
158# The ugly duckling - must list releases oldest to newest 163# The ugly duckling - must list releases oldest to newest
@@ -187,6 +192,8 @@ SWIFT_CODENAMES = OrderedDict([
187 ['2.16.0', '2.17.0']), 192 ['2.16.0', '2.17.0']),
188 ('rocky', 193 ('rocky',
189 ['2.18.0', '2.19.0']), 194 ['2.18.0', '2.19.0']),
195 ('stein',
196 ['2.19.0']),
190]) 197])
191 198
192# >= Liberty version->codename mapping 199# >= Liberty version->codename mapping
@@ -199,6 +206,7 @@ PACKAGE_CODENAMES = {
199 ('16', 'pike'), 206 ('16', 'pike'),
200 ('17', 'queens'), 207 ('17', 'queens'),
201 ('18', 'rocky'), 208 ('18', 'rocky'),
209 ('19', 'stein'),
202 ]), 210 ]),
203 'neutron-common': OrderedDict([ 211 'neutron-common': OrderedDict([
204 ('7', 'liberty'), 212 ('7', 'liberty'),
@@ -208,6 +216,7 @@ PACKAGE_CODENAMES = {
208 ('11', 'pike'), 216 ('11', 'pike'),
209 ('12', 'queens'), 217 ('12', 'queens'),
210 ('13', 'rocky'), 218 ('13', 'rocky'),
219 ('14', 'stein'),
211 ]), 220 ]),
212 'cinder-common': OrderedDict([ 221 'cinder-common': OrderedDict([
213 ('7', 'liberty'), 222 ('7', 'liberty'),
@@ -217,6 +226,7 @@ PACKAGE_CODENAMES = {
217 ('11', 'pike'), 226 ('11', 'pike'),
218 ('12', 'queens'), 227 ('12', 'queens'),
219 ('13', 'rocky'), 228 ('13', 'rocky'),
229 ('14', 'stein'),
220 ]), 230 ]),
221 'keystone': OrderedDict([ 231 'keystone': OrderedDict([
222 ('8', 'liberty'), 232 ('8', 'liberty'),
@@ -226,6 +236,7 @@ PACKAGE_CODENAMES = {
226 ('12', 'pike'), 236 ('12', 'pike'),
227 ('13', 'queens'), 237 ('13', 'queens'),
228 ('14', 'rocky'), 238 ('14', 'rocky'),
239 ('15', 'stein'),
229 ]), 240 ]),
230 'horizon-common': OrderedDict([ 241 'horizon-common': OrderedDict([
231 ('8', 'liberty'), 242 ('8', 'liberty'),
@@ -235,6 +246,7 @@ PACKAGE_CODENAMES = {
235 ('12', 'pike'), 246 ('12', 'pike'),
236 ('13', 'queens'), 247 ('13', 'queens'),
237 ('14', 'rocky'), 248 ('14', 'rocky'),
249 ('15', 'stein'),
238 ]), 250 ]),
239 'ceilometer-common': OrderedDict([ 251 'ceilometer-common': OrderedDict([
240 ('5', 'liberty'), 252 ('5', 'liberty'),
@@ -244,6 +256,7 @@ PACKAGE_CODENAMES = {
244 ('9', 'pike'), 256 ('9', 'pike'),
245 ('10', 'queens'), 257 ('10', 'queens'),
246 ('11', 'rocky'), 258 ('11', 'rocky'),
259 ('12', 'stein'),
247 ]), 260 ]),
248 'heat-common': OrderedDict([ 261 'heat-common': OrderedDict([
249 ('5', 'liberty'), 262 ('5', 'liberty'),
@@ -253,6 +266,7 @@ PACKAGE_CODENAMES = {
253 ('9', 'pike'), 266 ('9', 'pike'),
254 ('10', 'queens'), 267 ('10', 'queens'),
255 ('11', 'rocky'), 268 ('11', 'rocky'),
269 ('12', 'stein'),
256 ]), 270 ]),
257 'glance-common': OrderedDict([ 271 'glance-common': OrderedDict([
258 ('11', 'liberty'), 272 ('11', 'liberty'),
@@ -262,6 +276,7 @@ PACKAGE_CODENAMES = {
262 ('15', 'pike'), 276 ('15', 'pike'),
263 ('16', 'queens'), 277 ('16', 'queens'),
264 ('17', 'rocky'), 278 ('17', 'rocky'),
279 ('18', 'stein'),
265 ]), 280 ]),
266 'openstack-dashboard': OrderedDict([ 281 'openstack-dashboard': OrderedDict([
267 ('8', 'liberty'), 282 ('8', 'liberty'),
@@ -271,6 +286,7 @@ PACKAGE_CODENAMES = {
271 ('12', 'pike'), 286 ('12', 'pike'),
272 ('13', 'queens'), 287 ('13', 'queens'),
273 ('14', 'rocky'), 288 ('14', 'rocky'),
289 ('15', 'stein'),
274 ]), 290 ]),
275} 291}
276 292
@@ -299,7 +315,7 @@ def get_os_codename_install_source(src):
299 rel = '' 315 rel = ''
300 if src is None: 316 if src is None:
301 return rel 317 return rel
302 if src in ['distro', 'distro-proposed']: 318 if src in ['distro', 'distro-proposed', 'proposed']:
303 try: 319 try:
304 rel = UBUNTU_OPENSTACK_RELEASE[ubuntu_rel] 320 rel = UBUNTU_OPENSTACK_RELEASE[ubuntu_rel]
305 except KeyError: 321 except KeyError:
@@ -1303,6 +1319,65 @@ def is_unit_paused_set():
1303 return False 1319 return False
1304 1320
1305 1321
1322def manage_payload_services(action, services=None, charm_func=None):
1323 """Run an action against all services.
1324
1325 An optional charm_func() can be called. It should raise an Exception to
1326 indicate that the function failed. If it was succesfull it should return
1327 None or an optional message.
1328
1329 The signature for charm_func is:
1330 charm_func() -> message: str
1331
1332 charm_func() is executed after any services are stopped, if supplied.
1333
1334 The services object can either be:
1335 - None : no services were passed (an empty dict is returned)
1336 - a list of strings
1337 - A dictionary (optionally OrderedDict) {service_name: {'service': ..}}
1338 - An array of [{'service': service_name, ...}, ...]
1339
1340 :param action: Action to run: pause, resume, start or stop.
1341 :type action: str
1342 :param services: See above
1343 :type services: See above
1344 :param charm_func: function to run for custom charm pausing.
1345 :type charm_func: f()
1346 :returns: Status boolean and list of messages
1347 :rtype: (bool, [])
1348 :raises: RuntimeError
1349 """
1350 actions = {
1351 'pause': service_pause,
1352 'resume': service_resume,
1353 'start': service_start,
1354 'stop': service_stop}
1355 action = action.lower()
1356 if action not in actions.keys():
1357 raise RuntimeError(
1358 "action: {} must be one of: {}".format(action,
1359 ', '.join(actions.keys())))
1360 services = _extract_services_list_helper(services)
1361 messages = []
1362 success = True
1363 if services:
1364 for service in services.keys():
1365 rc = actions[action](service)
1366 if not rc:
1367 success = False
1368 messages.append("{} didn't {} cleanly.".format(service,
1369 action))
1370 if charm_func:
1371 try:
1372 message = charm_func()
1373 if message:
1374 messages.append(message)
1375 except Exception as e:
1376 success = False
1377 messages.append(str(e))
1378 return success, messages
1379
1380
1306def pause_unit(assess_status_func, services=None, ports=None, 1381def pause_unit(assess_status_func, services=None, ports=None,
1307 charm_func=None): 1382 charm_func=None):
1308 """Pause a unit by stopping the services and setting 'unit-paused' 1383 """Pause a unit by stopping the services and setting 'unit-paused'
@@ -1333,20 +1408,10 @@ def pause_unit(assess_status_func, services=None, ports=None,
1333 @returns None 1408 @returns None
1334 @raises Exception(message) on an error for action_fail(). 1409 @raises Exception(message) on an error for action_fail().
1335 """ 1410 """
1336 services = _extract_services_list_helper(services) 1411 _, messages = manage_payload_services(
1337 messages = [] 1412 'pause',
1338 if services: 1413 services=services,
1339 for service in services.keys(): 1414 charm_func=charm_func)
1340 stopped = service_pause(service)
1341 if not stopped:
1342 messages.append("{} didn't stop cleanly.".format(service))
1343 if charm_func:
1344 try:
1345 message = charm_func()
1346 if message:
1347 messages.append(message)
1348 except Exception as e:
1349 message.append(str(e))
1350 set_unit_paused() 1415 set_unit_paused()
1351 if assess_status_func: 1416 if assess_status_func:
1352 message = assess_status_func() 1417 message = assess_status_func()
@@ -1385,20 +1450,10 @@ def resume_unit(assess_status_func, services=None, ports=None,
1385 @returns None 1450 @returns None
1386 @raises Exception(message) on an error for action_fail(). 1451 @raises Exception(message) on an error for action_fail().
1387 """ 1452 """
1388 services = _extract_services_list_helper(services) 1453 _, messages = manage_payload_services(
1389 messages = [] 1454 'resume',
1390 if services: 1455 services=services,
1391 for service in services.keys(): 1456 charm_func=charm_func)
1392 started = service_resume(service)
1393 if not started:
1394 messages.append("{} didn't start cleanly.".format(service))
1395 if charm_func:
1396 try:
1397 message = charm_func()
1398 if message:
1399 messages.append(message)
1400 except Exception as e:
1401 message.append(str(e))
1402 clear_unit_paused() 1457 clear_unit_paused()
1403 if assess_status_func: 1458 if assess_status_func:
1404 message = assess_status_func() 1459 message = assess_status_func()
diff --git a/hooks/charmhelpers/contrib/storage/linux/loopback.py b/hooks/charmhelpers/contrib/storage/linux/loopback.py
index 0dfdae5..82472ff 100644
--- a/hooks/charmhelpers/contrib/storage/linux/loopback.py
+++ b/hooks/charmhelpers/contrib/storage/linux/loopback.py
@@ -36,8 +36,10 @@ def loopback_devices():
36 ''' 36 '''
37 loopbacks = {} 37 loopbacks = {}
38 cmd = ['losetup', '-a'] 38 cmd = ['losetup', '-a']
39 devs = [d.strip().split(' ') for d in 39 output = check_output(cmd)
40 check_output(cmd).splitlines() if d != ''] 40 if six.PY3:
41 output = output.decode('utf-8')
42 devs = [d.strip().split(' ') for d in output.splitlines() if d != '']
41 for dev, _, f in devs: 43 for dev, _, f in devs:
42 loopbacks[dev.replace(':', '')] = re.search(r'\((\S+)\)', f).groups()[0] 44 loopbacks[dev.replace(':', '')] = re.search(r'\((\S+)\)', f).groups()[0]
43 return loopbacks 45 return loopbacks
diff --git a/hooks/charmhelpers/fetch/ubuntu.py b/hooks/charmhelpers/fetch/ubuntu.py
index c7ad128..8a5cadf 100644
--- a/hooks/charmhelpers/fetch/ubuntu.py
+++ b/hooks/charmhelpers/fetch/ubuntu.py
@@ -166,6 +166,14 @@ CLOUD_ARCHIVE_POCKETS = {
166 'rocky/proposed': 'bionic-proposed/rocky', 166 'rocky/proposed': 'bionic-proposed/rocky',
167 'bionic-rocky/proposed': 'bionic-proposed/rocky', 167 'bionic-rocky/proposed': 'bionic-proposed/rocky',
168 'bionic-proposed/rocky': 'bionic-proposed/rocky', 168 'bionic-proposed/rocky': 'bionic-proposed/rocky',
169 # Stein
170 'stein': 'bionic-updates/stein',
171 'bionic-stein': 'bionic-updates/stein',
172 'bionic-stein/updates': 'bionic-updates/stein',
173 'bionic-updates/stein': 'bionic-updates/stein',
174 'stein/proposed': 'bionic-proposed/stein',
175 'bionic-stein/proposed': 'bionic-proposed/stein',
176 'bionic-proposed/stein': 'bionic-proposed/stein',
169} 177}
170 178
171 179