Skip to content

Commit 296de6e

Browse files
Jenkinsopenstack-gerrit
Jenkins
authored andcommitted
Merge "Changes swift-ring-builder exit codes"
2 parents 1397fa7 + 1ad31af commit 296de6e

File tree

1 file changed

+34
-30
lines changed

1 file changed

+34
-30
lines changed

bin/swift-ring-builder

+34-30
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/python -uO
1+
#! /usr/bin/env python
22
# Copyright (c) 2010-2011 OpenStack, LLC.
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -28,9 +28,9 @@ from swift.common.ring import RingBuilder
2828

2929

3030
MAJOR_VERSION = 1
31-
MINOR_VERSION = 2
32-
EXIT_RING_CHANGED = 0
33-
EXIT_RING_UNCHANGED = 1
31+
MINOR_VERSION = 3
32+
EXIT_SUCCESS = 0
33+
EXIT_WARNING = 1
3434
EXIT_ERROR = 2
3535

3636

@@ -146,7 +146,7 @@ swift-ring-builder <builder_file> create <part_power> <replicas>
146146
"""
147147
if len(argv) < 6:
148148
print Commands.create.__doc__.strip()
149-
exit(EXIT_RING_UNCHANGED)
149+
exit(EXIT_ERROR)
150150
builder = RingBuilder(int(argv[3]), int(argv[4]), int(argv[5]))
151151
backup_dir = pathjoin(dirname(argv[1]), 'backups')
152152
try:
@@ -157,7 +157,7 @@ swift-ring-builder <builder_file> create <part_power> <replicas>
157157
pickle.dump(builder.to_dict(), open(pathjoin(backup_dir,
158158
'%d.' % time() + basename(argv[1])), 'wb'), protocol=2)
159159
pickle.dump(builder.to_dict(), open(argv[1], 'wb'), protocol=2)
160-
exit(EXIT_RING_CHANGED)
160+
exit(EXIT_SUCCESS)
161161

162162
def default():
163163
"""
@@ -195,7 +195,7 @@ swift-ring-builder <builder_file>
195195
(dev['id'], dev['zone'], dev['ip'], dev['port'],
196196
dev['device'], dev['weight'], dev['parts'], balance,
197197
dev['meta'])
198-
exit(EXIT_RING_UNCHANGED)
198+
exit(EXIT_SUCCESS)
199199

200200
def search():
201201
"""
@@ -206,7 +206,7 @@ swift-ring-builder <builder_file> search <search-value>
206206
print Commands.search.__doc__.strip()
207207
print
208208
print search_devs.__doc__.strip()
209-
exit(EXIT_RING_UNCHANGED)
209+
exit(EXIT_ERROR)
210210
devs = search_devs(builder, argv[3])
211211
if not devs:
212212
print 'No matching devices found'
@@ -228,7 +228,7 @@ swift-ring-builder <builder_file> search <search-value>
228228
(dev['id'], dev['zone'], dev['ip'], dev['port'],
229229
dev['device'], dev['weight'], dev['parts'], balance,
230230
dev['meta'])
231-
exit(EXIT_RING_UNCHANGED)
231+
exit(EXIT_SUCCESS)
232232

233233
def list_parts():
234234
"""
@@ -244,7 +244,7 @@ swift-ring-builder <builder_file> list_parts <search-value> [<search-value>] ..
244244
print Commands.list_parts.__doc__.strip()
245245
print
246246
print search_devs.__doc__.strip()
247-
exit(EXIT_RING_UNCHANGED)
247+
exit(EXIT_ERROR)
248248
devs = []
249249
for arg in argv[3:]:
250250
devs.extend(search_devs(builder, arg) or [])
@@ -262,7 +262,7 @@ swift-ring-builder <builder_file> list_parts <search-value> [<search-value>] ..
262262
for index, parts in enumerate(matches):
263263
for part in parts:
264264
print '%9d %7d' % (part, builder.replicas - index)
265-
exit(EXIT_RING_UNCHANGED)
265+
exit(EXIT_SUCCESS)
266266

