Skip to content

Commit e1a7615

Browse files
committed
Manually merge PR94 to address PR77 regression in auth.log init in the simplest possible way. Adds a new disable_auth_log argument and corresponding docs to let unit tests disable auth.log init while preserving it for all real sites.
git-svn-id: svn+ssh://svn.code.sf.net/p/migrid/code/trunk@6103 b75ad72c-e7d7-11dd-a971-7dbc132099af
1 parent 74c5ac6 commit e1a7615

File tree

3 files changed

+27
-19
lines changed

3 files changed

+27
-19
lines changed

mig/shared/conf.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# --- BEGIN_HEADER ---
55
#
66
# conf - Server configuration handling
7-
# Copyright (C) 2003-2017 The MiG Project lead by Brian Vinter
7+
# Copyright (C) 2003-2024 The MiG Project lead by Brian Vinter
88
#
99
# This file is part of MiG.
1010
#
@@ -26,6 +26,7 @@
2626
#
2727

2828
"""Configuration functions"""
29+
2930
from __future__ import absolute_import
3031

3132
import os
@@ -34,9 +35,11 @@
3435
from mig.shared.fileio import unpickle
3536

3637

37-
def get_configuration_object(config_file=None, skip_log=False):
38+
def get_configuration_object(config_file=None, skip_log=False,
39+
disable_auth_log=False):
3840
"""Simple helper to call the general configuration init. Optional skip_log
39-
argument is passed on to allow skipping the default log initialization.
41+
and disable_auth_log arguments are passed on to allow skipping the default
42+
log initialization and disabling auth log for unit tests.
4043
"""
4144
from mig.shared.configuration import Configuration
4245
if config_file:
@@ -50,7 +53,8 @@ def get_configuration_object(config_file=None, skip_log=False):
5053
else:
5154
_config_file = os.path.join(app_dir, '..', 'server',
5255
'MiGserver.conf')
53-
configuration = Configuration(_config_file, False, skip_log)
56+
configuration = Configuration(_config_file, False, skip_log,
57+
disable_auth_log)
5458
return configuration
5559

5660

mig/shared/configuration.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -685,15 +685,21 @@ class Configuration:
685685

686686
# constructor
687687

688-
def __init__(self, config_file, verbose=False, skip_log=False):
688+
def __init__(self, config_file, verbose=False, skip_log=False,
689+
disable_auth_log=False):
689690
self.config_file = config_file
690-
self.reload_config(verbose, skip_log)
691-
692-
def reload_config(self, verbose, skip_log=False):
693-
"""Re-read and parse configuration file. Optional skip_log
694-
initializes default logger to use the NullHandler in order to avoid
695-
uninitialized log while not really touching log files or causing stdio
696-
output.
691+
self.reload_config(verbose, skip_log, disable_auth_log)
692+
693+
def reload_config(self, verbose, skip_log=False, disable_auth_log=False):
694+
"""Re-read and parse configuration file. Optional skip_log arg
695+
initializes default logger(s) to use the NullHandler in order to
696+
avoid uninitialized log while not really touching log files or causing
697+
stdio output. It is mainly used to disable logging to mig.log from
698+
grid_X daemons, which already set up their own per-daemon log for the
699+
purpose.
700+
The optional disable_auth_log is a workaround ONLY to be used inside a
701+
few unit tests where auth.log is really only in the way. It should
702+
NEVER be set in code used for production.
697703
"""
698704

699705
try:
@@ -2486,17 +2492,14 @@ def reload_config(self, verbose, skip_log=False):
24862492

24872493
# Init auth logger
24882494

2489-
auth_logger_logfile = None
2490-
if skip_log:
2491-
auth_logger_logfile = None
2492-
else:
2493-
auth_logger_logfile = self.user_auth_log
2495+
if disable_auth_log:
2496+
self.user_auth_log = None
24942497

24952498
if self.auth_logger_obj:
24962499
self.auth_logger_obj.reopen()
24972500
else:
24982501
self.auth_logger_obj = Logger(
2499-
self.loglevel, logfile=auth_logger_logfile, app='main-auth')
2502+
self.loglevel, logfile=self.user_auth_log, app='main-auth')
25002503
self.auth_logger = self.auth_logger_obj.logger
25012504

25022505
# cert and key for generating a default proxy for nordugrid/ARC

mig/unittest/testcore.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ def main(_exit=sys.exit):
7878
config_global_values = _assert_local_config_global_values(config)
7979

8080
from mig.shared.conf import get_configuration_object
81-
configuration = get_configuration_object(_TEST_CONF_FILE, skip_log=True)
81+
configuration = get_configuration_object(_TEST_CONF_FILE, skip_log=True,
82+
disable_auth_log=True)
8283
logging.basicConfig(filename=None, level=logging.INFO,
8384
format="%(asctime)s %(levelname)s %(message)s")
8485
configuration.logger = logging

0 commit comments

Comments
 (0)