From 8663655afae42c2584f5d9c4d123eb00af9de85c Mon Sep 17 00:00:00 2001 From: Dan Smith Date: Thu, 14 Jan 2021 12:43:29 -0800 Subject: [PATCH] Make random_bytes() enforce sane size limits This makes random_bytes() refuse to generate more than 1MiB of data at a time. This should almost never be necessary, and we have chased actual gate OOM failures related to sloppy handling of even moderately-sized test buffers. Change-Id: I9cebe778a9309a0f4f5d78be97d062864e1849f1 --- .../notes/random-bytes-size-limit-ee94a8c6534fe916.yaml | 9 +++++++++ tempest/lib/common/utils/data_utils.py | 2 ++ 2 files changed, 11 insertions(+) create mode 100644 releasenotes/notes/random-bytes-size-limit-ee94a8c6534fe916.yaml diff --git a/releasenotes/notes/random-bytes-size-limit-ee94a8c6534fe916.yaml b/releasenotes/notes/random-bytes-size-limit-ee94a8c6534fe916.yaml new file mode 100644 index 0000000000..42322e4001 --- /dev/null +++ b/releasenotes/notes/random-bytes-size-limit-ee94a8c6534fe916.yaml @@ -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. diff --git a/tempest/lib/common/utils/data_utils.py b/tempest/lib/common/utils/data_utils.py index 44b55eb556..b6671b5d29 100644 --- a/tempest/lib/common/utils/data_utils.py +++ b/tempest/lib/common/utils/data_utils.py @@ -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)])