From b7e39ce7e93bcea496853e9761a8cdd6c8d537c8 Mon Sep 17 00:00:00 2001 From: Rafael Guterres Jeffman Date: Wed, 9 Nov 2022 22:35:25 -0300 Subject: [PATCH 1/4] linters: Fix versions of linter packages due to Python 3.11. Under Python 3.11 some linters have failed to execute due to deprecated items. Increasing or setting specific allow the linters to succeed with Python's lates version. --- .github/workflows/lint.yml | 2 +- requirements-dev.txt | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 748bfcd3..5cc1b8a7 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -68,7 +68,7 @@ jobs: python-version: "3.x" - name: Run pylint run: | - pip install pylint==2.12.2 + pip install pylint==2.13.7 wrapt==1.14.0 pylint plugins roles --disable=import-error shellcheck: diff --git a/requirements-dev.txt b/requirements-dev.txt index f224861f..0915965a 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -2,11 +2,9 @@ ipdb==0.13.4 pre-commit flake8==4.0.1 -flake8-bugbear +flake8-bugbear==22.10.27 pylint==2.13.7 +wrapt >= 1.14.0 pydocstyle==6.0.0 yamllint==1.26.3 ansible-lint==5.3.2 -dnspython==2.2.0 -netaddr==0.8.0 -gssapi==1.7.2 From 10b3f4610c7ef813cd8cebd8657ae7c4d866ee75 Mon Sep 17 00:00:00 2001 From: Rafael Guterres Jeffman Date: Wed, 9 Nov 2022 23:20:35 -0300 Subject: [PATCH 2/4] pylint: Modify certificate loader function definition. This patch modifies the way that the certificate load function is defined, depending on the dependency version, so that the resulting identifier for the function is always set and static analysis tools, like linters don't complain about variables being used before being set. The same idiom is applied to both the ipaclient role and the plugins ansible_module_utils. --- plugins/module_utils/ansible_freeipa_module.py | 9 +++------ roles/ipaserver/module_utils/ansible_ipa_server.py | 8 +++----- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/plugins/module_utils/ansible_freeipa_module.py b/plugins/module_utils/ansible_freeipa_module.py index d92dbc9a..247f6e74 100644 --- a/plugins/module_utils/ansible_freeipa_module.py +++ b/plugins/module_utils/ansible_freeipa_module.py @@ -99,9 +99,10 @@ try: try: from ipalib.x509 import load_pem_x509_certificate + certificate_loader = load_pem_x509_certificate except ImportError: from ipalib.x509 import load_certificate - load_pem_x509_certificate = None + certificate_loader = load_certificate # Try to import is_ipa_configured or use a fallback implementation. try: @@ -147,7 +148,6 @@ except ImportError as _err: uuid = None netaddr = None is_ipa_configured = None - load_certificate = None kerberos = None ipaserver = None # pylint: disable=C0103 else: @@ -588,10 +588,7 @@ def load_cert_from_str(cert): if not cert.endswith("-----END CERTIFICATE-----"): cert += "\n-----END CERTIFICATE-----" - if load_pem_x509_certificate is not None: - cert = load_pem_x509_certificate(cert.encode('utf-8')) - else: - cert = load_certificate(cert.encode('utf-8')) + cert = certificate_loader(cert.encode('utf-8')) return cert diff --git a/roles/ipaserver/module_utils/ansible_ipa_server.py b/roles/ipaserver/module_utils/ansible_ipa_server.py index 8e7be0b0..f1f4972b 100644 --- a/roles/ipaserver/module_utils/ansible_ipa_server.py +++ b/roles/ipaserver/module_utils/ansible_ipa_server.py @@ -196,9 +196,10 @@ else: try: from ipalib.x509 import load_pem_x509_certificate + certificate_loader = load_pem_x509_certificate except ImportError: from ipalib.x509 import load_certificate - load_pem_x509_certificate = None + certificate_loader = load_certificate try: from ipaserver.install.server.install import get_min_idstart @@ -426,10 +427,7 @@ else: if not cert.endswith("-----END CERTIFICATE-----"): cert += "\n-----END CERTIFICATE-----" - if load_pem_x509_certificate is not None: - cert = load_pem_x509_certificate(cert.encode('utf-8')) - else: - cert = load_certificate(cert.encode('utf-8')) + cert = certificate_loader(cert.encode('utf-8')) else: cert = base64.b64decode(cert) return cert From 9b6fd8cce00ace5e3b4c618b11dd22d0edd71002 Mon Sep 17 00:00:00 2001 From: Rafael Guterres Jeffman Date: Wed, 9 Nov 2022 23:27:34 -0300 Subject: [PATCH 3/4] pylint: Update configuration for Python 3.11 Update pylint configuration on setup.cfg to cope with recent changes in Python 3.11. --- setup.cfg | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/setup.cfg b/setup.cfg index 10edc502..a199be56 100644 --- a/setup.cfg +++ b/setup.cfg @@ -59,12 +59,18 @@ disable = [pylint.BASIC] good-names = - ex, i, j, k, Run, _, e, x, dn, cn, ip, os, unicode, __metaclass__, ds + ex, i, j, k, Run, _, e, x, dn, cn, ip, os, unicode, __metaclass__, ds, + # These are utils tools, and not part of the released collection. + galaxyfy-playbook, galaxyfy-README, galaxyfy-module-EXAMPLES, + module_EXAMPLES + [pylint.IMPORTS] ignored-modules = ansible.errors, ansible.plugins.action, ansible.module_utils, ansible.module_utils.ansible_freeipa_module, + dns, + gssapi, ipalib, ipalib.config, ipalib.constants, ipalib.krb_utils, ipalib.errors, ipapython.ipautil, ipapython.dn, ipapython.version, ipapython.dnsutil, ipapython.ipa_log_manager, ipapython, @@ -72,7 +78,10 @@ ignored-modules = ipaserver.install.installutils, ipaserver.install.server.install, ipaserver.install, ipaclient.install.ipachangeconf, ipaclient.install.client, - ipaserver.dcerpc + ipaserver.dcerpc, + jinja2, + os, + SSSDConfig [pylint.REFACTORING] max-nested-blocks = 9 From 29dccf3d8ac29db9d5082dac31e169303acaf0af Mon Sep 17 00:00:00 2001 From: Rafael Guterres Jeffman Date: Wed, 9 Nov 2022 23:31:38 -0300 Subject: [PATCH 4/4] pylint: Fix pylint issues on utils/galaxyfy-module-EXAMPLES.py --- utils/galaxyfy-module-EXAMPLES.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/galaxyfy-module-EXAMPLES.py b/utils/galaxyfy-module-EXAMPLES.py index 31da3bb3..46a740be 100644 --- a/utils/galaxyfy-module-EXAMPLES.py +++ b/utils/galaxyfy-module-EXAMPLES.py @@ -37,7 +37,7 @@ def module_EXAMPLES(module_in, project_prefix, collection_prefix): example = True out_lines.append(line) continue - elif example and stripped in ["'''", '"""']: + if example and stripped in ["'''", '"""']: _out_lines, _changed = \ galaxyfy_playbook(project_prefix, collection_prefix, example_lines)