swift-manage-shard-ranges analyze: accept incomplete shard data

swift-container-info does not currently include 'epoch' among the
shard range info that it outputs, which prevents shard data scraped
from that tool being read by the swift-manage-shard-ranges 'analyze'
command.  The 'epoch' key is not significant to the 'analyze' results
so it is safe to add a default value when it is missing.

Change-Id: I7be30c3247a53969a17fed63d0eba5ab4f4027e4
This commit is contained in:
Alistair Coles 2021-03-29 18:56:18 +01:00
parent c9c42c07c9
commit fc7c0afbe4
2 changed files with 17 additions and 0 deletions

View File

@ -654,6 +654,10 @@ def repair_shard_ranges(broker, args):
def analyze_shard_ranges(args):
shard_data = _load_and_validate_shard_data(args, require_index=False)
for data in shard_data:
# allow for incomplete shard range data that may have been scraped from
# swift-container-info output
data.setdefault('epoch', None)
shard_ranges = [ShardRange.from_dict(data) for data in shard_data]
whole_sr = ShardRange('whole/namespace', 0)
try:

View File

@ -1602,3 +1602,16 @@ class TestManageShardRanges(unittest.TestCase):
self.assertEqual(
['Repairs necessary to remove overlapping shard ranges.'],
out_lines[:1])
filtered_shard_json = [{k: v for k, v in sr.items() if k != 'epoch'}
for sr in shard_json]
with open(shard_file, 'w') as fd:
json.dump(filtered_shard_json, fd)
out = StringIO()
err = StringIO()
with mock.patch('sys.stdout', out), mock.patch('sys.stderr', err):
ret = main([shard_file, 'analyze'])
self.assertEqual(0, ret)
self.assertEqual('', err.getvalue())
new_out_lines = out.getvalue().split('\n')
self.assertEqual(out_lines, new_out_lines)