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 <mcdkr@yandex.ru>
This commit is contained in:
parent
15ebebf9fa
commit
2e710e792d
|
@ -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)
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in New Issue