From beb6d74b81eae9965ddc031db1a3826c01d59d30 Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Thu, 4 Jan 2018 13:51:39 +0100 Subject: [PATCH] LGTM: unnecessary else in for loop for/else makes only sense when the for loop uses break, too. If the for loop simply returns on success, then else is not necessary. Signed-off-by: Christian Heimes Reviewed-By: Fraser Tweedale --- ipaclient/install/client.py | 15 +++++++-------- ipaserver/plugins/dns.py | 3 +-- ipaserver/plugins/permission.py | 13 +++++++------ ipatests/pytest_plugins/integration/env_config.py | 4 ++-- 4 files changed, 17 insertions(+), 18 deletions(-) diff --git a/ipaclient/install/client.py b/ipaclient/install/client.py index c565871b9..5173d90bf 100644 --- a/ipaclient/install/client.py +++ b/ipaclient/install/client.py @@ -1194,8 +1194,7 @@ def get_iface_from_ip(ip_addr): for ip in if_addrs.get(family, []): if ip['addr'] == ip_addr: return interface - else: - raise RuntimeError("IP %s not assigned to any interface." % ip_addr) + raise RuntimeError("IP %s not assigned to any interface." % ip_addr) def get_local_ipaddresses(iface=None): @@ -1390,6 +1389,7 @@ def verify_dns_update(fqdn, ips): def get_server_connection_interface(server): """Connect to IPA server, get all ip addresses of interface used to connect """ + last_error = None for res in socket.getaddrinfo( server, 389, socket.AF_UNSPEC, socket.SOCK_STREAM): af, socktype, proto, _canonname, sa = res @@ -1397,7 +1397,6 @@ def get_server_connection_interface(server): s = socket.socket(af, socktype, proto) except socket.error as e: last_error = e - s = None continue try: s.connect(sa) @@ -1413,11 +1412,11 @@ def get_server_connection_interface(server): return get_iface_from_ip(ip) except (CalledProcessError, RuntimeError) as e: last_error = e - else: - msg = "Cannot get server connection interface" - if last_error: - msg += ": %s" % (last_error) - raise RuntimeError(msg) + + msg = "Cannot get server connection interface" + if last_error: + msg += ": %s" % last_error + raise RuntimeError(msg) def client_dns(server, hostname, options): diff --git a/ipaserver/plugins/dns.py b/ipaserver/plugins/dns.py index 01bd689d6..e6a1f580e 100644 --- a/ipaserver/plugins/dns.py +++ b/ipaserver/plugins/dns.py @@ -3426,8 +3426,7 @@ class dnsrecord(LDAPObject): time.sleep(period) # Maximum number of attempts was reached - else: - raise errors.DNSDataMismatch(expected=ldap_rrset, got=dns_rrset) + raise errors.DNSDataMismatch(expected=ldap_rrset, got=dns_rrset) def wait_for_modified_attrs(self, entry_attrs, dns_name, dns_domain): '''Wait until DNS resolver returns up-to-date answer for given entry diff --git a/ipaserver/plugins/permission.py b/ipaserver/plugins/permission.py index 0a3873b40..30f8663c9 100644 --- a/ipaserver/plugins/permission.py +++ b/ipaserver/plugins/permission.py @@ -694,6 +694,7 @@ class permission(baseldap.LDAPObject): acientry = ldap.get_entry(location, ['aci']) except errors.NotFound: acientry = ldap.make_entry(location) + acis = acientry.get('aci', ()) for acistring in acis: try: @@ -704,12 +705,12 @@ class permission(baseldap.LDAPObject): continue if aci.name == wanted_aciname: return acientry, acistring - else: - if notfound_ok: - return acientry, None - raise errors.NotFound( - reason=_('The ACI for permission %(name)s was not found ' - 'in %(dn)s ') % {'name': name, 'dn': location}) + + if notfound_ok: + return acientry, None + raise errors.NotFound( + reason=_('The ACI for permission %(name)s was not found ' + 'in %(dn)s ') % {'name': name, 'dn': location}) def upgrade_permission(self, entry, target_entry=None, output_only=False, cached_acientry=None): diff --git a/ipatests/pytest_plugins/integration/env_config.py b/ipatests/pytest_plugins/integration/env_config.py index d140aa9df..1bf1dc7d0 100644 --- a/ipatests/pytest_plugins/integration/env_config.py +++ b/ipatests/pytest_plugins/integration/env_config.py @@ -251,8 +251,8 @@ def env_normalize(env): pass else: return - else: - env[name] = '' + env[name] = '' + coalesce('MASTER_env1', 'MASTER') coalesce('REPLICA_env1', 'REPLICA', 'SLAVE') coalesce('CLIENT_env1', 'CLIENT')