Fix string formatting in dispersion cli command
... and add a basic test that would have prevented the regression Change-Id: I4c5f643ee291dcc1397ca951450459d8b8ad0bbd
This commit is contained in:
@@ -930,13 +930,19 @@ swift-ring-builder <builder_file> dispersion <search_filter> [options]
|
|||||||
for tier_name, dispersion in report['graph']:
|
for tier_name, dispersion in report['graph']:
|
||||||
replica_counts_repr = replica_counts_tmpl % tuple(
|
replica_counts_repr = replica_counts_tmpl % tuple(
|
||||||
dispersion['replicas'])
|
dispersion['replicas'])
|
||||||
print('%-' + str(tier_width) + 's ' + part_count_width +
|
template = ''.join([
|
||||||
' %6.02f %6d %s') % (tier_name,
|
'%-', str(tier_width), 's ',
|
||||||
dispersion['placed_parts'],
|
part_count_width,
|
||||||
dispersion['dispersion'],
|
' %6.02f %6d %s',
|
||||||
dispersion['max_replicas'],
|
])
|
||||||
replica_counts_repr,
|
args = (
|
||||||
)
|
tier_name,
|
||||||
|
dispersion['placed_parts'],
|
||||||
|
dispersion['dispersion'],
|
||||||
|
dispersion['max_replicas'],
|
||||||
|
replica_counts_repr,
|
||||||
|
)
|
||||||
|
print(template % args)
|
||||||
exit(status)
|
exit(status)
|
||||||
|
|
||||||
def validate():
|
def validate():
|
||||||
|
@@ -20,6 +20,7 @@ import six
|
|||||||
import tempfile
|
import tempfile
|
||||||
import unittest
|
import unittest
|
||||||
import uuid
|
import uuid
|
||||||
|
import shlex
|
||||||
|
|
||||||
from swift.cli import ringbuilder
|
from swift.cli import ringbuilder
|
||||||
from swift.common import exceptions
|
from swift.common import exceptions
|
||||||
@@ -29,6 +30,9 @@ from swift.common.ring import RingBuilder
|
|||||||
class RunSwiftRingBuilderMixin(object):
|
class RunSwiftRingBuilderMixin(object):
|
||||||
|
|
||||||
def run_srb(self, *argv):
|
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_stdout = six.StringIO()
|
||||||
mock_stderr = six.StringIO()
|
mock_stderr = six.StringIO()
|
||||||
|
|
||||||
@@ -40,7 +44,10 @@ class RunSwiftRingBuilderMixin(object):
|
|||||||
ringbuilder.main(srb_args)
|
ringbuilder.main(srb_args)
|
||||||
except SystemExit as err:
|
except SystemExit as err:
|
||||||
if err.code not in (0, 1): # (success, warning)
|
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())
|
return (mock_stdout.getvalue(), mock_stderr.getvalue())
|
||||||
|
|
||||||
|
|
||||||
@@ -1741,6 +1748,13 @@ class TestCommands(unittest.TestCase, RunSwiftRingBuilderMixin):
|
|||||||
err = exc
|
err = exc
|
||||||
self.assertEquals(err.code, 2)
|
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):
|
class TestRebalanceCommand(unittest.TestCase, RunSwiftRingBuilderMixin):
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user