Defer passlib dependency from plugins/filter/network.py (#59304)
* Defer passlib dependency from plugins/filter/network.py to what utils/encrypt.py provides. * Revert test changes now that passlib is optional
This commit is contained in:
parent
fd9b643219
commit
41e4ece44b
2 changed files with 3 additions and 15 deletions
|
@ -33,7 +33,7 @@ from ansible.module_utils.six import iteritems, string_types
|
|||
from ansible.module_utils.common._collections_compat import Mapping
|
||||
from ansible.errors import AnsibleError, AnsibleFilterError
|
||||
from ansible.utils.display import Display
|
||||
from ansible.utils.encrypt import random_password
|
||||
from ansible.utils.encrypt import passlib_or_crypt, random_password
|
||||
|
||||
try:
|
||||
import yaml
|
||||
|
@ -47,12 +47,6 @@ try:
|
|||
except ImportError:
|
||||
HAS_TEXTFSM = False
|
||||
|
||||
try:
|
||||
from passlib.hash import md5_crypt
|
||||
HAS_PASSLIB = True
|
||||
except ImportError:
|
||||
HAS_PASSLIB = False
|
||||
|
||||
display = Display()
|
||||
|
||||
|
||||
|
@ -357,9 +351,6 @@ def parse_xml(output, tmpl):
|
|||
|
||||
|
||||
def type5_pw(password, salt=None):
|
||||
if not HAS_PASSLIB:
|
||||
raise AnsibleFilterError('type5_pw filter requires PassLib library to be installed')
|
||||
|
||||
if not isinstance(password, string_types):
|
||||
raise AnsibleFilterError("type5_pw password input should be a string, but was given a input of %s" % (type(password).__name__))
|
||||
|
||||
|
@ -375,7 +366,7 @@ def type5_pw(password, salt=None):
|
|||
elif not set(salt) <= set(salt_chars):
|
||||
raise AnsibleFilterError("type5_pw salt used inproper characters, must be one of %s" % (salt_chars))
|
||||
|
||||
encrypted_password = md5_crypt.encrypt(password, salt=salt)
|
||||
encrypted_password = passlib_or_crypt(password, "md5_crypt", salt=salt)
|
||||
|
||||
return encrypted_password
|
||||
|
||||
|
|
|
@ -23,8 +23,7 @@ import sys
|
|||
import pytest
|
||||
|
||||
from units.compat import unittest
|
||||
from ansible.plugins.filter.network import (HAS_PASSLIB, parse_xml, type5_pw, hash_salt,
|
||||
comp_type5, vlan_parser)
|
||||
from ansible.plugins.filter.network import parse_xml, type5_pw, hash_salt, comp_type5, vlan_parser
|
||||
|
||||
fixture_path = os.path.join(os.path.dirname(__file__), 'fixtures', 'network')
|
||||
|
||||
|
@ -83,7 +82,6 @@ class TestNetworkParseFilter(unittest.TestCase):
|
|||
self.assertEqual("parse_xml works on string input, but given input of : %s" % type(output), str(e.exception))
|
||||
|
||||
|
||||
@pytest.mark.skipif(not HAS_PASSLIB, reason="Current type5_pw filter needs passlib to function")
|
||||
class TestNetworkType5(unittest.TestCase):
|
||||
|
||||
def test_defined_salt_success(self):
|
||||
|
@ -147,7 +145,6 @@ class TestHashSalt(unittest.TestCase):
|
|||
self.assertEqual("Could not parse salt out password correctly from $nTc1$Z28sUTcWfXlvVe2x.3XAa.", str(e.exception))
|
||||
|
||||
|
||||
@pytest.mark.skipif(not HAS_PASSLIB, reason="Current comp_type5 filter needs passlib to function")
|
||||
class TestCompareType5(unittest.TestCase):
|
||||
|
||||
def test_compare_type5_boolean(self):
|
||||
|
|
Loading…
Add table
Reference in a new issue