Merge "sharding: Don't inject shard ranges when user says quit"
This commit is contained in:
commit
835145e62a
@ -343,7 +343,9 @@ def _replace_shard_ranges(broker, args, shard_data, timeout=0):
|
|||||||
|
|
||||||
# Crank up the timeout in an effort to *make sure* this succeeds
|
# Crank up the timeout in an effort to *make sure* this succeeds
|
||||||
with broker.updated_timeout(max(timeout, args.replace_timeout)):
|
with broker.updated_timeout(max(timeout, args.replace_timeout)):
|
||||||
delete_shard_ranges(broker, args)
|
delete_status = delete_shard_ranges(broker, args)
|
||||||
|
if delete_status != 0:
|
||||||
|
return delete_status
|
||||||
broker.merge_shard_ranges(shard_ranges)
|
broker.merge_shard_ranges(shard_ranges)
|
||||||
|
|
||||||
print('Injected %d shard ranges.' % len(shard_ranges))
|
print('Injected %d shard ranges.' % len(shard_ranges))
|
||||||
|
@ -358,6 +358,23 @@ class TestManageShardRanges(unittest.TestCase):
|
|||||||
self.assertEqual(['Loaded db broker for a/c.'],
|
self.assertEqual(['Loaded db broker for a/c.'],
|
||||||
err.getvalue().splitlines())
|
err.getvalue().splitlines())
|
||||||
self._assert_enabled(broker, now)
|
self._assert_enabled(broker, now)
|
||||||
|
found_shard_ranges = broker.get_shard_ranges()
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
[(data['lower'], data['upper']) for data in self.shard_data],
|
[(data['lower'], data['upper']) for data in self.shard_data],
|
||||||
[(sr.lower_str, sr.upper_str) for sr in broker.get_shard_ranges()])
|
[(sr.lower_str, sr.upper_str) for sr in found_shard_ranges])
|
||||||
|
|
||||||
|
# Do another find & replace but quit when prompted about existing
|
||||||
|
# shard ranges
|
||||||
|
out = StringIO()
|
||||||
|
err = StringIO()
|
||||||
|
to_patch = 'swift.cli.manage_shard_ranges.input'
|
||||||
|
with mock.patch('sys.stdout', out), mock.patch('sys.stderr', err), \
|
||||||
|
mock_timestamp_now() as now, \
|
||||||
|
mock.patch(to_patch, return_value='q'):
|
||||||
|
main([broker.db_file, 'find_and_replace', '10'])
|
||||||
|
# Shard ranges haven't changed at all
|
||||||
|
self.assertEqual(found_shard_ranges, broker.get_shard_ranges())
|
||||||
|
expected = ['This will delete existing 10 shard ranges.']
|
||||||
|
self.assertEqual(expected, out.getvalue().splitlines())
|
||||||
|
self.assertEqual(['Loaded db broker for a/c.'],
|
||||||
|
err.getvalue().splitlines())
|
||||||
|
Loading…
Reference in New Issue
Block a user