Commit 774d2fcb authored by Jérome Perrin's avatar Jérome Perrin

software/erp5: add control for PYTHONHASHSEED

See https://docs.python.org/3/using/cmdline.html#envvar-PYTHONHASHSEED

Setting a value will set the environment variable for all zope processes
and for the test runner.

Default behavior is:
  - for zope: do not set the variable, so default python behavior will
  be used ( equivalent to setting `0` on python2 and `random` on python3)
  - for test runner: generate a random value for each execution and
  print it, to make it easy to re-run a failing test with the same seed.

This means that ERP5 tests will likely reveal problems where code
depends on python2 behavior of deterministic hashing. To keep previous
behavior (and hide these problems), it's possible to set
python-hash-seed to 0 in test suite parameters.
parent 25c9e0fb
...@@ -107,6 +107,18 @@ ...@@ -107,6 +107,18 @@
"description": "Set open file descriptors soft limit to hard limit", "description": "Set open file descriptors soft limit to hard limit",
"type": "boolean" "type": "boolean"
}, },
"python-hash-seed": {
"description": "Sets the value of `PYTHONHASHSEED` environment variable for zope processes and test runner. If not provided, zope processes use python default (`0` for python2, `random` for python3) and test runner choose a different `PYTHONHASHSEED` for each execution.",
"oneOf": [
{
"type": "number"
},
{
"const": "random",
"type": "string"
}
]
},
"family-override": { "family-override": {
"description": "Family-wide options, possibly overriding global options", "description": "Family-wide options, possibly overriding global options",
"default": {}, "default": {},
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
# not need these here). # not need these here).
[template-erp5] [template-erp5]
filename = instance-erp5.cfg.in filename = instance-erp5.cfg.in
md5sum = 620912069597ea748d55cb68790fa270 md5sum = 38eab3283d175230231c998fa4a3416e
[template-balancer] [template-balancer]
filename = instance-balancer.cfg.in filename = instance-balancer.cfg.in
......
...@@ -253,6 +253,7 @@ config-memcached-url = ${request-memcached-volatile:connection-url} ...@@ -253,6 +253,7 @@ config-memcached-url = ${request-memcached-volatile:connection-url}
config-monitor-passwd = ${monitor-htpasswd:passwd} config-monitor-passwd = ${monitor-htpasswd:passwd}
config-mysql-test-url-list = ${request-mariadb:connection-test-database-list} config-mysql-test-url-list = ${request-mariadb:connection-test-database-list}
config-mysql-url-list = ${request-mariadb:connection-database-list} config-mysql-url-list = ${request-mariadb:connection-database-list}
config-python-hash-seed = {{ dumps(slapparameter_dict.get('python-hash-seed', '')) }}
config-site-id = {{ dumps(site_id) }} config-site-id = {{ dumps(site_id) }}
config-smtp-url = ${request-smtp:connection-url} config-smtp-url = ${request-smtp:connection-url}
config-timezone = {{ dumps(slapparameter_dict.get('timezone', 'UTC')) }} config-timezone = {{ dumps(slapparameter_dict.get('timezone', 'UTC')) }}
......
...@@ -273,6 +273,7 @@ link-binary = ...@@ -273,6 +273,7 @@ link-binary =
${sed:location}/bin/sed ${sed:location}/bin/sed
${tesseract:location}/bin/tesseract ${tesseract:location}/bin/tesseract
${w3m:location}/bin/w3m ${w3m:location}/bin/w3m
${coreutils:location}/bin/shuf
fonts = fonts =
${liberation-fonts:location} ${liberation-fonts:location}
${ipaex-fonts:location} ${ipaex-fonts:location}
......
...@@ -74,7 +74,7 @@ md5sum = ca0cb83950dd9079cc289891cce08e76 ...@@ -74,7 +74,7 @@ md5sum = ca0cb83950dd9079cc289891cce08e76
[template-erp5] [template-erp5]
filename = instance-erp5.cfg.in filename = instance-erp5.cfg.in
md5sum = 7318eb93f1abf4c07a54b89e4a710fa6 md5sum = 6f57c834eb3f774d265c3fd6661429d8
[template-zeo] [template-zeo]
filename = instance-zeo.cfg.in filename = instance-zeo.cfg.in
...@@ -86,7 +86,7 @@ md5sum = 0ac4b74436f554cd677f19275d18d880 ...@@ -86,7 +86,7 @@ md5sum = 0ac4b74436f554cd677f19275d18d880
[template-zope] [template-zope]
filename = instance-zope.cfg.in filename = instance-zope.cfg.in
md5sum = 6178ba7b42848f9e2412ab898a7b026c md5sum = 8725a6b42de735b64b51d9bac598f94b
[template-balancer] [template-balancer]
filename = instance-balancer.cfg.in filename = instance-balancer.cfg.in
......
...@@ -247,6 +247,7 @@ config-memcached-url = ${request-memcached-volatile:connection-url} ...@@ -247,6 +247,7 @@ config-memcached-url = ${request-memcached-volatile:connection-url}
config-monitor-passwd = ${monitor-htpasswd:passwd} config-monitor-passwd = ${monitor-htpasswd:passwd}
config-mysql-test-url-list = ${request-mariadb:connection-test-database-list} config-mysql-test-url-list = ${request-mariadb:connection-test-database-list}
config-mysql-url-list = ${request-mariadb:connection-database-list} config-mysql-url-list = ${request-mariadb:connection-database-list}
config-python-hash-seed = {{ dumps(slapparameter_dict.get('python-hash-seed', '')) }}
config-site-id = {{ dumps(site_id) }} config-site-id = {{ dumps(site_id) }}
config-smtp-url = ${request-smtp:connection-url} config-smtp-url = ${request-smtp:connection-url}
config-timezone = {{ dumps(slapparameter_dict.get('timezone', 'UTC')) }} config-timezone = {{ dumps(slapparameter_dict.get('timezone', 'UTC')) }}
......
...@@ -85,6 +85,9 @@ environment += ...@@ -85,6 +85,9 @@ environment +=
JUPYTER_PATH=${directory:jupyter-dir} JUPYTER_PATH=${directory:jupyter-dir}
JUPYTER_CONFIG_DIR=${directory:jupyter-config-dir} JUPYTER_CONFIG_DIR=${directory:jupyter-config-dir}
JUPYTER_RUNTIME_DIR=${directory:jupyter-runtime-dir} JUPYTER_RUNTIME_DIR=${directory:jupyter-runtime-dir}
{% if slapparameter_dict.get('python-hash-seed') %}
PYTHONHASHSEED={{ slapparameter_dict['python-hash-seed'] }}
{% endif %}
{% if slapparameter_dict.get('wendelin-core-zblk-fmt') %} {% if slapparameter_dict.get('wendelin-core-zblk-fmt') %}
WENDELIN_CORE_ZBLK_FMT={{ slapparameter_dict['wendelin-core-zblk-fmt'] }} WENDELIN_CORE_ZBLK_FMT={{ slapparameter_dict['wendelin-core-zblk-fmt'] }}
{% endif %} {% endif %}
...@@ -469,9 +472,26 @@ context = ...@@ -469,9 +472,26 @@ context =
{% else -%} {% else -%}
[{{ section('run-unit-test-userhosts-wrapper') }}] [{{ section('run-unit-test-userhosts-wrapper') }}]
<= userhosts-wrapper-base <= userhosts-wrapper-base
wrapped-command-line = ${runUnitTest:wrapper-path} wrapped-command-line = ${run-unit-test-python-hash-seed-wrapper:output}
wrapper-path = ${buildout:bin-directory}/runUnitTest wrapper-path = ${buildout:bin-directory}/runUnitTest
[{{ section('run-unit-test-python-hash-seed-wrapper') }}]
recipe = slapos.recipe.template
inline =
#!/bin/sh
{% if slapparameter_dict.get('python-hash-seed') %}
PYTHONHASHSEED={{ slapparameter_dict['python-hash-seed'] }}
{% endif %}
if [ -z "$PYTHONHASHSEED" ]; then
PYTHONHASHSEED=$(${buildout:bin-directory}/shuf -i 1-1024 -n 1)
echo "Generated PYTHONHASHSEED: $PYTHONHASHSEED"
else
echo "Using PYTHONHASHSEED: $PYTHONHASHSEED"
fi
export PYTHONHASHSEED
exec ${runUnitTest:wrapper-path} "$@"
output = ${buildout:bin-directory}/runUnitTest.python-hash-seed
[{{ section('run-test-suite-userhosts-wrapper') }}] [{{ section('run-test-suite-userhosts-wrapper') }}]
<= userhosts-wrapper-base <= userhosts-wrapper-base
wrapped-command-line = ${runTestSuite:wrapper-path} wrapped-command-line = ${runTestSuite:wrapper-path}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment