Skip to content

Commit

Permalink
Some more tests, try to improve Python 2.6 tests and try to fix #1007
Browse files Browse the repository at this point in the history
  • Loading branch information
mohierf committed Mar 24, 2018
1 parent f022389 commit 5691386
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 21 deletions.
5 changes: 3 additions & 2 deletions alignak/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -1018,9 +1018,10 @@ def do_main_loop(self): # pylint: disable=too-many-branches, too-many-statement
self.do_loop_turn()
statsmgr.timer('loop-turn', time.time() - _ts)
else:
logger.info("+++ loop %d, did not yet received my configuration", self.loop_count)
logger.info("+++ loop %d, I do not have a configuration", self.loop_count)

# Daemon load
# TODO this measurement needs to be made reliable (check and adapt if needed)
self.load_1_min.update_load(self.maximum_loop_duration - elapsed_time)
statsmgr.gauge('load_1_min', self.load_1_min.get_load())
if self.log_loop:
Expand Down Expand Up @@ -1072,7 +1073,7 @@ def do_main_loop(self): # pylint: disable=too-many-branches, too-many-statement

pause = self.maximum_loop_duration - loop_duration
if loop_duration > self.maximum_loop_duration:
logger.warning("The %s %s loop exceeded the maximum expected loop duration: %.2f. "
logger.warning("The %s %s loop exceeded the maximum expected loop duration (%.2f). "
"The last loop needed %.2f seconds to execute. "
"You should try to reduce the load on this %s.",
self.type, self.name, self.maximum_loop_duration,
Expand Down
5 changes: 4 additions & 1 deletion alignak/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ def setup_logger(logger_configuration_file, log_dir=None, process_name='', log_f
If a log file name is provide, it will override the default defined log file name.
At first, this function checks if the logger is still existing and initialized to
update the handlers and formatters. This mainly happens during the unit tests.
:param logger_configuration_file: Python Json logger configuration file
:rtype logger_configuration_file: str
:param log_dir: default log directory to update the defined logging handlers
Expand All @@ -141,7 +144,7 @@ def setup_logger(logger_configuration_file, log_dir=None, process_name='', log_f
logger_ = logging.getLogger(ALIGNAK_LOGGER_NAME)
for handler in logger_.handlers:
if getattr(handler, '_name', None) == 'daemons':
# Already configured... exit
# Already configured...
# Update the declared formats with the process name
for hdlr in logger_.handlers:
if process_name and 'alignak_tests' in hdlr.formatter._fmt:
Expand Down
10 changes: 0 additions & 10 deletions test/alignak_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,6 @@ def setUp(self):
self.logger_ = logging.getLogger(ALIGNAK_LOGGER_NAME)
self.logger_.info("Test: %s", self.id())

# # Only for Python < 2.7, DEBUG logs ...
# print("OS version: %s" % os.sys.version_info)
# if os.sys.version_info < (2, 7):
# print("-> add a logger handler for Python 2.6")
# # Add collector for test purpose.
# collector_h = CollectorHandler()
# collector_h.setFormatter(Formatter('[%(created)i] %(levelname)s: [%(name)s] %(message)s'))
# collector_h.setLevel(logging.DEBUG)
# logger_.addHandler(collector_h)
#
# To make sure that no running daemon exist
print("Checking Alignak running daemons...")
for daemon in ['broker', 'poller', 'reactionner', 'receiver', 'scheduler', 'arbiter']:
Expand Down
25 changes: 17 additions & 8 deletions test/cfg/default_with_modules/alignak-logger.json
Original file line number Diff line number Diff line change
@@ -1,33 +1,42 @@
{
"version": 1,
"disable_existing_loggers": false,
"disable_existing_loggers": true,
"formatters": {
"unit_tests": {
"format": "[%(asctime)s] %(levelname)s: [%(daemon)s.%(name)s] %(message)s"
,"datefmt": "%Y-%m-%d %H:%M:%S"
},
"alignak": {
"format": "[%(asctime)s] %(levelname)s: [%(daemon)s.%(name)s] %(message)s"
,"datefmt": "%Y-%m-%d %H:%M:%S"
,"datefmt": "%Y-%m-%d %H:%M:%S"
},
"monitoring-log": {
"format": "[%(asctime)s] %(levelname)s: %(message)s"
"format": "[%(asctime)s] ML-%(levelname)s: %(message)s"
,"datefmt": "%Y-%m-%d %H:%M:%S"
}
},

"handlers": {
"unit_tests": {
"class": "alignak.log.CollectorHandler",
"level": "INFO",
"formatter": "unit_tests"
},
"console": {
"class": "logging.StreamHandler",
"level": "DEBUG",
"level": "ERROR",
"formatter": "alignak",
"stream": "ext://sys.stdout"
},
"color_console": {
"class": "alignak.log.ColorStreamHandler",
"level": "DEBUG",
"level": "ERROR",
"formatter": "alignak",
"stream": "ext://sys.stdout"
},
"daemons": {
"class": "logging.handlers.TimedRotatingFileHandler",
"level": "DEBUG",
"level": "INFO",
"formatter": "alignak",
"filename": "%(logdir)s/%(daemon)s.log",
"when": "midnight",
Expand All @@ -49,8 +58,8 @@

"loggers": {
"alignak": {
"level": "INFO",
"handlers": ["color_console", "daemons"],
"level": "DEBUG",
"handlers": ["unit_tests", "color_console", "daemons"],
"propagate": "no"
},
"monitoring-log": {
Expand Down

0 comments on commit 5691386

Please sign in to comment.