Browse Source

Sync charm-helpers

Change-Id: Iaa29be49b44c76c4c89cef17b3212502b09d65ac
changes/10/629210/1
Corey Bryant 4 months ago
parent
commit
609631e658

+ 15
- 10
hooks/charmhelpers/contrib/charmsupport/nrpe.py View File

@@ -305,7 +305,7 @@ class NRPE(object):
305 305
 
306 306
         # update-status hooks are configured to firing every 5 minutes by
307 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 309
         # on update-status hooks.
310 310
         if not hook_name() == 'update-status':
311 311
             service('restart', 'nagios-nrpe-server')
@@ -416,15 +416,20 @@ def copy_nrpe_checks(nrpe_files_dir=None):
416 416
 
417 417
     """
418 418
     NAGIOS_PLUGINS = '/usr/local/lib/nagios/plugins'
419
-    default_nrpe_files_dir = os.path.join(
420
-        os.getenv('CHARM_DIR'),
421
-        'hooks',
422
-        'charmhelpers',
423
-        'contrib',
424
-        'openstack',
425
-        'files')
426
-    if not nrpe_files_dir:
427
-        nrpe_files_dir = default_nrpe_files_dir
419
+    if nrpe_files_dir is None:
420
+        # determine if "charmhelpers" is in CHARMDIR or CHARMDIR/hooks
421
+        for segment in ['.', 'hooks']:
422
+            nrpe_files_dir = os.path.abspath(os.path.join(
423
+                os.getenv('CHARM_DIR'),
424
+                segment,
425
+                'charmhelpers',
426
+                'contrib',
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 433
     if not os.path.exists(NAGIOS_PLUGINS):
429 434
         os.makedirs(NAGIOS_PLUGINS)
430 435
     for fname in glob.glob(os.path.join(nrpe_files_dir, "check_*")):

+ 84
- 29
hooks/charmhelpers/contrib/openstack/utils.py View File

@@ -73,6 +73,8 @@ from charmhelpers.core.host import (
73 73
     service_running,
74 74
     service_pause,
75 75
     service_resume,
76
+    service_stop,
77
+    service_start,
76 78
     restart_on_change_helper,
77 79
 )
78 80
 from charmhelpers.fetch import (
@@ -116,6 +118,7 @@ OPENSTACK_RELEASES = (
116 118
     'pike',
117 119
     'queens',
118 120
     'rocky',
121
+    'stein',
119 122
 )
120 123
 
121 124
 UBUNTU_OPENSTACK_RELEASE = OrderedDict([
@@ -134,6 +137,7 @@ UBUNTU_OPENSTACK_RELEASE = OrderedDict([
134 137
     ('artful', 'pike'),
135 138
     ('bionic', 'queens'),
136 139
     ('cosmic', 'rocky'),
140
+    ('disco', 'stein'),
137 141
 ])
138 142
 
139 143
 
@@ -153,6 +157,7 @@ OPENSTACK_CODENAMES = OrderedDict([
153 157
     ('2017.2', 'pike'),
154 158
     ('2018.1', 'queens'),
155 159
     ('2018.2', 'rocky'),
160
+    ('2019.1', 'stein'),
156 161
 ])
157 162
 
158 163
 # The ugly duckling - must list releases oldest to newest
@@ -187,6 +192,8 @@ SWIFT_CODENAMES = OrderedDict([
187 192
         ['2.16.0', '2.17.0']),
188 193
     ('rocky',
189 194
         ['2.18.0', '2.19.0']),
195
+    ('stein',
196
+        ['2.19.0']),
190 197
 ])
191 198
 
192 199
 # >= Liberty version->codename mapping
@@ -199,6 +206,7 @@ PACKAGE_CODENAMES = {
199 206
         ('16', 'pike'),
200 207
         ('17', 'queens'),
201 208
         ('18', 'rocky'),
209
+        ('19', 'stein'),
202 210
     ]),
203 211
     'neutron-common': OrderedDict([
204 212
         ('7', 'liberty'),
@@ -208,6 +216,7 @@ PACKAGE_CODENAMES = {
208 216
         ('11', 'pike'),
209 217
         ('12', 'queens'),
210 218
         ('13', 'rocky'),
219
+        ('14', 'stein'),
211 220
     ]),
212 221
     'cinder-common': OrderedDict([
213 222
         ('7', 'liberty'),
@@ -217,6 +226,7 @@ PACKAGE_CODENAMES = {
217 226
         ('11', 'pike'),
218 227
         ('12', 'queens'),
219 228
         ('13', 'rocky'),
229
+        ('14', 'stein'),
220 230
     ]),
221 231
     'keystone': OrderedDict([
222 232
         ('8', 'liberty'),
@@ -226,6 +236,7 @@ PACKAGE_CODENAMES = {
226 236
         ('12', 'pike'),
227 237
         ('13', 'queens'),
228 238
         ('14', 'rocky'),
239
+        ('15', 'stein'),
229 240
     ]),
230 241
     'horizon-common': OrderedDict([
231 242
         ('8', 'liberty'),
@@ -235,6 +246,7 @@ PACKAGE_CODENAMES = {
235 246
         ('12', 'pike'),
236 247
         ('13', 'queens'),
237 248
         ('14', 'rocky'),
249
+        ('15', 'stein'),
238 250
     ]),
239 251
     'ceilometer-common': OrderedDict([
240 252
         ('5', 'liberty'),
@@ -244,6 +256,7 @@ PACKAGE_CODENAMES = {
244 256
         ('9', 'pike'),
245 257
         ('10', 'queens'),
246 258
         ('11', 'rocky'),
259
+        ('12', 'stein'),
247 260
     ]),
248 261
     'heat-common': OrderedDict([
249 262
         ('5', 'liberty'),
@@ -253,6 +266,7 @@ PACKAGE_CODENAMES = {
253 266
         ('9', 'pike'),
254 267
         ('10', 'queens'),
255 268
         ('11', 'rocky'),
269
+        ('12', 'stein'),
256 270
     ]),
257 271
     'glance-common': OrderedDict([
258 272
         ('11', 'liberty'),
@@ -262,6 +276,7 @@ PACKAGE_CODENAMES = {
262 276
         ('15', 'pike'),
263 277
         ('16', 'queens'),
264 278
         ('17', 'rocky'),
279
+        ('18', 'stein'),
265 280
     ]),
266 281
     'openstack-dashboard': OrderedDict([
267 282
         ('8', 'liberty'),
@@ -271,6 +286,7 @@ PACKAGE_CODENAMES = {
271 286
         ('12', 'pike'),
272 287
         ('13', 'queens'),
273 288
         ('14', 'rocky'),
289
+        ('15', 'stein'),
274 290
     ]),
275 291
 }
276 292
 
@@ -299,7 +315,7 @@ def get_os_codename_install_source(src):
299 315
     rel = ''
300 316
     if src is None:
301 317
         return rel
302
-    if src in ['distro', 'distro-proposed']:
318
+    if src in ['distro', 'distro-proposed', 'proposed']:
303 319
         try:
304 320
             rel = UBUNTU_OPENSTACK_RELEASE[ubuntu_rel]
305 321
         except KeyError:
@@ -1303,6 +1319,65 @@ def is_unit_paused_set():
1303 1319
         return False
1304 1320
 
1305 1321
 
1322
+def 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
+
1306 1381
 def pause_unit(assess_status_func, services=None, ports=None,
1307 1382
                charm_func=None):
1308 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 1408
     @returns None
1334 1409
     @raises Exception(message) on an error for action_fail().
1335 1410
     """
