summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2016-11-18 18:25:40 +0000
committerGerrit Code Review <review@openstack.org>2016-11-18 18:25:40 +0000
commit88e57da8c1f20e4cafbd3949aae666b60decd87f (patch)
tree9d259f7fefacdc9f8e4c52188fd533caea18871f
parent15e61c82bed8a55e57da51b26ef8486209d7dc61 (diff)
parente3e457da662e92885620981a445530fbd8370604 (diff)
downloadswift-88e57da8c1f20e4cafbd3949aae666b60decd87f.tar.gz
Merge "Respect server type for --md5 check in swift-recon"
-rw-r--r--swift/cli/recon.py16
-rw-r--r--test/unit/cli/test_recon.py61
2 files changed, 67 insertions, 10 deletions
diff --git a/swift/cli/recon.py b/swift/cli/recon.py
index 35fa07a31..1bd7ecabe 100644
--- a/swift/cli/recon.py
+++ b/swift/cli/recon.py
@@ -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
diff --git a/test/unit/cli/test_recon.py b/test/unit/cli/test_recon.py
index 1d5bbedb1..560a201cd 100644
--- a/test/unit/cli/test_recon.py
+++ b/test/unit/cli/test_recon.py
@@ -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))