From 9111f5ec7a6fbcec824d3c8d4018a7a6e109c466 Mon Sep 17 00:00:00 2001 From: Julien Date: Wed, 14 Jun 2017 15:33:39 +0800 Subject: [PATCH] Fix log directory issues 1. /home/opnfv can not be created in osx 2. when the log directory is not existed, anteater_logger.py will fail 3. add new added directory .reports into .gitignore Change-Id: If3833bfbaf160d35afab1c71d3fab060a1164da6 Signed-off-by: Julien --- .gitignore | 1 + anteater.conf | 6 +++--- anteater/utils/anteater_logger.py | 9 +++++++++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index eeabaeb..a8705c9 100644 --- a/.gitignore +++ b/.gitignore @@ -36,3 +36,4 @@ testapi_venv/ .tox *.retry job_output/ +.reports/ diff --git a/anteater.conf b/anteater.conf index 198ebbc..8dcc897 100644 --- a/anteater.conf +++ b/anteater.conf @@ -1,4 +1,4 @@ [config] -reports_dir = /home/opnfv/reports/ -anteater_log = /home/opnfv/anteater.log -gate_checks = /home/opnfv/anteater/gatechecks.yaml +reports_dir = .reports/ +anteater_log = .reports/anteater.log +gate_checks = ./gatechecks.yaml diff --git a/anteater/utils/anteater_logger.py b/anteater/utils/anteater_logger.py index ae9f356..1fe705f 100644 --- a/anteater/utils/anteater_logger.py +++ b/anteater/utils/anteater_logger.py @@ -11,6 +11,7 @@ import ConfigParser import logging +import os config = ConfigParser.RawConfigParser() config.read('anteater.conf') @@ -30,6 +31,14 @@ class Logger: ch.setLevel(logging.DEBUG) self.logger.addHandler(ch) + # create the directory if not existed + path = os.path.dirname(anteater_log) + if ( False == os.path.exists(path)): + try: + os.makedirs(path) + except OSError as e: + raise e + handler = logging.FileHandler(anteater_log) handler.setFormatter(formatter) handler.setLevel(logging.DEBUG) -- 2.16.6