Merge "Ringbuilder: Forbid writing empty rings"
This commit is contained in:
commit
0e95730eb3
@ -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…
Reference in New Issue
Block a user