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>
pull/85016/head
Lee Garrett 8 months ago committed by GitHub
parent 1b6b910439
commit 5f6aef95ac
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -5,6 +5,7 @@ from __future__ import annotations
import collections.abc as c
import copy
import re
import sys
import typing as t
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()`
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
assert templar.evaluate_conditional(TRUST.tag("range(1000000000000) | type_debug == 'range'"))
assert isinstance(templar.template(TRUST.tag("{{ range(1000000000000) | random }}")), int)
assert templar.evaluate_conditional(TRUST.tag("range(large_value) | type_debug == 'range'"))
assert isinstance(templar.template(TRUST.tag("{{ range(large_value) | random }}")), int)
assert templar.template(TRUST.tag("{{ range(3) | reverse }}")) == [2, 1, 0]

Loading…
Cancel
Save