Fix log directory issues 93/36093/3
authorJulien <zhang.jun3g@zte.com.cn>
Wed, 14 Jun 2017 07:33:39 +0000 (15:33 +0800)
committerJulien <zhang.jun3g@zte.com.cn>
Wed, 14 Jun 2017 09:01:13 +0000 (17:01 +0800)
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 <zhang.jun3g@zte.com.cn>
.gitignore
anteater.conf
anteater/utils/anteater_logger.py

index eeabaeb..a8705c9 100644 (file)
@@ -36,3 +36,4 @@ testapi_venv/
 .tox
 *.retry
 job_output/
+.reports/
index 198ebbc..8dcc897 100644 (file)
@@ -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
index ae9f356..1fe705f 100644 (file)
@@ -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)