Merge "Fixed wrap from taking negative values"

This commit is contained in:
Jenkins 2017-07-10 19:21:40 +00:00 committed by Gerrit Code Review
commit 5cdb655241
3 changed files with 14 additions and 0 deletions

View File

@ -223,6 +223,9 @@ def print_dict(dct, dict_property="Property", wrap=0, dict_value='Value',
v = six.text_type(v)
if wrap > 0:
v = textwrap.fill(six.text_type(v), wrap)
elif wrap < 0:
raise ValueError(_("wrap argument should be a non-negative "
"integer"))
# if value has a newline, add in multiple rows
# e.g. fault with stacktrace
if v and isinstance(v, six.string_types) and r'\n' in v:

View File

@ -663,6 +663,10 @@ class PrintResultStringTestCase(test_base.BaseTestCase):
'''
self.assertEqual(expected, out)
def test_print_dict_negative_wrap(self):
dct = {"K": "k", "Key": "Value"}
self.assertRaises(ValueError, cliutils.print_dict, dct, wrap=-10)
class DecoratorsTestCase(test_base.BaseTestCase):

View File

@ -0,0 +1,7 @@
---
fixes:
- |
``--wrap`` CLI argument for ``ironic driver-properties`` and
``ironic driver-raid-logical-disk-properties`` commands now takes
only non-negative integers as input. An error is shown if a
negative value is passed.