Merge "Fix string formatting in dispersion cli command"

This commit is contained in:
Jenkins 2015-07-31 13:23:43 +00:00 committed by Gerrit Code Review
commit 9d101ac6e6
2 changed files with 28 additions and 8 deletions

View File

@ -930,13 +930,19 @@ swift-ring-builder <builder_file> dispersion <search_filter> [options]
for tier_name, dispersion in report['graph']:
replica_counts_repr = replica_counts_tmpl % tuple(
dispersion['replicas'])
print('%-' + str(tier_width) + 's ' + part_count_width +
' %6.02f %6d %s') % (tier_name,
dispersion['placed_parts'],
dispersion['dispersion'],
dispersion['max_replicas'],
replica_counts_repr,
)
template = ''.join([
'%-', str(tier_width), 's ',
part_count_width,
' %6.02f %6d %s',
])
args = (
tier_name,
dispersion['placed_parts'],
dispersion['dispersion'],
dispersion['max_replicas'],
replica_counts_repr,
)
print(template % args)
exit(status)
def validate():

View File

@ -20,6 +20,7 @@ import six
import tempfile
import unittest
import uuid
import shlex
from swift.cli import ringbuilder
from swift.common import exceptions
@ -29,6 +30,9 @@ from swift.common.ring import RingBuilder
class RunSwiftRingBuilderMixin(object):
def run_srb(self, *argv):
if len(argv) == 1 and isinstance(argv[0], basestring):
# convert a single string to a list
argv = shlex.split(argv[0])
mock_stdout = six.StringIO()
mock_stderr = six.StringIO()
@ -40,7 +44,10 @@ class RunSwiftRingBuilderMixin(object):
ringbuilder.main(srb_args)
except SystemExit as err:
if err.code not in (0, 1): # (success, warning)
raise
msg = 'Unexpected exit status %s\n' % err.code
msg += 'STDOUT:\n%s\nSTDERR:\n%s\n' % (
mock_stdout.getvalue(), mock_stderr.getvalue())
self.fail(msg)
return (mock_stdout.getvalue(), mock_stderr.getvalue())
@ -1741,6 +1748,13 @@ class TestCommands(unittest.TestCase, RunSwiftRingBuilderMixin):
err = exc
self.assertEquals(err.code, 2)
def test_dispersion_command(self):
self.create_sample_ring()
self.run_srb('rebalance')
out, err = self.run_srb('dispersion -v')
self.assertIn('dispersion', out.lower())
self.assertFalse(err)
class TestRebalanceCommand(unittest.TestCase, RunSwiftRingBuilderMixin):