summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJordan Borean <jborean93@gmail.com>2018-10-09 12:18:49 +1000
committerMatt Clay <matt@mystile.com>2018-10-09 18:56:02 -0700
commitf9c4da4cdfb79e333cded42480bf0a2811cc3f57 (patch)
tree51ede29ae689efc8f38716fcaf5ee42c82513985
parent034e5b634112f376ad4da93873f6d74d04db10c5 (diff)
downloadansible-f9c4da4cdfb79e333cded42480bf0a2811cc3f57.tar.gz
ansible-test: set ulimit to enforce consistent test environment (#46652)
* ansible-test: set ulimit to enforce consistent test environment * fixed santiy issue (cherry picked from commit 7b774117ab7504c72a583b3aae576933c78411d7)
-rwxr-xr-xtest/runner/injector/injector.py12
-rwxr-xr-xtest/runner/test.py12
2 files changed, 24 insertions, 0 deletions
diff --git a/test/runner/injector/injector.py b/test/runner/injector/injector.py
index 31bc0cbc37..238dd2ed52 100755
--- a/test/runner/injector/injector.py
+++ b/test/runner/injector/injector.py
@@ -32,6 +32,7 @@ import sys
import pipes
import logging
import getpass
+import resource
logger = logging.getLogger('injector') # pylint: disable=locally-disabled, invalid-name
# pylint: disable=locally-disabled, invalid-name
@@ -90,6 +91,17 @@ def main():
try:
logger.debug('Self: %s', __file__)
+ # to achieve a consistent nofile ulimit, set to 16k here, this can affect performance in subprocess.Popen when
+ # being called with close_fds=True on Python (8x the time on some environments)
+ nofile_limit = 16 * 1024
+ current_limit = resource.getrlimit(resource.RLIMIT_NOFILE)
+ new_limit = (nofile_limit, nofile_limit)
+ if current_limit > new_limit:
+ logger.debug('RLIMIT_NOFILE: %s -> %s', current_limit, new_limit)
+ resource.setrlimit(resource.RLIMIT_NOFILE, (nofile_limit, nofile_limit))
+ else:
+ logger.debug('RLIMIT_NOFILE: %s', current_limit)
+
config_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'injector.json')
try:
diff --git a/test/runner/test.py b/test/runner/test.py
index 1546c7900c..e8617a1504 100755
--- a/test/runner/test.py
+++ b/test/runner/test.py
@@ -7,6 +7,7 @@ from __future__ import absolute_import, print_function
import errno
import os
import sys
+import resource
from lib.util import (
ApplicationError,
@@ -85,6 +86,17 @@ def main():
display.info_stderr = (isinstance(config, SanityConfig) and config.lint) or (isinstance(config, IntegrationConfig) and config.list_targets)
check_startup()
+ # to achieve a consistent nofile ulimit, set to 16k here, this can affect performance in subprocess.Popen when
+ # being called with close_fds=True on Python (8x the time on some environments)
+ nofile_limit = 16 * 1024
+ current_limit = resource.getrlimit(resource.RLIMIT_NOFILE)
+ new_limit = (nofile_limit, nofile_limit)
+ if current_limit > new_limit:
+ display.info('RLIMIT_NOFILE: %s -> %s' % (current_limit, new_limit), verbosity=2)
+ resource.setrlimit(resource.RLIMIT_NOFILE, (nofile_limit, nofile_limit))
+ else:
+ display.info('RLIMIT_NOFILE: %s' % (current_limit, ), verbosity=2)
+
try:
args.func(config)
except Delegate as ex: