logging: do not reference loggers in arguments and attributes

Remove logger arguments in all functions and logger attributes in all
objects, with the exception of API object logger, which is now deprecated.
Replace affected logger calls with module-level logger calls.

Reviewed-By: Martin Basti <mbasti@redhat.com>
This commit is contained in:
Jan Cholasta
2017-07-14 15:55:59 +02:00
committed by Martin Basti
parent bccb243b05
commit ab9d1e75fc
23 changed files with 325 additions and 265 deletions
+23 -21
View File
@@ -23,6 +23,7 @@
This script creates or removes the symlink from /etc/ipa/ipa-kdc-proxy.conf
to /etc/httpd/conf.d/. It's called from ExecStartPre hook in httpd.service.
"""
import logging
import os
import socket
import sys
@@ -33,6 +34,8 @@ from ipapython.ipaldap import LDAPClient
from ipapython.dn import DN
from ipaplatform.paths import paths
logger = logging.getLogger(os.path.basename(__file__))
DEBUG = False
TIME_LIMIT = 2
@@ -66,7 +69,6 @@ class KDCProxyConfig(object):
def __init__(self, time_limit=TIME_LIMIT):
self.time_limit = time_limit
self.con = None
self.log = api.log
self.ldap_uri = api.env.ldap_uri
self.kdc_dn = DN(('cn', 'KDC'), ('cn', api.env.host),
('cn', 'masters'), ('cn', 'ipa'), ('cn', 'etc'),
@@ -76,7 +78,7 @@ class KDCProxyConfig(object):
def _ldap_con(self):
"""Establish LDAP connection"""
self.log.debug('ldap_uri: %s', self.ldap_uri)
logger.debug('ldap_uri: %s', self.ldap_uri)
try:
self.con = LDAPClient(self.ldap_uri)
self.con.external_bind()
@@ -89,7 +91,7 @@ class KDCProxyConfig(object):
except Exception as e:
msg = ('Unknown error while retrieving setting from %s: %s' %
(self.ldap_uri, e))
self.log.exception(msg)
logger.exception('%s', msg)
raise FatalError(msg)
def _find_entry(self, dn, attrs, filter, scope=LDAPClient.SCOPE_BASE):
@@ -98,23 +100,23 @@ class KDCProxyConfig(object):
entries = self.con.get_entries(
dn, scope, filter, attrs, time_limit=self.time_limit)
except errors.NotFound:
self.log.debug('Entry not found: %s', dn)
logger.debug('Entry not found: %s', dn)
return None
except Exception as e:
msg = ('Unknown error while retrieving setting from %s: %s' %
(self.ldap_uri, e))
self.log.exception(msg)
logger.exception('%s', msg)
raise FatalError(msg)
return entries[0]
def is_host_enabled(self):
"""Check replica specific flag"""
self.log.debug('Read settings from dn: %s', self.kdc_dn)
logger.debug('Read settings from dn: %s', self.kdc_dn)
srcfilter = self.con.make_filter(
{'ipaConfigString': u'kdcProxyEnabled'}
)
entry = self._find_entry(self.kdc_dn, ['cn'], srcfilter)
self.log.debug('%s ipaConfigString: %s', self.kdc_dn, entry)
logger.debug('%s ipaConfigString: %s', self.kdc_dn, entry)
return entry is not None
def validate_symlink(self):
@@ -137,20 +139,20 @@ class KDCProxyConfig(object):
try:
valid = self.validate_symlink()
except ConfigFileError as e:
self.log.warning("Cannot enable KDC proxy: %s " % e)
logger.warning("Cannot enable KDC proxy: %s ", e)
return False
if valid:
self.log.debug("Symlink exists and is valid")
logger.debug("Symlink exists and is valid")
return True
if not os.path.isfile(self.conf):
self.log.warning("'%s' does not exist", self.conf)
logger.warning("'%s' does not exist", self.conf)
return False
# create the symbolic link
self.log.debug("Creating symlink from '%s' to '%s'",
self.conf, self.conflink)
logger.debug("Creating symlink from '%s' to '%s'",
self.conf, self.conflink)
os.symlink(self.conf, self.conflink)
return True
@@ -159,15 +161,15 @@ class KDCProxyConfig(object):
try:
valid = self.validate_symlink()
except CheckError as e:
self.log.warning("Cannot disable KDC proxy: %s " % e)
logger.warning("Cannot disable KDC proxy: %s ", e)
return False
if valid:
self.log.debug("Removing symlink '%s'", self.conflink)
logger.debug("Removing symlink '%s'", self.conflink)
os.unlink(self.conflink)
else:
self.log.debug("Symlink '%s' has already been removed.",
self.conflink)
logger.debug("Symlink '%s' has already been removed.",
self.conflink)
return True
@@ -193,19 +195,19 @@ def main(debug=DEBUG, time_limit=TIME_LIMIT):
with cfg:
if cfg.is_host_enabled():
if cfg.create_symlink():
api.log.info('KDC proxy enabled')
logger.info('KDC proxy enabled')
return 0
else:
if cfg.remove_symlink():
api.log.info('KDC proxy disabled')
logger.info('KDC proxy disabled')
return 0
except CheckError as e:
api.log.warning(str(e))
api.log.warning('Disabling KDC proxy')
logger.warning('%s', str(e))
logger.warning('Disabling KDC proxy')
cfg.remove_symlink()
return 0
except Exception as e:
api.log.error(str(e))
logger.error('%s', str(e))
return 1