Skip to content

Commit 03691e6

Browse files
committed
Remove ansible-core 2.20 deprecated imports
This commit removes all dependencies on the 'asible.module_util.six' module and fixes deprecated imports as defined by the ansible-core release version 2.20. This changes render ansible-freeipa collection incompatible with Python 2. Changes include: * Remove six module imports from all modules and roles - Removed 'from ansible.module_utils import six' statements - Removed 'from ansible.module_utils.six.moves' imports * Replace and remove Python version checks (six.PY3 and six.PY2) * Replace unicode usage with to_text or str * Ensure text conversion routines imports are consistent and are imported from Ansible common.text.converters * Update standard library imports - Changed 'six.moves.urllib.parse' to 'urllib.parse' - Changed 'six.moves.configparser' to 'ConfigParser' - Import 'Mapping' from 'collections.abc' * Remove Python 2 specific code Signed-off-by: Rafael Guterres Jeffman <rjeffman@redhat.com>
1 parent 0b9718b commit 03691e6

37 files changed

Lines changed: 58 additions & 204 deletions

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ configured trust to an AD domain). For these cases, there are some `facts`
8787
available that will only enable the tests if the testing environment is
8888
enabled.
8989

90-
The tests run automatically on every pull request, using Fedora, CentOS 7,
91-
and CentOS 8 environments.
90+
The tests run automatically on every pull request, using Fedora, and CentOS
91+
supported environments.
9292

9393
See the document [Running the tests] and also the section `Preparing the
9494
development environment`, to prepare your environment.

README-host.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Example playbook to ensure host presence:
5858
ip_address: 192.168.0.123
5959
locality: Lab
6060
ns_host_location: Lab
61-
ns_os_version: CentOS 7
61+
ns_os_version: CentOS Stream 10
6262
ns_hardware_platform: Lenovo T61
6363
mac_address:
6464
- "08:00:27:E3:B1:2D"
@@ -89,7 +89,7 @@ Example playbook to ensure host presence with several IP addresses:
8989
- fe80::20c:29ff:fe02:a1b4
9090
locality: Lab
9191
ns_host_location: Lab
92-
ns_os_version: CentOS 7
92+
ns_os_version: CentOS Stream 10
9393
ns_hardware_platform: Lenovo T61
9494
mac_address:
9595
- "08:00:27:E3:B1:2D"

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ The client role supports versions 4.4 and up, the server role is working with ve
6767
Supported Distributions
6868
-----------------------
6969

70-
* RHEL/CentOS 7.4+
70+
* RHEL 8/9/10
71+
* CentOS Stream 8+
7172
* Fedora 40+
7273
* Ubuntu
7374
* Debian 10+ (ipaclient only, no server or replica!)

plugins/inventory/freeipa.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
from ansible.errors import AnsibleParserError
105105
from ansible.module_utils.common.text.converters import to_native
106106
from ansible.plugins.inventory import BaseInventoryPlugin
107-
from ansible.module_utils.six.moves.urllib.parse import quote
107+
from urllib.parse import quote
108108

109109

110110
class InventoryModule(BaseInventoryPlugin): # pylint: disable=R0901

plugins/module_utils/ansible_freeipa_module.py

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,9 @@
5959
import time
6060
from datetime import datetime
6161
from contextlib import contextmanager
62+
from collections.abc import Mapping
6263
from ansible.module_utils.basic import AnsibleModule
63-
from ansible.module_utils._text import to_text
64-
from ansible.module_utils.common.text.converters import jsonify
65-
from ansible.module_utils import six
66-
from ansible.module_utils.common._collections_compat import Mapping
64+
from ansible.module_utils.common.text.converters import jsonify, to_text
6765
from ansible.module_utils.parsing.convert_bool import boolean
6866

6967
# Import getargspec from inspect or provide own getargspec for
@@ -165,11 +163,7 @@ def is_ipa_configured():
165163
except ImportError:
166164
_dcerpc_bindings_installed = False # pylint: disable=invalid-name
167165

