ansible/test/units/module_utils
Toshio Kuratomi bd072fe83a
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
2018-12-18 18:01:46 -08:00
..
aws Move unit test compat code out of lib/ansible/. (#46996) 2018-10-12 20:01:14 -07:00
basic Port from plaform.dist to ansible.module_utils.distro.linux_distribution 2018-12-17 11:01:01 -08:00
cloud Move unit test compat code out of lib/ansible/. (#46996) 2018-10-12 20:01:14 -07:00
common Move unit test compat code out of lib/ansible/. (#46996) 2018-10-12 20:01:14 -07:00
ec2 Update bare exceptions to specify Exception. 2018-12-16 15:03:19 -08:00
facts Make the timeout decorator raise an exception out of the function's scope (#49921) 2018-12-18 18:01:46 -08:00
gcp Enable additional pylint rules and resolve issues found. (#47221) 2018-10-18 13:38:08 -07:00
json_utils Move unit test compat code out of lib/ansible/. (#46996) 2018-10-12 20:01:14 -07:00
net_tools Move unit test compat code out of lib/ansible/. (#46996) 2018-10-12 20:01:14 -07:00
network Replace nose with pytest 2018-11-26 13:41:57 -08:00
parsing
urls Fixing HTTPError case of fetch_url for Python 3 compatibility. (#45628) 2018-09-19 10:53:16 -05:00
__init__.py
conftest.py Python 3.8 collections compatibility fixes. 2018-10-08 11:26:37 -07:00
test_acme.py Code style adjustment. (#49329) 2018-11-29 21:57:32 +01:00
test_database.py Fix unit test parametrize order on Python 3.5. 2018-09-17 22:45:42 -07:00
test_distribution_version.py Port from plaform.dist to ansible.module_utils.distro.linux_distribution 2018-12-17 11:01:01 -08:00
test_distro.py Port from plaform.dist to ansible.module_utils.distro.linux_distribution 2018-12-17 11:01:01 -08:00
test_docker_common.py docker_* modules: simplify idempotency comparisons (#47709) 2018-10-30 08:50:34 +00:00
test_known_hosts.py Fix unit test parametrize order on Python 3.5. 2018-09-17 22:45:42 -07:00
test_postgresql.py Move unit test compat code out of lib/ansible/. (#46996) 2018-10-12 20:01:14 -07:00
test_text.py Porting tests to pytest (#33387) 2017-12-05 12:43:13 -08:00
test_vmware.py VMware: Fix module usages in module_utils (#49421) 2018-12-04 10:11:29 +05:30