Merge "Respect server type for --md5 check in swift-recon"

This commit is contained in:
Jenkins 2016-11-18 18:25:40 +00:00 committed by Gerrit Code Review
commit 88e57da8c1
2 changed files with 67 additions and 10 deletions

View File

@ -239,14 +239,14 @@ class SwiftRecon(object):
matches = 0
errors = 0
ring_names = set()
for server_type in ('account', 'container'):
ring_name = '%s.ring.gz' % server_type
if self.server_type == 'object':
for ring_name in os.listdir(swift_dir):
if ring_name.startswith('object') and \
ring_name.endswith('ring.gz'):
ring_names.add(ring_name)
else:
ring_name = '%s.ring.gz' % self.server_type
ring_names.add(ring_name)
# include any other object ring files
for ring_name in os.listdir(swift_dir):
if ring_name.startswith('object') and \
ring_name.endswith('ring.gz'):
ring_names.add(ring_name)
rings = {}
for ring_name in ring_names:
md5sum = md5()
@ -271,6 +271,8 @@ class SwiftRecon(object):
success = True
for remote_ring_file, remote_ring_sum in response.items():
remote_ring_name = os.path.basename(remote_ring_file)
if not remote_ring_name.startswith(self.server_type):
continue
ring_sum = rings.get(remote_ring_name, None)
if remote_ring_sum != ring_sum:
success = False

View File

@ -270,6 +270,7 @@ class TestRecon(unittest.TestCase):
open(ring_file, 'w')
empty_file_hash = 'd41d8cd98f00b204e9800998ecf8427e'
bad_file_hash = '00000000000000000000000000000000'
hosts = [("127.0.0.1", "8080")]
with mock.patch('swift.cli.recon.Scout') as mock_scout:
scout_instance = mock.MagicMock()
@ -283,8 +284,60 @@ class TestRecon(unittest.TestCase):
status = 200
scout_instance.scout.return_value = (url, response, status, 0, 0)
mock_scout.return_value = scout_instance
stdout = StringIO()
mock_hash = mock.MagicMock()
# Check correct account, container and object ring hashes
for server_type in ('account', 'container', 'object'):
self.recon_instance.server_type = server_type
stdout = StringIO()
with mock.patch('sys.stdout', new=stdout), \
mock.patch('swift.cli.recon.md5', new=mock_hash):
mock_hash.return_value.hexdigest.return_value = \
empty_file_hash
self.recon_instance.get_ringmd5(hosts, self.swift_dir)
output = stdout.getvalue()
expected = '1/1 hosts matched'
found = False
for line in output.splitlines():
if '!!' in line:
self.fail('Unexpected Error in output: %r' % line)
if expected in line:
found = True
if not found:
self.fail('Did not find expected substring %r '
'in output:\n%s' % (expected, output))
# Check bad container ring hash
self.recon_instance.server_type = 'container'
response = {
'/etc/swift/account.ring.gz': empty_file_hash,
'/etc/swift/container.ring.gz': bad_file_hash,
'/etc/swift/object.ring.gz': empty_file_hash,
'/etc/swift/object-1.ring.gz': empty_file_hash,
}
scout_instance.scout.return_value = (url, response, status, 0, 0)
mock_scout.return_value = scout_instance
stdout = StringIO()
with mock.patch('sys.stdout', new=stdout), \
mock.patch('swift.cli.recon.md5', new=mock_hash):
mock_hash.return_value.hexdigest.return_value = \
empty_file_hash
self.recon_instance.get_ringmd5(hosts, self.swift_dir)
output = stdout.getvalue()
expected = '0/1 hosts matched'
found = False
for line in output.splitlines():
if '!!' in line:
self.assertIn('doesn\'t match on disk md5sum', line)
if expected in line:
found = True
if not found:
self.fail('Did not find expected substring %r '
'in output:\n%s' % (expected, output))
# Check object ring, container mismatch should be ignored
self.recon_instance.server_type = 'object'
stdout = StringIO()
with mock.patch('sys.stdout', new=stdout), \
mock.patch('swift.cli.recon.md5', new=mock_hash):
mock_hash.return_value.hexdigest.return_value = \
@ -296,11 +349,13 @@ class TestRecon(unittest.TestCase):
if '!!' in line:
self.fail('Unexpected Error in output: %r' % line)
if expected in line:
break
else:
found = True
if not found:
self.fail('Did not find expected substring %r '
'in output:\n%s' % (expected, output))
# Cleanup
self.recon_instance.server_type = 'object'
for ring in ('account', 'container', 'object', 'object-1'):
os.remove(os.path.join(self.swift_dir, "%s.ring.gz" % ring))