1336
-    services = _extract_services_list_helper(services)
1337
-    messages = []
1338
-    if services:
1339
-        for service in services.keys():
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))
1411
+    _, messages = manage_payload_services(
1412
+        'pause',
1413
+        services=services,
1414
+        charm_func=charm_func)
1350 1415
     set_unit_paused()
1351 1416
     if assess_status_func:
1352 1417
         message = assess_status_func()
@@ -1385,20 +1450,10 @@ def resume_unit(assess_status_func, services=None, ports=None,
1385 1450
     @returns None
1386 1451
     @raises Exception(message) on an error for action_fail().
1387 1452
     """
1388
-    services = _extract_services_list_helper(services)
1389
-    messages = []
1390
-    if services:
1391
-        for service in services.keys():
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))
1453
+    _, messages = manage_payload_services(
1454
+        'resume',
1455
+        services=services,
1456
+        charm_func=charm_func)
1402 1457
     clear_unit_paused()
1403 1458
     if assess_status_func:
1404 1459
         message = assess_status_func()

+ 4
- 2
hooks/charmhelpers/contrib/storage/linux/loopback.py View File

@@ -36,8 +36,10 @@ def loopback_devices():
36 36
     '''
37 37
     loopbacks = {}
38 38
     cmd = ['losetup', '-a']
39
-    devs = [d.strip().split(' ') for d in
40
-            check_output(cmd).splitlines() if d != '']
39
+    output = check_output(cmd)
40
+    if six.PY3:
41
+        output = output.decode('utf-8')
42
+    devs = [d.strip().split(' ') for d in output.splitlines() if d != '']
41 43
     for dev, _, f in devs:
42 44
         loopbacks[dev.replace(':', '')] = re.search(r'\((\S+)\)', f).groups()[0]
43 45
     return loopbacks

+ 8
- 0
hooks/charmhelpers/fetch/ubuntu.py View File

@@ -166,6 +166,14 @@ CLOUD_ARCHIVE_POCKETS = {
166 166
     'rocky/proposed': 'bionic-proposed/rocky',
167 167
     'bionic-rocky/proposed': 'bionic-proposed/rocky',
168 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
 

Loading…
Cancel
Save