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 Improve convert_bool error message 2018-02-12 13:05:38 -05:00
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 Surround top-level function and class definitions with two blank lines. 2018-07-31 12:06:56 -07:00
storage New module for managing EMC VNX Block storage (#42945) 2018-08-09 10:38:26 -07:00
__init__.py Enhance empty __init__ code-smell to check module_utils (#33438) 2017-11-30 15:47:38 -08:00
_text.py Fix for to_text and to_bytes error handlers 2017-07-24 09:19:04 -07:00
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 [AWS] Add Ansible Version to botocore user agent string (#39993) 2018-05-17 11:41:14 -04:00
ansible_tower.py Tower modules: move HAS_TOWER_CLI check in module_utils and minor improvements (#39809) 2018-08-02 11:17:39 -04:00
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 AWSRetry: allow retrying on additional ClientError exceptions (#28483) 2017-08-22 15:31:20 -04:00
cloudscale.py cloudscale_floating_ip module (#33181) 2017-12-11 14:48:35 +00:00
cloudstack.py cloudstack: fix query tags by resourceid (#40482) 2018-05-21 17:16:44 +02:00
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 Surround top-level function and class definitions with two blank lines. 2018-07-31 12:06:56 -07:00
digital_ocean.py Include Digital Ocean Token Alias (#36810) 2018-03-01 09:56:53 +05:30
dimensiondata.py dimensiondata: fix broken import (#35634) 2018-02-07 00:44:42 +01:00
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 exo_dns_record: remove limitation for multiple records only for A type (#35173) 2018-02-05 22:40:02 +01:00
f5_utils.py Refactor common network shared and platform utils code into package (#33452) 2017-12-03 21:42:30 +05:30
firewalld.py refactor firewalld module, add firewalld module_util (#37603) 2018-04-30 15:33:28 -05:00
gcdns.py Collated PEP8 fixes (#25293) 2017-06-02 12:14:11 +01:00
gce.py Collated PEP8 fixes (#25293) 2017-06-02 12:14:11 +01:00
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 Fix shebangs and file modes and update tests. (#40563) 2018-05-22 14:25:36 -07:00
heroku.py New module: heroku_collaborator (#39001) 2018-05-22 11:50:53 +02:00
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 influxdb: Add condition for retries argument (#38441) 2018-04-15 22:05:51 -04:00
ipa.py IPA: Add option to specify timeout (#44572) 2018-08-26 23:18:46 +05:30
ismount.py
json_utils.py Remove use of simplejson throughout code base (#43548) 2018-08-10 11:13:29 -05:00
keycloak.py New module: keycloak_clienttemplate (#33419) 2018-01-31 13:12:53 +00:00
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 Remove use of simplejson throughout code base (#43548) 2018-08-10 11:13:29 -05:00
manageiq.py Fix shebangs and file modes and update tests. (#40563) 2018-05-22 14:25:36 -07:00
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 New module: manage 1&1 public ip (cloud/oneandone/oneandone_public_ip) (#35079) 2018-02-07 12:15:27 -06:00
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 Remove wildcard imports and get_exception calls 2017-08-12 00:48:53 -07:00
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 Miscellaneous pylint fixes. 2017-09-13 01:53:08 -07:00
scaleway.py Add support for adding custom query parameters to URL (#46390) 2018-10-26 15:20:00 +01:00
service.py Fix typo of stderr 2018-07-31 13:23:05 -04:00
splitter.py Collated PEP8 fixes (#25293) 2017-06-02 12:14:11 +01:00
univention_umc.py Python 2.6 str.format() compatibility fixes. 2018-01-10 14:08:11 -08:00
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 Use response.content instead of response object (#25772) 2017-08-14 12:40:06 -04:00
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