1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Fix azure module use of module_utils.facts (#25318)

Module was importing '*' from facts to get to TimeoutError
but that has moved to facts.timeout, so import is updated.

Also rm old style imports to new style imports at the start
of the module.

'signal' py module was used and referenced but never imported,
presumably it was using the 'signal' previously imported into
module_utils.facts. Now imported directly.

'AnsibleModule' was also from a * import, so now imported directly.

A ref to 'module' was in _delete_disks_when_detached(), so now it
is updated to raise an AzureException() with its message, and
let its caller catch it and call module.fail_json()
This commit is contained in:
Adrian Likins 2017-07-11 14:07:20 -04:00 committed by GitHub
parent dc75bc06d9
commit 261c40bac7
2 changed files with 8 additions and 5 deletions

View file

@ -192,9 +192,11 @@ EXAMPLES = '''
import base64
import datetime
import os
import signal
import time
from urlparse import urlparse
from ansible.module_utils.facts import * # TimeoutError
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.facts.timeout import TimeoutError
AZURE_LOCATIONS = ['South Central US',
'Central US',
@ -279,6 +281,7 @@ except ImportError:
from types import MethodType
import json
def _wait_for_completion(azure, promise, wait_timeout, msg):
if not promise:
return
@ -291,6 +294,7 @@ def _wait_for_completion(azure, promise, wait_timeout, msg):
raise AzureException('Timed out waiting for async operation ' + msg + ' "' + str(promise.request_id) + '" to complete.')
def _delete_disks_when_detached(azure, wait_timeout, disk_names):
def _handle_timeout(signum, frame):
raise TimeoutError("Timeout reached while waiting for disks to become detached.")
@ -305,10 +309,11 @@ def _delete_disks_when_detached(azure, wait_timeout, disk_names):
azure.delete_disk(disk.name, True)
disk_names.remove(disk_name)
except AzureException as e:
module.fail_json(msg="failed to get or delete disk %s, error was: %s" % (disk_name, str(e)))
raise AzureException("failed to get or delete disk %s, error was: %s" % (disk_name, str(e)))
finally:
signal.alarm(0)
def get_ssh_certificate_tokens(module, ssh_cert_path):
"""
Returns the sha1 fingerprint and a base64-encoded PKCS12 version of the certificate.
@ -376,7 +381,7 @@ def create_virtual_machine(module, azure):
disable_ssh_password_authentication = not password
vm_config = LinuxConfigurationSet(hostname, user, password, disable_ssh_password_authentication)
else:
#Create Windows Config
# Create Windows Config
vm_config = WindowsConfigurationSet(hostname, password, None, module.params.get('auto_updates'), None, user)
vm_config.domain_join = None
if module.params.get('enable_winrm'):
@ -620,6 +625,5 @@ class Wrapper(object):
# import module snippets
from ansible.module_utils.basic import *
if __name__ == '__main__':
main()

View file

@ -66,7 +66,6 @@ lib/ansible/modules/cloud/amazon/sts_assume_role.py
lib/ansible/modules/cloud/amazon/sts_session_token.py
lib/ansible/modules/cloud/atomic/atomic_host.py
lib/ansible/modules/cloud/atomic/atomic_image.py
lib/ansible/modules/cloud/azure/azure.py
lib/ansible/modules/cloud/azure/azure_rm_deployment.py
lib/ansible/modules/cloud/azure/azure_rm_networkinterface.py
lib/ansible/modules/cloud/azure/azure_rm_networkinterface_facts.py