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

MD5 sum compare of server ring ignores server_type parameter
now. This could be confusing and this should only test
specified server_type, same as --replication, --validate-servers,
etc.

Change-Id: I9095309c24f42aec1330757c88e7b242b2a6a865
This commit is contained in:
Ondřej Nový 2015-11-01 19:32:19 +01:00 committed by Christian Schwede
parent e55f3ad203
commit e3e457da66
2 changed files with 67 additions and 10 deletions

View File

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

View File

@ -270,6 +270,7 @@ class TestRecon(unittest.TestCase):
open(ring_file, 'w') open(ring_file, 'w')
empty_file_hash = 'd41d8cd98f00b204e9800998ecf8427e' empty_file_hash = 'd41d8cd98f00b204e9800998ecf8427e'
bad_file_hash = '00000000000000000000000000000000'
hosts = [("127.0.0.1", "8080")] hosts = [("127.0.0.1", "8080")]
with mock.patch('swift.cli.recon.Scout') as mock_scout: with mock.patch('swift.cli.recon.Scout') as mock_scout:
scout_instance = mock.MagicMock() scout_instance = mock.MagicMock()
@ -283,8 +284,60 @@ class TestRecon(unittest.TestCase):
status = 200 status = 200
scout_instance.scout.return_value = (url, response, status, 0, 0) scout_instance.scout.return_value = (url, response, status, 0, 0)
mock_scout.return_value = scout_instance mock_scout.return_value = scout_instance
stdout = StringIO()
mock_hash = mock.MagicMock() 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), \ with mock.patch('sys.stdout', new=stdout), \
mock.patch('swift.cli.recon.md5', new=mock_hash): mock.patch('swift.cli.recon.md5', new=mock_hash):
mock_hash.return_value.hexdigest.return_value = \ mock_hash.return_value.hexdigest.return_value = \
@ -296,11 +349,13 @@ class TestRecon(unittest.TestCase):
if '!!' in line: if '!!' in line:
self.fail('Unexpected Error in output: %r' % line) self.fail('Unexpected Error in output: %r' % line)
if expected in line: if expected in line:
break found = True
else: if not found:
self.fail('Did not find expected substring %r ' self.fail('Did not find expected substring %r '
'in output:\n%s' % (expected, output)) 'in output:\n%s' % (expected, output))
# Cleanup
self.recon_instance.server_type = 'object'
for ring in ('account', 'container', 'object', 'object-1'): for ring in ('account', 'container', 'object', 'object-1'):
os.remove(os.path.join(self.swift_dir, "%s.ring.gz" % ring)) os.remove(os.path.join(self.swift_dir, "%s.ring.gz" % ring))