Fix exceptions thrown from cryptography import (#16723)
A simple import of cryptography can throw several types of errors. For example, if `setuptools` is less than cryptography's minimum requirement of 11.3, then this import of cryptography will throw a VersionConflict here. An earlier case threw a DistributionNotFound exception. An optional dependency should not stop ansible. If the error is more than an ImportError, log a warning, so that errors can be fixed in ansible or elsewhere.
This commit is contained in:
parent
d8a3feb976
commit
b06c61c49b
1 changed files with 9 additions and 4 deletions
|
@ -30,6 +30,12 @@ from hashlib import sha256
|
||||||
from binascii import hexlify
|
from binascii import hexlify
|
||||||
from binascii import unhexlify
|
from binascii import unhexlify
|
||||||
|
|
||||||
|
try:
|
||||||
|
from __main__ import display
|
||||||
|
except ImportError:
|
||||||
|
from ansible.utils.display import Display
|
||||||
|
display = Display()
|
||||||
|
|
||||||
# Note: Only used for loading obsolete VaultAES files. All files are written
|
# Note: Only used for loading obsolete VaultAES files. All files are written
|
||||||
# using the newer VaultAES256 which does not require md5
|
# using the newer VaultAES256 which does not require md5
|
||||||
from hashlib import md5
|
from hashlib import md5
|
||||||
|
@ -71,10 +77,9 @@ try:
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if e.__module__ == 'pkg_resources' and e.__class__.__name__ == 'DistributionNotFound':
|
display.warning("Optional dependency 'cryptography' raised an exception, falling back to 'Crypto'")
|
||||||
pass
|
import traceback
|
||||||
else:
|
traceback.print_exc()
|
||||||
raise
|
|
||||||
|
|
||||||
from ansible.compat.six import PY3
|
from ansible.compat.six import PY3
|
||||||
from ansible.utils.unicode import to_unicode, to_bytes
|
from ansible.utils.unicode import to_unicode, to_bytes
|
||||||
|
|
Loading…
Reference in a new issue