Merge "Make random_bytes() enforce sane size limits"

This commit is contained in:
Zuul 2021-01-26 09:10:05 +00:00 committed by Gerrit Code Review
commit 1f385c2cb2
2 changed files with 11 additions and 0 deletions

View File

@ -0,0 +1,9 @@
---
upgrade:
- |
The ``tempest.lib.common.utils.data_utils.random_bytes()`` helper
function will no longer allow a ``size`` of more than 1MiB. Tests
generally do not need to generate and use large payloads for
feature verification and it is easy to lose track of and duplicate
large buffers. The sum total of such errors can become problematic
in paralllelized and constrained CI environments.

View File

@ -169,6 +169,8 @@ def random_bytes(size=1024):
:return: size randomly bytes
:rtype: string
"""
if size > 1 << 20:
raise RuntimeError('Size should be less than 1MiB')
return b''.join([six.int2byte(random.randint(0, 255))
for i in range(size)])