From 6788bf4aad2d1b58cdd2089254c711db42ac587c Mon Sep 17 00:00:00 2001 From: lijunbo Date: Fri, 7 Apr 2017 16:21:55 +0800 Subject: [PATCH] Fixed get ring name from recon cli This patch uses a more specific string to match the ring name in recon cli. Almost all the places in the project where need to get the suffix (like ring.gz, ts, data and .etc) will include the '.' in front, if a file named 'object.sring.gz' in the swift_dir will be added in the ring_names, which is not what we want. Co-Authored-By: Kota Tsuyuzaki Closes-Bug: #1680704 Change-Id: Ida659fa71585f9b0cf36da75b58b28e6a25533df --- swift/cli/recon.py | 2 +- test/unit/cli/test_recon.py | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/swift/cli/recon.py b/swift/cli/recon.py index 49df596942..346bb30c00 100644 --- a/swift/cli/recon.py +++ b/swift/cli/recon.py @@ -227,7 +227,7 @@ class SwiftRecon(object): 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_name.endswith('.ring.gz'): ring_names.add(ring_name) else: ring_name = '%s.ring.gz' % self.server_type diff --git a/test/unit/cli/test_recon.py b/test/unit/cli/test_recon.py index 141cfc5aa2..bdec8d83c8 100644 --- a/test/unit/cli/test_recon.py +++ b/test/unit/cli/test_recon.py @@ -263,6 +263,26 @@ class TestRecon(unittest.TestCase): self.assertEqual(set([('127.0.0.1', 10001), ('127.0.0.2', 10004)]), ips) + def test_get_error_ringnames(self): + # create invalid ring name files + invalid_ring_file_names = ('object.sring.gz', + 'object-1.sring.gz', + 'broken') + for invalid_ring in invalid_ring_file_names: + ring_path = os.path.join(self.swift_dir, invalid_ring) + with open(ring_path, 'w'): + pass + + hosts = [("127.0.0.1", "8080")] + self.recon_instance.verbose = True + self.recon_instance.server_type = 'object' + stdout = StringIO() + with mock.patch('sys.stdout', new=stdout), \ + mock.patch('swift.common.utils.md5'): + self.recon_instance.get_ringmd5(hosts, self.swift_dir) + output = stdout.getvalue() + self.assertNotIn('On disk ', output) + def test_get_ringmd5(self): for server_type in ('account', 'container', 'object', 'object-1'): ring_name = '%s.ring.gz' % server_type