community.general/lib/ansible/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 [aws] ALB/NLB support SubnetMappings in AWS create LB call (#42060) 2018-10-04 16:53:32 -04:00
common Port from plaform.dist to ansible.module_utils.distro.linux_distribution 2018-12-17 11:01:01 -08:00
compat Misc fixes for several errors 2018-11-02 12:14:57 -04:00
csharp Windows Privileges - moved util code to it's own C# util (#48897) 2018-12-14 12:00:46 +10:00
distro Changes to bundled distro to be Python-2.6 compatible 2018-12-17 11:01:01 -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
k8s k8s_service: add new kubernetes module for handling Services (#48872) 2018-12-12 11:18:36 -05:00
net_tools Netbox Module: netbox_ip_address (#48424) 2018-12-13 09:40:15 +00:00
network Sanity fixes in various modules (#50080) 2018-12-18 09:53:46 -06:00
parsing
powershell Windows Privileges - moved util code to it's own C# util (#48897) 2018-12-14 12:00:46 +10:00
remote_management Update bare exceptions to specify Exception. 2018-12-16 15:03:19 -08:00
six
storage
__init__.py
_text.py
acme.py ACME: add diff to acme_account, account_public_key to acme_account_facts, and general refactoring (#49410) 2018-12-02 18:40:14 +01:00
alicloud_ecs.py Add new module ali_instance (#36898) 2018-10-23 13:02:21 -05:00
ansible_release.py
ansible_tower.py
api.py Update bare exceptions to specify Exception. 2018-12-16 15:03:19 -08:00
azure_rm_common.py Update bare exceptions to specify Exception. 2018-12-16 15:03:19 -08:00
azure_rm_common_rest.py support lro in azure_rm_resource (#49919) 2018-12-17 13:21:25 +08:00
basic.py Make the timeout decorator raise an exception out of the function's scope (#49921) 2018-12-18 18:01:46 -08:00
cloud.py
cloudscale.py
cloudstack.py
connection.py Remove cliconf from httpapi connection (#46813) 2018-12-11 16:26:59 -05:00
crypto.py openssl_privatekey: add ECC support (#49416) 2018-12-18 09:07:36 +00:00
database.py
digital_ocean.py
dimensiondata.py
docker_common.py Docker common consolidation (#49707) 2018-12-12 09:05:12 +00:00
ec2.py Update bare exceptions to specify Exception. 2018-12-16 15:03:19 -08:00
exoscale.py
f5_utils.py
firewalld.py
gcdns.py
gce.py
gcp.py removing libcloud secrets support for legacy gcp modules (#44932) 2018-08-31 08:28:32 -04:00
gcp_utils.py Fix google auth scoping for unscoped credentials (#46740) 2018-12-06 11:29:57 +00:00
gitlab.py
heroku.py
ibm_sa_utils.py IBM storage: fix domain issue by adding more keywords to pyxcli avail… (#48345) 2018-11-12 10:47:38 -05:00
infinibox.py Update bare exceptions to specify Exception. 2018-12-16 15:03:19 -08:00
influxdb.py
ipa.py IPA: Add option to specify timeout (#44572) 2018-08-26 23:18:46 +05:30
ismount.py
json_utils.py
keycloak.py
known_hosts.py Update bare exceptions to specify Exception. 2018-12-16 15:03:19 -08:00
ldap.py doc: fix maintainer's name (#44452) 2018-08-21 16:32:37 +02:00
linode.py Add new linode_v4 module. (#46151) 2018-11-16 12:39:05 +00:00
lxd.py
manageiq.py
memset.py New facts module: Memset Memstore (#42387) 2018-10-29 12:27:03 +00:00
mysql.py Migrate from MySQLdb to PyMySQL (#40123) 2018-09-19 08:44:05 -07:00
netapp.py Update bare exceptions to specify Exception. 2018-12-16 15:03:19 -08:00
netapp_elementsw_module.py Update bare exceptions to specify Exception. 2018-12-16 15:03:19 -08:00
netapp_module.py Adding Common files for NetApp ElementSW release (#43727) 2018-08-10 09:33:08 -07:00
oneandone.py
oneview.py Python 3.8 collections compatibility fixes. 2018-10-08 11:26:37 -07:00
online.py Add an Online servers fact 2018-09-24 21:03:50 +02:00
opennebula.py one_host environment variables, Fixes #44163 (#44568) 2018-08-27 10:55:04 -04:00
openstack.py openstack: fix parameter handling when cloud provided as dict (#42899) 2018-12-10 11:41:22 +00:00
ovirt.py ovirt: Return also nested attributes of structs (#49239) 2018-12-12 05:39:31 -05:00
postgres.py
pure.py Add user_agent into FlashBlade API calls (#46221) 2018-10-29 11:28:00 +00:00
pycompat24.py Enable pylint rules and fix exposed bugs. (#47219) 2018-10-19 08:32:52 -07:00
rabbitmq.py RabbitMQ publisher module (#44718) 2018-11-15 11:06:54 +10:00
rax.py Update bare exceptions to specify Exception. 2018-12-16 15:03:19 -08:00
redfish_utils.py GetManagerNicInventory (#49961) 2018-12-18 09:58:17 -06:00
redhat.py
scaleway.py Add support for adding custom query parameters to URL (#46390) 2018-10-26 15:20:00 +01:00
service.py
splitter.py
univention_umc.py
urls.py Sanity fixes in various modules (#50080) 2018-12-18 09:53:46 -06:00
utm_utils.py Creates base Sophos UTM module (#45781) 2018-10-26 23:21:54 +05:30
vca.py
vmware.py Ensure that current uses of BaseException are required 2018-12-16 15:03:19 -08:00
vmware_rest_client.py VMware: Add tag facts to vmware_guest_facts (#47495) 2018-10-25 09:45:38 +05:30
vultr.py vultr: fix for API returned unexpected empty list (#48036) 2018-11-04 11:23:36 +01:00
xenserver.py New module: xenserver_guest - manages XenServer VMs (#41041) 2018-11-19 01:50:20 -05:00
yumdnf.py Correct yum and dnf autoremove behavior (#47902) 2018-11-05 16:00:42 -05:00