mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Improve import error handling in azure_rm_common. (#29153)
* Improve import error handling in azure_rm_common. * Update skip.txt
This commit is contained in:
parent
d043ba2673
commit
cafd064547
2 changed files with 21 additions and 3 deletions
|
@ -21,11 +21,9 @@ import os
|
|||
import re
|
||||
import sys
|
||||
import copy
|
||||
import importlib
|
||||
import inspect
|
||||
import traceback
|
||||
|
||||
from packaging.version import Version
|
||||
from os.path import expanduser
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
|
@ -81,6 +79,22 @@ HAS_AZURE_CLI_CORE = True
|
|||
HAS_MSRESTAZURE = True
|
||||
HAS_MSRESTAZURE_EXC = None
|
||||
|
||||
try:
|
||||
import importlib
|
||||
except ImportError:
|
||||
# This passes the sanity import test, but does not provide a user friendly error message.
|
||||
# Doing so would require catching Exception for all imports of Azure dependencies in modules and module_utils.
|
||||
importlib = None
|
||||
|
||||
try:
|
||||
from packaging.version import Version
|
||||
HAS_PACKAGING_VERSION = True
|
||||
HAS_PACKAGING_VERSION_EXC = None
|
||||
except ImportError as exc:
|
||||
Version = None
|
||||
HAS_PACKAGING_VERSION = False
|
||||
HAS_PACKAGING_VERSION_EXC = exc
|
||||
|
||||
# NB: packaging issue sometimes cause msrestazure not to be installed, check it separately
|
||||
try:
|
||||
from msrest.serialization import Serializer
|
||||
|
@ -174,6 +188,10 @@ class AzureRMModuleBase(object):
|
|||
supports_check_mode=supports_check_mode,
|
||||
required_if=merged_required_if)
|
||||
|
||||
if not HAS_PACKAGING_VERSION:
|
||||
self.fail("Do you have packaging installed? Try `pip install packaging`"
|
||||
"- {0}".format(HAS_PACKAGING_VERSION_EXC))
|
||||
|
||||
if not HAS_MSRESTAZURE:
|
||||
self.fail("Do you have msrestazure installed? Try `pip install msrestazure`"
|
||||
"- {0}".format(HAS_MSRESTAZURE_EXC))
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
lib/ansible/module_utils/ansible_tower.py
|
||||
lib/ansible/module_utils/avi.py
|
||||
lib/ansible/module_utils/azure_rm_common.py
|
||||
lib/ansible/module_utils/ovirt.py
|
||||
lib/ansible/modules/cloud/amazon/cloudtrail.py
|
||||
lib/ansible/modules/cloud/amazon/ec2_vpc_igw.py
|
||||
lib/ansible/modules/cloud/amazon/ec2_vpc_route_table.py
|
||||
|
|
Loading…
Reference in a new issue