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 <tsuyuzaki.kota@lab.ntt.co.jp>
Closes-Bug: #1680704
Change-Id: Ida659fa71585f9b0cf36da75b58b28e6a25533df
This commit is contained in:
lijunbo
2017-04-07 16:21:55 +08:00
committed by junboli
parent bc9a7075d3
commit 6788bf4aad
2 changed files with 21 additions and 1 deletions

View File

@@ -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

View File

@@ -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