Fix test_range_templating on 32-bit architectures (#85007)

* Fix test_range_templating on 32-bit architectures

32-bit archtectures like i386, armel, armhf will fail with the error

ansible._internal._templating._errors.AnsibleTemplatePluginRuntimeError: The
filter plugin 'ansible.builtin.random' failed: Python int too large to convert
to C ssize_t

So just pick sys.maxsize (2**31 - 1) so it works on 32 bit machines.

---------

Co-authored-by: Lee Garrett <lgarrett@rocketjump.eu>
Co-authored-by: Matt Clay <matt@mystile.com>
(cherry picked from commit 5f6aef95ac)
pull/85040/head
Lee Garrett 8 months ago committed by Matt Martz
parent 82ea3addce
commit 7fc916361e
No known key found for this signature in database
GPG Key ID: 40832D88E9FC91D8

@ -5,6 +5,7 @@ from __future__ import annotations
import collections.abc as c import collections.abc as c
import copy import copy
import re import re
import sys
import typing as t import typing as t
import pytest import pytest
@ -463,11 +464,13 @@ def test_range_templating():
They are usually listified like other iterables when returned from a Jinja filter or method/function call, except when calling the Python `range()` They are usually listified like other iterables when returned from a Jinja filter or method/function call, except when calling the Python `range()`
global function directly, which allows the range object to be returned and used directly. global function directly, which allows the range object to be returned and used directly.
""" """
templar = TemplateEngine() templar = TemplateEngine(variables=dict(
large_value=min(1000000000000, sys.maxsize - 1) # ensure we don't exceed ssize_t on 32-bit systems
))
# ensure that an insanely large range is not listified # ensure that an insanely large range is not listified
assert templar.evaluate_conditional(TRUST.tag("range(1000000000000) | type_debug == 'range'")) assert templar.evaluate_conditional(TRUST.tag("range(large_value) | type_debug == 'range'"))
assert isinstance(templar.template(TRUST.tag("{{ range(1000000000000) | random }}")), int) assert isinstance(templar.template(TRUST.tag("{{ range(large_value) | random }}")), int)
assert templar.template(TRUST.tag("{{ range(3) | reverse }}")) == [2, 1, 0] assert templar.template(TRUST.tag("{{ range(3) | reverse }}")) == [2, 1, 0]

Loading…
Cancel
Save