From 2e710e792d3e70c18c2636e23feb44e19284b35c Mon Sep 17 00:00:00 2001 From: Vitalii Solodilov Date: Wed, 2 May 2018 12:12:14 +0400 Subject: [PATCH] Fixed workflow output in case of execution_field_size_limit_kb Now if length parameter in cut functions will be negative value that there is no restriction on length. Change-Id: I116d0bcb5663666ba4d280237a03d687de71f549 Closes-bug: #1768450 Signed-off-by: Vitalii Solodilov --- .../test_execution_fields_size_limitation.py | 26 +++++++++++++++++++ mistral/tests/unit/utils/test_utils.py | 14 ++++++++++ mistral/utils/__init__.py | 17 ++++++------ 3 files changed, 48 insertions(+), 9 deletions(-) diff --git a/mistral/tests/unit/engine/test_execution_fields_size_limitation.py b/mistral/tests/unit/engine/test_execution_fields_size_limitation.py index 7ab75c577..4689451f3 100644 --- a/mistral/tests/unit/engine/test_execution_fields_size_limitation.py +++ b/mistral/tests/unit/engine/test_execution_fields_size_limitation.py @@ -282,3 +282,29 @@ class ExecutionFieldsSizeLimitTest(base.EngineTestCase): self.assertGreater(len(task_ex.state_info), 65490) self.assertLess(len(wf_ex.state_info), 65536) self.assertGreater(len(wf_ex.state_info), 65490) + + def test_fail_workflow_no_limit(self): + cfg.CONF.set_default( + 'execution_field_size_limit_kb', + -1, + group='engine' + ) + + wf_service.create_workflows(WF) + + # Start workflow. + wf_ex = self.engine.start_workflow( + 'wf', + wf_input={ + 'action_output_length': 10000, + 'action_output_dict': True, + 'action_error': True + } + ) + + self.await_workflow_error(wf_ex.id) + + with db_api.transaction(): + wf_ex = db_api.get_workflow_execution(wf_ex.id) + + self.assertGreater(len(wf_ex.output['result']), 10000) diff --git a/mistral/tests/unit/utils/test_utils.py b/mistral/tests/unit/utils/test_utils.py index 4bc102afe..bf1deaf81 100644 --- a/mistral/tests/unit/utils/test_utils.py +++ b/mistral/tests/unit/utils/test_utils.py @@ -137,6 +137,7 @@ class UtilsTest(base.BaseTest): self.assertEqual('Hello...', utils.cut_string(s, length=5)) self.assertEqual(s, utils.cut_string(s, length=100)) + self.assertEqual(s, utils.cut_string(s, length=-1)) def test_cut_list(self): l = ['Hello, Mistral!', 'Hello, OpenStack!'] @@ -150,6 +151,11 @@ class UtilsTest(base.BaseTest): utils.cut_list(l, 100) ) + self.assertEqual( + "['Hello, Mistral!', 'Hello, OpenStack!']", + utils.cut_list(l, -1) + ) + self.assertEqual("[1, 2...", utils.cut_list([1, 2, 3, 4, 5], 8)) self.assertEqual("[1, 2,...", utils.cut_list([1, 2, 3, 4, 5], 9)) self.assertEqual("[1, 2, 3...", utils.cut_list([1, 2, 3, 4, 5], 11)) @@ -203,6 +209,14 @@ class UtilsTest(base.BaseTest): ] ) + self.assertIn( + utils.cut_dict(d, -1), + [ + "{'key1': 'value1', 'key2': 'value2'}", + "{'key2': 'value2', 'key1': 'value1'}" + ] + ) + self.assertRaises(ValueError, utils.cut_dict, (1, 2)) def test_cut_dict_with_digits(self): diff --git a/mistral/utils/__init__.py b/mistral/utils/__init__.py index b90daf7d8..6185fc31d 100644 --- a/mistral/utils/__init__.py +++ b/mistral/utils/__init__.py @@ -223,7 +223,7 @@ def cut_dict(d, length=100): if is_str: new_len += 2 # Account for the quotation marks - if new_len + len(res) >= length: + if 0 <= length <= new_len + len(res): res += "'%s" % k if is_str else k break else: @@ -239,7 +239,7 @@ def cut_dict(d, length=100): if is_str: new_len += 2 - if new_len + len(res) >= length: + if 0 <= length <= new_len + len(res): res += "'%s" % v if is_str else v break else: @@ -249,8 +249,9 @@ def cut_dict(d, length=100): idx += 1 - if len(res) >= length and res[length - 1] is not '}': + if 0 <= length <= len(res) and res[length - 1] is not '}': res = res[:length - 3] + '...' + return res @@ -270,20 +271,21 @@ def cut_list(l, length=100): if is_str: new_len += 2 - if new_len >= length: + if 0 <= length <= new_len: res += "'%s" % s if is_str else s break else: res += "'%s'" % s if is_str else s res += ', ' if idx < len(l) - 1 else ']' - if len(res) >= length and res[length - 1] is not ']': + if 0 <= length <= len(res) and res[length - 1] is not ']': res = res[:length - 3] + '...' + return res def cut_string(s, length=100): - if len(s) > length: + if 0 <= length < len(s): return "%s..." % s[:length] return s @@ -303,9 +305,6 @@ def cut(data, length=100): def cut_by_kb(data, kilobytes): - if kilobytes <= 0: - return cut(data) - length = get_number_of_chars_from_kilobytes(kilobytes) return cut(data, length)