From de9d8b50cf1f4f64ec6c157e4b1cde77e24487de Mon Sep 17 00:00:00 2001
From: Thomas Woerner <twoerner@redhat.com>
Date: Wed, 17 Jul 2019 18:54:20 +0200
Subject: [PATCH] ipa[server,replica,client]: pylint fixes

---
 .../ipaclient/action_plugins/ipaclient_get_otp.py  |  2 +-
 roles/ipaclient/library/ipaclient_api.py           |  4 ++--
 roles/ipaclient/library/ipaclient_get_facts.py     |  3 ++-
 roles/ipaclient/library/ipaclient_get_otp.py       |  2 +-
 roles/ipaclient/library/ipaclient_join.py          |  2 +-
 roles/ipaclient/library/ipaclient_set_hostname.py  |  1 +
 roles/ipaclient/library/ipaclient_setup_ntp.py     |  3 ++-
 roles/ipaclient/library/ipaclient_test.py          |  5 +++--
 roles/ipaclient/library/ipaclient_test_keytab.py   |  4 ++--
 .../library/ipareplica_ds_apply_updates.py         |  2 +-
 roles/ipaserver/library/ipaserver_enable_ipa.py    |  2 +-
 roles/ipaserver/library/ipaserver_load_cache.py    |  4 ++--
 roles/ipaserver/library/ipaserver_setup_ds.py      |  4 ++--
 roles/ipaserver/library/ipaserver_test.py          | 14 +++++++-------
 14 files changed, 28 insertions(+), 24 deletions(-)

diff --git a/roles/ipaclient/action_plugins/ipaclient_get_otp.py b/roles/ipaclient/action_plugins/ipaclient_get_otp.py
index 9850f72f..f6deebc9 100644
--- a/roles/ipaclient/action_plugins/ipaclient_get_otp.py
+++ b/roles/ipaclient/action_plugins/ipaclient_get_otp.py
@@ -45,7 +45,7 @@ def run_cmd(args, stdin=None):
 
     p = subprocess.Popen(args, stdin=p_in, stdout=p_out, stderr=p_err,
                          close_fds=True)
-    stdout, stderr = p.communicate(stdin)
+    __temp, stderr = p.communicate(stdin)
 
     if p.returncode != 0:
         raise RuntimeError(stderr)
diff --git a/roles/ipaclient/library/ipaclient_api.py b/roles/ipaclient/library/ipaclient_api.py
index 284bbb41..aa80d6d4 100644
--- a/roles/ipaclient/library/ipaclient_api.py
+++ b/roles/ipaclient/library/ipaclient_api.py
@@ -97,9 +97,9 @@ def main():
 
     host_principal = 'host/%s@%s' % (hostname, realm)
     os.environ['KRB5CCNAME'] = paths.IPA_DNS_CCACHE
-    
+
     ca_certs = x509.load_certificate_list_from_file(paths.IPA_CA_CRT)
-    if NUM_VERSION >= 40500 and NUM_VERSION < 40590:
+    if 40500 <= NUM_VERSION < 40590:
         ca_certs = [ cert.public_bytes(serialization.Encoding.DER)
                      for cert in ca_certs ]
     elif NUM_VERSION < 40500:
diff --git a/roles/ipaclient/library/ipaclient_get_facts.py b/roles/ipaclient/library/ipaclient_get_facts.py
index 8a70257e..7ae7ffa7 100644
--- a/roles/ipaclient/library/ipaclient_get_facts.py
+++ b/roles/ipaclient/library/ipaclient_get_facts.py
@@ -8,6 +8,7 @@ from six.moves.configparser import RawConfigParser
 
 from ansible.module_utils.basic import AnsibleModule
 
+# pylint: disable=unused-import
 try:
     from ipalib import api
 except ImportError:
@@ -126,7 +127,7 @@ def get_ipa_version():
             version=version.VERSION,
             version_info=version_info
             )
