Ringbuilder: Forbid writing empty rings
Swift definitely can't make any use of empty rings, so it should not be allowed to write them. Replace warning with an error message & error exit. Change-Id: I3a1b86368d363e67d1f91d7d8af4b391a0a53fff Closes-Bug: #1396841
This commit is contained in:
parent
b808c806b4
commit
84ea58b8c8
@ -1085,14 +1085,16 @@ swift-ring-builder <builder_file> write_ring
|
||||
'set_info' calls when no rebalance is needed but you want to send out the
|
||||
new device information.
|
||||
"""
|
||||
if not builder.devs:
|
||||
print('Unable to write empty ring.')
|
||||
exit(EXIT_ERROR)
|
||||
|
||||
ring_data = builder.get_ring()
|
||||
if not ring_data._replica2part2dev_id:
|
||||
if ring_data.devs:
|
||||
print('Warning: Writing a ring with no partition '
|
||||
'assignments but with devices; did you forget to run '
|
||||
'"rebalance"?')
|
||||
else:
|
||||
print('Warning: Writing an empty ring')
|
||||
ring_data.save(
|
||||
pathjoin(backup_dir, '%d.' % time() + basename(ring_file)))
|
||||
ring_data.save(ring_file)
|
||||
|
@ -46,7 +46,6 @@ class RunSwiftRingBuilderMixin(object):
|
||||
|
||||
if 'exp_results' in kwargs:
|
||||
exp_results = kwargs['exp_results']
|
||||
argv = argv[:-1]
|
||||
else:
|
||||
exp_results = None
|
||||
|
||||
@ -2078,6 +2077,13 @@ class TestCommands(unittest.TestCase, RunSwiftRingBuilderMixin):
|
||||
argv = ["", self.tmpfile, "write_ring"]
|
||||
self.assertSystemExit(EXIT_SUCCESS, ringbuilder.main, argv)
|
||||
|
||||
def test_write_empty_ring(self):
|
||||
ring = RingBuilder(6, 3, 1)
|
||||
ring.save(self.tmpfile)
|
||||
exp_results = {'valid_exit_codes': [2]}
|
||||
out, err = self.run_srb("write_ring", exp_results=exp_results)
|
||||
self.assertEqual('Unable to write empty ring.\n', out)
|
||||
|
||||
def test_write_builder(self):
|
||||
# Test builder file already exists
|
||||
self.create_sample_ring()
|
||||
|
Loading…
x
Reference in New Issue
Block a user