168-
try:
169-
from urllib.parse import urlparse
170-
except ImportError:
171-
from ansible.module_utils.six.moves.urllib.parse import urlparse
172-
166+
from urllib.parse import urlparse
173167
from ipalib.util import normalize_sshpubkey
174168

175169
except ImportError as _err:
@@ -187,10 +181,6 @@ def is_ipa_configured():
187181
ANSIBLE_FREEIPA_MODULE_IMPORT_ERROR = None
188182

189183

190-
if six.PY3:
191-
unicode = str
192-
193-
194184
def valid_creds(module, principal): # noqa
195185
"""Get valid credentials matching the princial, try GSSAPI first."""
196186
if "KRB5CCNAME" in os.environ:
@@ -508,10 +498,7 @@ def module_params_get(module, name, allow_empty_list_item=False):
508498
# Ansible issue https://github.com/ansible/ansible/issues/77108
509499
if isinstance(value, list):
510500
for val in value:
511-
if (
512-
isinstance(val, (str, unicode)) # pylint: disable=W0012,E0606
513-
and not val
514-
):
501+
if isinstance(val, str) and not val:
515502
if not allow_empty_list_item:
516503
module.fail_json(
517504
msg="Parameter '%s' contains an empty string" %
@@ -532,7 +519,7 @@ def module_params_get_lowercase(module, name, allow_empty_list_item=False):
532519
def convert_param_value_to_lowercase(value):
533520
if isinstance(value, list):
534521
value = [v.lower() for v in value]
535-
if isinstance(value, (str, unicode)):
522+
if isinstance(value, str):
536523
value = value.lower()
537524
return value
538525

@@ -673,12 +660,11 @@ def encode_certificate(cert):
673660
It also takes FreeIPA and Python versions into account.
674661
This is used to convert the certificates returned by find and show.
675662
"""
676-
if isinstance(cert, (str, unicode, bytes)):
663+
if isinstance(cert, (str, bytes)):
677664
encoded = base64.b64encode(cert)
678665
else:
679666
encoded = base64.b64encode(cert.public_bytes(Encoding.DER))
680-
if not six.PY2:
681-
encoded = encoded.decode('ascii')
667+
encoded = encoded.decode('ascii')
682668
return encoded
683669

684670

@@ -795,9 +781,9 @@ def _normalize_principal_name(name, realm):
795781

796782
if len(princ.components) == 1 and \
797783
not princ.components[0].endswith('$'):
798-
nprinc = 'host/' + unicode(princ)
784+
nprinc = 'host/' + str(princ)
799785
else:
800-
nprinc = unicode(princ)
786+
nprinc = str(princ)
801787
return nprinc
802788

803789
def _check_exists(module, _type, name):
@@ -829,7 +815,7 @@ def _check_exists(module, _type, name):
829815
nprinc = _normalize_principal_name(princ, realm)
830816
except ipalib_errors.ValidationError as err:
831817
module.fail_json(msg="%s: %s" % (_princ, str(err)))
832-
princ = unicode(nprinc)
818+
princ = str(nprinc)
833819

834820
# Check that host principal exists
835821
if princ.startswith("host/"):
@@ -908,20 +894,20 @@ def get_trusted_domain_sid_from_name(dom_name):
908894
"""
909895
Given a trust domain name, returns the domain SID.
910896
911-
Returns unicode string representation for a given trusted domain name
897+
Returns string representation for a given trusted domain name
912898
or None if SID for the given trusted domain name could not be found.
913899
"""
914900
domain_validator = __get_domain_validator()
915901
sid = domain_validator.get_sid_from_domain_name(dom_name)
916902

917-
return unicode(sid) if sid is not None else None
903+
return str(sid) if sid is not None else None
918904

919905

920906
def get_trusted_domain_object_sid(object_name):
921907
"""Given an object name, returns de object SID."""
922908
domain_validator = __get_domain_validator()
923909
sid = domain_validator.get_trusted_domain_object_sid(object_name)
924-
return unicode(sid) if sid is not None else None
910+
return str(sid) if sid is not None else None
925911

926912

927913
class IPAParamMapping(Mapping):

plugins/modules/ipacert.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -243,15 +243,10 @@
243243
import time
244244
import ssl
245245

246-
from ansible.module_utils import six
247-
from ansible.module_utils._text import to_text
248246
from ansible.module_utils.ansible_freeipa_module import (
249-
IPAAnsibleModule, certificate_loader, write_certificate_list,
247+
IPAAnsibleModule, certificate_loader, write_certificate_list, to_text,
250248
)
251249

252-
if six.PY3:
253-
unicode = str
254-
255250
# Reasons are defined in RFC 5280 sec. 5.3.1; removeFromCRL is not present in
256251
# this list; run the module with state=released instead.
257252
REVOCATION_REASONS = {

plugins/modules/ipadnsforwardzone.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,8 @@
131131
'''
132132

133133

134-
from ansible.module_utils._text import to_text
135134
from ansible.module_utils.ansible_freeipa_module import \
136-
IPAAnsibleModule, compare_args_ipa
135+
IPAAnsibleModule, compare_args_ipa, to_text
137136

138137

139138
def find_dnsforwardzone(module, name):

plugins/modules/ipadnsrecord.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -964,9 +964,8 @@
964964
"""
965965

966966

967-
from ansible.module_utils._text import to_text
968967
from ansible.module_utils.ansible_freeipa_module import \
969-
IPAAnsibleModule, is_ipv4_addr, is_ipv6_addr, ipalib_errors
968+
IPAAnsibleModule, is_ipv4_addr, is_ipv6_addr, ipalib_errors, to_text
970969
try:
971970
import dns.reversename
972971
import dns.resolver
@@ -975,10 +974,6 @@
975974
else:
976975
MODULE_IMPORT_ERROR = None
977976

978-
from ansible.module_utils import six
979-
980-
if six.PY3:
981-
unicode = str
982977

983978
_SUPPORTED_RECORD_TYPES = [
984979
"A", "AAAA", "A6", "AFSDB", "CERT", "CNAME", "DLV", "DNAME", "DS", "KX",

plugins/modules/ipadnszone.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -233,11 +233,6 @@
233233
DNSName,
234234
netaddr
235235
) # noqa: E402
236-
from ansible.module_utils import six
237-
238-
239-
if six.PY3:
240-
unicode = str
241236

242237

243238
class DNSZoneModule(IPAAnsibleModule):

plugins/modules/ipagroup.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -327,14 +327,10 @@
327327
RETURN = """
328328
"""
329329

330-
from ansible.module_utils._text import to_text
331330
from ansible.module_utils.ansible_freeipa_module import \
332331
IPAAnsibleModule, compare_args_ipa, gen_add_del_lists, \
333332
gen_add_list, gen_intersection_list, api_check_param, \
334-
convert_to_sid
335-
from ansible.module_utils import six
336-
if six.PY3:
337-
unicode = str
333+
convert_to_sid, to_text
338334
# Ensuring (adding) several groups with mixed types external, nonposix
339335
# and posix require to have a fix in IPA:
340336
# FreeIPA issue: https://pagure.io/freeipa/issue/9349
@@ -675,11 +671,7 @@ def main():
675671

676672
check_parameters(ansible_module, state, action)
677673

678-
elif (
679-
isinstance(
680-
group_name, (str, unicode) # pylint: disable=W0012,E0606
681-
)
682-
):
674+
elif isinstance(group_name, str):
683675
name = group_name
684676
else:
685677
ansible_module.fail_json(msg="Group '%s' is not valid" %

0 commit comments

Comments
 (0)