-        
+
 def main():
     module = AnsibleModule(
         argument_spec = dict(),
diff --git a/roles/ipaclient/library/ipaclient_get_otp.py b/roles/ipaclient/library/ipaclient_get_otp.py
index b6463c15..4014d234 100644
--- a/roles/ipaclient/library/ipaclient_get_otp.py
+++ b/roles/ipaclient/library/ipaclient_get_otp.py
@@ -327,7 +327,7 @@ def main():
         except errors.NotFound:
             host = None
 
-        if state == 'present' or state == 'disabled':
+        if state in ['present','disabled']:
             changed = ensure_host_present(module, api, host)
         elif state == 'absent':
             changed = ensure_host_absent(module, api, host)
diff --git a/roles/ipaclient/library/ipaclient_join.py b/roles/ipaclient/library/ipaclient_join.py
index 3a2cbc3f..838852d4 100644
--- a/roles/ipaclient/library/ipaclient_join.py
+++ b/roles/ipaclient/library/ipaclient_join.py
@@ -137,7 +137,7 @@ def main():
             realm=dict(required=True),
             hostname=dict(required=True),
             kdc=dict(required=True),
-            basedn=dict(required=True),            
+            basedn=dict(required=True),
             principal=dict(required=False),
             password=dict(required=False, no_log=True),
             keytab=dict(required=False),
diff --git a/roles/ipaclient/library/ipaclient_set_hostname.py b/roles/ipaclient/library/ipaclient_set_hostname.py
index aed2df59..2e5f6d30 100644
--- a/roles/ipaclient/library/ipaclient_set_hostname.py
+++ b/roles/ipaclient/library/ipaclient_set_hostname.py
@@ -77,5 +77,6 @@ def main():
 
     module.exit_json(changed=True)
 
+
 if __name__ == '__main__':
     main()
diff --git a/roles/ipaclient/library/ipaclient_setup_ntp.py b/roles/ipaclient/library/ipaclient_setup_ntp.py
index c2b0425d..645b8f1c 100644
--- a/roles/ipaclient/library/ipaclient_setup_ntp.py
+++ b/roles/ipaclient/library/ipaclient_setup_ntp.py
@@ -139,7 +139,7 @@ def main():
             logger.info("Skipping chrony configuration")
 
     else:
-        ntp_srv_servers = [ ]
+        ntp_srv_servers = []
         if not options.on_master and options.conf_ntp:
             # Attempt to sync time with IPA server.
             # If we're skipping NTP configuration, we also skip the time sync here.
@@ -176,5 +176,6 @@ def main():
     # Done
     module.exit_json(changed=synced_ntp)
 
+
 if __name__ == '__main__':
     main()
diff --git a/roles/ipaclient/library/ipaclient_test.py b/roles/ipaclient/library/ipaclient_test.py
index abacbd90..445b7518 100644
--- a/roles/ipaclient/library/ipaclient_test.py
+++ b/roles/ipaclient/library/ipaclient_test.py
@@ -461,7 +461,7 @@ def main():
         ### client.install_check ###
 
         logger.info("This program will set up FreeIPA client.")
-        logger.info("Version {}".format(version.VERSION))
+        logger.info("Version %s", version.VERSION)
         logger.info("")
 
         cli_domain_source = 'Unknown source'
@@ -494,7 +494,7 @@ def main():
             except timeconf.NTPConflictingService as e:
                 logger.info(
                     "WARNING: conflicting time&date synchronization service "
-                    "'%s' will be disabled in favor of chronyd" % \
+                    "'%s' will be disabled in favor of chronyd",
                     e.conflicting_service)
                 logger.info("")
             except timeconf.NTPConfigurationError:
@@ -563,6 +563,7 @@ def main():
                     rval=CLIENT_INSTALL_ERROR)
 
             (nssldap_installed, nosssd_files) = nssldap_exists()
