From 38e12731b030a1dcd0e1cf6905417c77b2f7536e Mon Sep 17 00:00:00 2001 From: M V P Nitesh Date: Wed, 28 Jun 2017 11:32:47 +0530 Subject: [PATCH] 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 --- ironicclient/common/cliutils.py | 3 +++ ironicclient/tests/unit/common/test_cliutils.py | 4 ++++ releasenotes/notes/negative-wrap-fix-4197e91b2ecfb722.yaml | 7 +++++++ 3 files changed, 14 insertions(+) create mode 100644 releasenotes/notes/negative-wrap-fix-4197e91b2ecfb722.yaml diff --git a/ironicclient/common/cliutils.py b/ironicclient/common/cliutils.py index ce396a08f..c5fb9cfaa 100644 --- a/ironicclient/common/cliutils.py +++ b/ironicclient/common/cliutils.py @@ -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: diff --git a/ironicclient/tests/unit/common/test_cliutils.py b/ironicclient/tests/unit/common/test_cliutils.py index 13c649679..5984b5f73 100644 --- a/ironicclient/tests/unit/common/test_cliutils.py +++ b/ironicclient/tests/unit/common/test_cliutils.py @@ -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): diff --git a/releasenotes/notes/negative-wrap-fix-4197e91b2ecfb722.yaml b/releasenotes/notes/negative-wrap-fix-4197e91b2ecfb722.yaml new file mode 100644 index 000000000..b874c7f3d --- /dev/null +++ b/releasenotes/notes/negative-wrap-fix-4197e91b2ecfb722.yaml @@ -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.