LGTM: Fix multiple use before assignment

- Move assignment before try/finally block
- Add raise to indicate control flow change
- Add default value

https://pagure.io/freeipa/issue/7344

Signed-off-by: Christian Heimes <cheimes@redhat.com>
Reviewed-By: Fraser Tweedale <ftweedal@redhat.com>
This commit is contained in:
Christian Heimes
2018-01-03 11:09:41 +01:00
parent dc599e0797
commit 73ee9ff40e
9 changed files with 45 additions and 25 deletions

View File

@@ -1275,9 +1275,11 @@ def update_dns(server, hostname, options):
ips = get_local_ipaddresses()
except CalledProcessError as e:
logger.error("Cannot update DNS records. %s", e)
logger.debug("Unable to get local IP addresses.")
ips = None
if options.all_ip_addresses:
if ips is None:
raise RuntimeError("Unable to get local IP addresses.")
update_ips = ips
elif options.ip_addresses:
update_ips = []
@@ -1777,8 +1779,8 @@ def get_ca_certs(fstore, options, server, basedn, realm):
override)
else:
# Auth with user credentials
url = ldap_url()
try:
url = ldap_url()
ca_certs = get_ca_certs_from_ldap(server, basedn, realm)
validate_new_ca_certs(existing_ca_certs, ca_certs, interactive)
except errors.FileError as e:
@@ -1821,7 +1823,7 @@ def get_ca_certs(fstore, options, server, basedn, realm):
if ca_certs is None and existing_ca_certs is None:
raise errors.InternalError(u"expected CA cert file '%s' to "
u"exist, but it's absent" % (ca_file))
u"exist, but it's absent" % ca_file)
if ca_certs is not None:
try:
@@ -2427,9 +2429,10 @@ def _install(options):
if not options.on_master:
nolog = tuple()
# First test out the kerberos configuration
fd, krb_name = tempfile.mkstemp()
os.close(fd)
ccache_dir = tempfile.mkdtemp(prefix='krbcc')
try:
(krb_fd, krb_name) = tempfile.mkstemp()
os.close(krb_fd)
configure_krb5_conf(
cli_realm=cli_realm,
cli_domain=cli_domain,
@@ -2442,7 +2445,6 @@ def _install(options):
configure_sssd=options.sssd,
force=options.force)
env['KRB5_CONFIG'] = krb_name
ccache_dir = tempfile.mkdtemp(prefix='krbcc')
ccache_name = os.path.join(ccache_dir, 'ccache')
join_args = [paths.SBIN_IPA_JOIN,
"-s", cli_server[0],
@@ -2799,7 +2801,7 @@ def _install(options):
nscd = services.knownservices.nscd
if nscd.is_installed():
save_state(nscd, statestore)
nscd_service_action = None
try:
if options.sssd:
nscd_service_action = 'stop'