You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ansible/test/units/module_utils
Toshio Kuratomi aa859597b1 Make the timeout decorator raise an exception out of the function's scope (#49921)
* Revert "allow caller to deal with timeout (#49449)"

This reverts commit 63279823a7.

Flawed on many levels

* Adds poor API to a public function
* Papers over the fact that the public function is doing something bad
  by catching exceptions it cannot handle in the first place
* Papers over the real cause of the issue which is a bug in the timeout
  decorator
* Doesn't reraise properly
* Catches the wrong exception

Fixes #49824
Fixes #49817

* Make the timeout decorator properly raise an exception outside of the function's scope

signal handlers which raise exceptions will never work well because the
exception can be raised anywhere in the called code.  This leads to
exception race conditions where the exceptions could end up being
hanlded by unintended pieces of the called code.

The timeout decorator was using just that idiom.  It was especially bad
because the decorator syntactically occurs outside of the called code
but because of the signal handler, the exception was being raised inside
of the called code.

This change uses a thread instead of a signal to manage the timeout in
parallel to the execution of the decorated function.  Since raising of
the exception happens inside of the decorator, now, instead of inside of
a signal handler, the timeout exception is raised from outside of the
called code as expected which makes reasoning about where exceptions are
to be expected intuitive again.

Fixes #43884

* Add a common case test.

Adding an integration test driven from our unittests.  Most of the time
we'll timeout in run_command which is running things in a subprocess.
Create a test for that specific case in case anything funky comes up
between threading and execve.

* Don't use OSError-based TimeoutError as a base class

Unlike most standard exceptions, OSError has a specific parameter list
with specific meanings.  Instead follow the example of other stdlib
functions, concurrent.futures and multiprocessing and define a separate
TimeoutException.

* Add comment and docstring to point out that this is not hte Python3 TimeoutError

(cherry picked from commit bd072fe83a)
7 years ago
..
aws AnsiballZ improvements 7 years ago
basic [stable-2.7] Python 2: accept both long and int for type=int (module options) (#53289) 7 years ago
cloud [cloud] Add more configurable backoff implementations to CloudRetry/AWSRetry (#27251) 8 years ago
common Provide kubernetes definition diffs in check_mode (#41471) 8 years ago
ec2 Provide kubernetes definition diffs in check_mode (#41471) 8 years ago
facts Make the timeout decorator raise an exception out of the function's scope (#49921) 7 years ago
gcp removing libcloud secrets support for legacy gcp modules (#44932) 7 years ago
json_utils Port some tests away from nose as examples (#33437) 8 years ago
net_tools Fix for updating the name in case of host record and network view and also display meaningful error in case of connection timeout (#40597) 8 years ago
network [stable-2.7] FTD HTTP Api plugin bug fixes (#47747) (#48982) 7 years ago
parsing Consolidate boolean/mk_boolean conversion functions into a single location 9 years ago
urls Fixing HTTPError case of fetch_url for Python 3 compatibility. (#45628) 7 years ago
__init__.py Add empty-init code-smell script. (#18406) 9 years ago
conftest.py AnsiballZ improvements 7 years ago
test_database.py Fix unit test parametrize order on Python 3.5. 7 years ago
test_distribution_version.py set ansible_os_family from name variable in os-release for clearlinux… (#49906) 7 years ago
test_docker_common.py docker_* modules: simplify idempotency comparisons (#47709) 7 years ago
test_known_hosts.py Fix unit test parametrize order on Python 3.5. 7 years ago
test_postgresql.py Porting tests to pytest (#33387) 8 years ago
test_text.py Porting tests to pytest (#33387) 8 years ago
test_vmware.py VMware: Fix module usages in module_utils (#49421) 7 years ago