267267
def add():
268268
"""
@@ -274,7 +274,7 @@ swift-ring-builder <builder_file> add z<zone>-<ip>:<port>/<device_name>_<meta>
274274
"""
275275
if len(argv) < 5:
276276
print Commands.add.__doc__.strip()
277-
exit(EXIT_RING_UNCHANGED)
277+
exit(EXIT_ERROR)
278278

279279
if not argv[3].startswith('z'):
280280
print 'Invalid add value: %s' % argv[3]
@@ -348,7 +348,7 @@ swift-ring-builder <builder_file> add z<zone>-<ip>:<port>/<device_name>_<meta>
348348
print 'Device z%s-%s:%s/%s_"%s" with %s weight got id %s' % \
349349
(zone, ip, port, device_name, meta, weight, next_dev_id)
350350
pickle.dump(builder.to_dict(), open(argv[1], 'wb'), protocol=2)
351-
exit(EXIT_RING_UNCHANGED)
351+
exit(EXIT_SUCCESS)
352352

353353
def set_weight():
354354
"""
@@ -361,7 +361,7 @@ swift-ring-builder <builder_file> set_weight <search-value> <weight>
361361
print Commands.set_weight.__doc__.strip()
362362
print
363363
print search_devs.__doc__.strip()
364-
exit(EXIT_RING_UNCHANGED)
364+
exit(EXIT_ERROR)
365365
devs = search_devs(builder, argv[3])
366366
weight = float(argv[4])
367367
if not devs:
@@ -381,7 +381,7 @@ swift-ring-builder <builder_file> set_weight <search-value> <weight>
381381
print 'd%(id)sz%(zone)s-%(ip)s:%(port)s/%(device)s_"%(meta)s" ' \
382382
'weight set to %(weight)s' % dev
383383
pickle.dump(builder.to_dict(), open(argv[1], 'wb'), protocol=2)
384-
exit(EXIT_RING_UNCHANGED)
384+
exit(EXIT_SUCCESS)
385385

386386
def set_info():
387387
"""
@@ -398,7 +398,7 @@ swift-ring-builder <builder_file> set_info <search-value>
398398
print Commands.set_info.__doc__.strip()
399399
print
400400
print search_devs.__doc__.strip()
401-
exit(EXIT_RING_UNCHANGED)
401+
exit(EXIT_ERROR)
402402
devs = search_devs(builder, argv[3])
403403
change_value = argv[4]
404404
change = []
@@ -463,7 +463,7 @@ swift-ring-builder <builder_file> set_info <search-value>
463463
dev[key] = value
464464
print 'Device %s is now %s' % (orig_dev_string, format_device(dev))
465465
pickle.dump(builder.to_dict(), open(argv[1], 'wb'), protocol=2)
466-
exit(EXIT_RING_UNCHANGED)
466+
exit(EXIT_SUCCESS)
467467

468468
def remove():
469469
"""
@@ -479,7 +479,7 @@ swift-ring-builder <builder_file> remove <search-value>
479479
print Commands.remove.__doc__.strip()
480480
print
481481
print search_devs.__doc__.strip()
482-
exit(EXIT_RING_UNCHANGED)
482+
exit(EXIT_ERROR)
483483
devs = search_devs(builder, argv[3])
484484
if not devs:
485485
print 'No matching devices found'
@@ -499,7 +499,7 @@ swift-ring-builder <builder_file> remove <search-value>
499499
'marked for removal and will be removed next rebalance.' \
500500
% dev
501501
pickle.dump(builder.to_dict(), open(argv[1], 'wb'), protocol=2)
502-
exit(EXIT_RING_UNCHANGED)
502+
exit(EXIT_SUCCESS)
503503

504504
def rebalance():
505505
"""
@@ -514,21 +514,23 @@ swift-ring-builder <builder_file> rebalance
514514
print 'No partitions could be reassigned.'
515515
print 'Either none need to be or none can be due to ' \
516516
'min_part_hours [%s].' % builder.min_part_hours
517-
exit(EXIT_RING_UNCHANGED)
517+
exit(EXIT_WARNING)
518518
if not devs_changed and abs(last_balance - balance) < 1:
519519
print 'Cowardly refusing to save rebalance as it did not change ' \
520520
'at least 1%.'
521-
exit(EXIT_RING_UNCHANGED)
521+
exit(EXIT_WARNING)
522522
builder.validate()
523523
print 'Reassigned %d (%.02f%%) partitions. Balance is now %.02f.' % \
524524
(parts, 100.0 * parts / builder.parts, balance)
525+
status = EXIT_SUCCESS
525526
if balance > 5:
526527
print '-' * 79
527528
print 'NOTE: Balance of %.02f indicates you should push this ' % \
528529
balance
529530
print ' ring, wait at least %d hours, and rebalance/repush.' \
530531
% builder.min_part_hours
531532
print '-' * 79
533+
status = EXIT_WARNING
532534
ts = time()
533535
pickle.dump(builder.get_ring().to_dict(),
534536
GzipFile(pathjoin(backup_dir, '%d.' % ts +
@@ -538,15 +540,15 @@ swift-ring-builder <builder_file> rebalance
538540
pickle.dump(builder.get_ring().to_dict(), GzipFile(ring_file, 'wb'),
539541
protocol=2)
540542
pickle.dump(builder.to_dict(), open(argv[1], 'wb'), protocol=2)
541-
exit(EXIT_RING_CHANGED)
543+
exit(status)
542544

543545
def validate():
544546
"""
545547
swift-ring-builder <builder_file> validate
546548
Just runs the validation routines on the ring.
547549
"""
548550
builder.validate()
549-
exit(EXIT_RING_UNCHANGED)
551+
exit(EXIT_SUCCESS)
550552

551553
def write_ring():
552554
"""
@@ -568,12 +570,12 @@ swift-ring-builder <builder_file> write_ring
568570
GzipFile(pathjoin(backup_dir, '%d.' % time() +
569571
basename(ring_file)), 'wb'), protocol=2)
570572
pickle.dump(ring_data.to_dict(), GzipFile(ring_file, 'wb'), protocol=2)
571-
exit(EXIT_RING_CHANGED)
573+
exit(EXIT_SUCCESS)
572574

573575
def pretend_min_part_hours_passed():
574576
builder.pretend_min_part_hours_passed()
575577
pickle.dump(builder.to_dict(), open(argv[1], 'wb'), protocol=2)
576-
exit(EXIT_RING_UNCHANGED)
578+
exit(EXIT_SUCCESS)
577579

578580
def set_min_part_hours():
579581
"""
@@ -584,12 +586,12 @@ swift-ring-builder <builder_file> set_min_part_hours <hours>
584586
"""
585587
if len(argv) < 4:
586588
print Commands.set_min_part_hours.__doc__.strip()
587-
exit(EXIT_RING_UNCHANGED)
589+
exit(EXIT_ERROR)
588590
builder.change_min_part_hours(int(argv[3]))
589591
print 'The minimum number of hours before a partition can be ' \
590592
'reassigned is now set to %s' % argv[3]
591593
pickle.dump(builder.to_dict(), open(argv[1], 'wb'), protocol=2)
592-
exit(EXIT_RING_UNCHANGED)
594+
exit(EXIT_SUCCESS)
593595

594596

595597
if __name__ == '__main__':
@@ -609,9 +611,11 @@ if __name__ == '__main__':
609611
for line in wrap(' '.join(cmds), 79, initial_indent='Quick list: ',
610612
subsequent_indent=' '):
611613
print line
612-
print 'Exit codes: 0 = ring changed, 1 = ring did not change, ' \
613-
'2 = error'
614-
exit(EXIT_RING_UNCHANGED)
614+
print ('Exit codes: 0 = operation successful\n'
615+
' 1 = operation completed with warnings\n' \
616+
' 2 = error'
617+
)
618+
exit(EXIT_SUCCESS)
615619

616620
if exists(argv[1]):
617621
try:

0 commit comments

Comments
 (0)