Fix log error when run unit tests in windows 61/59061/1
authorlaili <lai.li@zte.com.cn>
Mon, 6 Aug 2018 02:52:28 +0000 (10:52 +0800)
committerlaili <lai.li@zte.com.cn>
Mon, 6 Aug 2018 02:54:45 +0000 (10:54 +0800)
Fix log error when run catalog tests in windows

Change-Id: Ia075df00ba7b12529b1f81a2766b0a7c1b13f0c9
Issue-ID: VFC-1014
Signed-off-by: laili <lai.li@zte.com.cn>
catalog/settings.py

index 1920f1b..67b58b9 100644 (file)
@@ -14,6 +14,7 @@
 
 import os
 import sys
+import platform
 
 import redisco
 
@@ -131,47 +132,44 @@ STATICFILES_DIRS = [
 pub_config.CATALOG_ROOT_PATH = os.path.join(STATICFILES_DIRS[0], "catalog")
 pub_config.CATALOG_URL_PATH = "static/catalog"
 pub_config.SDC_BASE_URL = "http://%s:%s/api" % (pub_config.MSB_SERVICE_IP, pub_config.MSB_SERVICE_PORT)
-#
-# LOGGING = {
-#     'version': 1,
-#     'disable_existing_loggers': True,
-#     'formatters': {
-#         'standard': {
-#             'format': '%(asctime)s:[%(name)s]:[%(filename)s]-[%(lineno)d] [%(levelname)s]:%(message)s',
-#         },
-#     },
-#     'filters': {
-#     },
-#     'handlers': {
-#         'catalog_handler': {
-#             'level': 'DEBUG',
-#             'class': 'logging.handlers.RotatingFileHandler',
-#             'filename': os.path.join(BASE_DIR, 'logs/runtime_catalog.log'),
-#             'formatter': 'standard',
-#             'maxBytes': 1024 * 1024 * 50,
-#             'backupCount': 5,
-#         },
-#     },
-#
-#     'loggers': {
-#         'catalog': {
-#             'handlers': ['catalog_handler'],
-#             'level': 'DEBUG',
-#             'propagate': False
-#         },
-#     }
-# }
-
-LOGGING_CONFIG = None
-# yaml configuration of logging
-LOGGING_FILE = os.path.join(BASE_DIR, 'catalog/log.yml')
-if 'test' in sys.argv:
-    os.system('sed -i "s|/var/log/onap/vfc/catalog|/tmp|" %s' % LOGGING_FILE)
-log_config.yamlConfig(filepath=LOGGING_FILE, watchDog=True)
 
-if 'test' in sys.argv:
-    os.system('sed -i "s|/tmp|/var/log/onap/vfc/catalog|" %s' % LOGGING_FILE)
+if platform.system() == 'Windows' or 'test' in sys.argv:
+    LOGGING = {
+        'version': 1,
+        'disable_existing_loggers': True,
+        'formatters': {
+            'standard': {
+                'format': '%(asctime)s:[%(name)s]:[%(filename)s]-[%(lineno)d] [%(levelname)s]:%(message)s',
+            },
+        },
+        'filters': {
+        },
+        'handlers': {
+            'catalog_handler': {
+                'level': 'DEBUG',
+                'class': 'logging.handlers.RotatingFileHandler',
+                'filename': os.path.join(BASE_DIR, 'logs/runtime_catalog.log'),
+                'formatter': 'standard',
+                'maxBytes': 1024 * 1024 * 50,
+                'backupCount': 5,
+            },
+        },
 
+        'loggers': {
+            'catalog': {
+                'handlers': ['catalog_handler'],
+                'level': 'DEBUG',
+                'propagate': False
+            },
+        }
+    }
+else:
+    LOGGING_CONFIG = None
+    # yaml configuration of logging
+    LOGGING_FILE = os.path.join(BASE_DIR, 'catalog/log.yml')
+    log_config.yamlConfig(filepath=LOGGING_FILE, watchDog=True)
+
+if 'test' in sys.argv:
     pub_config.REG_TO_MSB_WHEN_START = False
 
     DATABASES = {}
@@ -181,7 +179,6 @@ if 'test' in sys.argv:
     }
     REST_FRAMEWORK = {}
 
-    import platform
     if platform.system() == 'Linux':
         TEST_RUNNER = 'xmlrunner.extra.djangotestrunner.XMLTestRunner'
         TEST_OUTPUT_VERBOSE = True