Fixed wrap from taking negative values

Now for wrap input it will take only postive integers as an input and
if any negative numbers are give it will give output as "Wrap argument
should be a non-negative integer".

Change-Id: I39a175e5a30af9128514fef814c6d62d2c283e84
Closes-Bug: #1628797
This commit is contained in:
M V P Nitesh 2017-06-28 11:32:47 +05:30 committed by Ruby Loo
parent 6425e65d90
commit 38e12731b0
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.