+            (nssldap_installed, __temp) = nssldap_exists()
             if not nssldap_installed:
                 raise ScriptError(
                     "One of these packages must be installed: nss_ldap or "
diff --git a/roles/ipaclient/library/ipaclient_test_keytab.py b/roles/ipaclient/library/ipaclient_test_keytab.py
index 9b5b64e5..6d557014 100644
--- a/roles/ipaclient/library/ipaclient_test_keytab.py
+++ b/roles/ipaclient/library/ipaclient_test_keytab.py
@@ -159,7 +159,7 @@ def main():
                 ping_test_ok = True
         except OSError:
             pass
-    except GSSError as e:
+    except GSSError:
         pass
 
     # Second try: Validate krb5 keytab with temporary krb5
@@ -197,7 +197,7 @@ def main():
               except OSError:
                   pass
 
-          except GSSError as e:
+          except GSSError:
               pass
 
       finally:
diff --git a/roles/ipareplica/library/ipareplica_ds_apply_updates.py b/roles/ipareplica/library/ipareplica_ds_apply_updates.py
index 5c1b08ca..f0ab776f 100644
--- a/roles/ipareplica/library/ipareplica_ds_apply_updates.py
+++ b/roles/ipareplica/library/ipareplica_ds_apply_updates.py
@@ -123,7 +123,7 @@ def main():
     ccache = os.environ['KRB5CCNAME']
 
     # There is a api.Backend.ldap2.connect call somewhere in ca, ds, dns or
-    # ntpinstance 
+    # ntpinstance
     api.Backend.ldap2.connect()
     conn.connect(ccache=ccache)
 
diff --git a/roles/ipaserver/library/ipaserver_enable_ipa.py b/roles/ipaserver/library/ipaserver_enable_ipa.py
index 1267d704..38a77d8c 100644
--- a/roles/ipaserver/library/ipaserver_enable_ipa.py
+++ b/roles/ipaserver/library/ipaserver_enable_ipa.py
@@ -88,7 +88,7 @@ def main():
 
     fstore = sysrestore.FileStore(paths.SYSRESTORE)
 
-    if NUM_VERSION < 40600:
+    if hasattr(tasks, "configure_tmpfiles"):
         # Make sure the files we crated in /var/run are recreated at startup
         tasks.configure_tmpfiles()
 
diff --git a/roles/ipaserver/library/ipaserver_load_cache.py b/roles/ipaserver/library/ipaserver_load_cache.py
index 28b23477..883cdf12 100644
--- a/roles/ipaserver/library/ipaserver_load_cache.py
+++ b/roles/ipaserver/library/ipaserver_load_cache.py
@@ -71,7 +71,7 @@ def main():
         if options.dm_password is None:
             ansible_module.fail_json(msg="Directory Manager password required")
         try:
-            cache_vars = read_cache(dm_password)
+            cache_vars = read_cache(options.dm_password)
             options.__dict__.update(cache_vars)
             if cache_vars.get('external_ca', False):
                 options.external_ca = False
@@ -83,7 +83,7 @@ def main():
         kwargs = { "changed": True }
         for name in options.__dict__:
             kwargs[name] = options.__dict__[name]
-        ansible_module.exit_json(kwargs)
+        ansible_module.exit_json(**kwargs)
 
     # done ##################################################################
 
diff --git a/roles/ipaserver/library/ipaserver_setup_ds.py b/roles/ipaserver/library/ipaserver_setup_ds.py
index f4aa9cba..6663d19f 100644
--- a/roles/ipaserver/library/ipaserver_setup_ds.py
+++ b/roles/ipaserver/library/ipaserver_setup_ds.py
@@ -127,7 +127,7 @@ def main():
     # Make sure tmpfiles dir exist before installing components
     if NUM_VERSION == 40504:
         tasks.create_tmpfiles_dirs(IPAAPI_USER)
-    elif NUM_VERSION >= 40500 and NUM_VERSION <= 40503:
+    elif 40500 <= NUM_VERSION <= 40503:
         tasks.create_tmpfiles_dirs()
 
     # Create a directory server instance
@@ -138,7 +138,7 @@ def main():
         ds.set_output(ansible_log)
 
         if options.dirsrv_cert_files:
-            _dirsrv_pkcs12_info=options.dirsrv_pkcs12_info
+            _dirsrv_pkcs12_info=options._dirsrv_pkcs12_info
         else:
             _dirsrv_pkcs12_info=None
 
diff --git a/roles/ipaserver/library/ipaserver_test.py b/roles/ipaserver/library/ipaserver_test.py
index 40805061..88b5db74 100644
--- a/roles/ipaserver/library/ipaserver_test.py
+++ b/roles/ipaserver/library/ipaserver_test.py
@@ -158,12 +158,12 @@ def main():
     options.dirsrv_cert_files = ansible_module.params.get('dirsrv_cert_files')
     options.http_cert_files = ansible_module.params.get('http_cert_files')
     options.pkinit_cert_files = ansible_module.params.get('pkinit_cert_files')
-    options.dirsrv_pin = ansible_module.params.get('dirsrv_pin'),
-    options.http_pin = ansible_module.params.get('http_pin'),
-    options.pkinit_pin = ansible_module.params.get('pkinit_pin'),
-    options.dirsrv_cert_name = ansible_module.params.get('dirsrv_cert_name'),
-    options.http_cert_name = ansible_module.params.get('http_cert_name'),
-    options.pkinit_cert_name = ansible_module.params.get('pkinit_cert_name'),
+    options.dirsrv_pin = ansible_module.params.get('dirsrv_pin')
+    options.http_pin = ansible_module.params.get('http_pin')
+    options.pkinit_pin = ansible_module.params.get('pkinit_pin')
+    options.dirsrv_cert_name = ansible_module.params.get('dirsrv_cert_name')
+    options.http_cert_name = ansible_module.params.get('http_cert_name')
+    options.pkinit_cert_name = ansible_module.params.get('pkinit_cert_name')
     ### client ###
     # mkhomedir
     options.ntp_servers = ansible_module.params.get('ntp_servers')
@@ -562,7 +562,7 @@ def main():
         try:
             check_zone_overlap(options.domain_name, False)
         except ValueError as e:
-            ansible_module.fail_json(str(e))
+            ansible_module.fail_json(msg=str(e))
 
     # dm_password
     with redirect_stdout(ansible_log):
-- 
GitLab