Remove dependency on onaplogging in vnflcm
[vfc/gvnfm/vnflcm.git] / lcm / lcm / settings.py
1 # Copyright 2017 ZTE Corporation.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #         http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 import os
16 import sys
17 import platform
18
19 import lcm.pub.redisco
20 import yaml
21
22 from lcm.pub.config.config import REDIS_HOST, REDIS_PORT, REDIS_PASSWD
23 from lcm.pub.config.config import DB_NAME, DB_IP, DB_USER, DB_PASSWD, DB_PORT
24 from logging import config
25
26 # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
27 BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
28
29 # Quick-start development settings - unsuitable for production
30 # See https://docs.djangoproject.com/en/1.9/howto/deployment/checklist/
31
32 # SECURITY WARNING: keep the secret key used in production secret!
33 SECRET_KEY = '3o-wney!99y)^h3v)0$j16l9=fdjxcb+a8g+q3tfbahcnu2b0o'
34
35 # SECURITY WARNING: don't run with debug turned on in production!
36 DEBUG = True
37
38 ALLOWED_HOSTS = ['*']
39
40 # Application definition
41
42 INSTALLED_APPS = [
43     'django.contrib.auth',
44     'django.contrib.contenttypes',
45     'django.contrib.sessions',
46     'django.contrib.messages',
47     'django.contrib.staticfiles',
48     'django.contrib.admin',
49     'rest_framework',
50     'lcm.pub.database',
51     'lcm.samples',
52     'lcm.swagger',
53     'drf_yasg',
54 ]
55
56 MIDDLEWARE = [
57     # 'django.contrib.sessions.middleware.SessionMiddleware',
58     # 'django.middleware.common.CommonMiddleware',
59     # 'django.middleware.csrf.CsrfViewMiddleware',
60     # 'django.contrib.auth.middleware.AuthenticationMiddleware',
61     # # 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
62     # 'django.contrib.messages.middleware.MessageMiddleware',
63     # 'django.middleware.clickjacking.XFrameOptionsMiddleware',
64     # 'django.middleware.security.SecurityMiddleware',
65     'django.middleware.security.SecurityMiddleware',
66     'django.contrib.sessions.middleware.SessionMiddleware',
67     'django.middleware.common.CommonMiddleware',
68     'django.middleware.csrf.CsrfViewMiddleware',
69     'django.contrib.auth.middleware.AuthenticationMiddleware',
70     'django.contrib.messages.middleware.MessageMiddleware',
71     'django.middleware.clickjacking.XFrameOptionsMiddleware',
72 ]
73
74 ROOT_URLCONF = 'lcm.urls'
75
76 WSGI_APPLICATION = 'lcm.wsgi.application'
77
78 REST_FRAMEWORK = {
79     'DEFAULT_RENDERER_CLASSES': (
80         'rest_framework.renderers.JSONRenderer',
81     ),
82
83     'DEFAULT_PARSER_CLASSES': (
84         'rest_framework.parsers.JSONParser',
85         'rest_framework.parsers.MultiPartParser',
86     )
87 }
88
89 # drf-yasg
90 TEMPLATES = [
91     {
92         'BACKEND': 'django.template.backends.django.DjangoTemplates',
93         'DIRS': [],
94         'APP_DIRS': True,
95         'OPTIONS': {
96             'context_processors': [
97                 'django.template.context_processors.debug',
98                 'django.template.context_processors.request',
99                 'django.contrib.auth.context_processors.auth',
100                 'django.contrib.messages.context_processors.messages',
101             ],
102         },
103     },
104 ]
105
106 SWAGGER_SETTINGS = {
107     'LOGIN_URL': '/admin/login',
108     'LOGOUT_URL': '/admin/logout',
109
110     'DEFAULT_INFO': 'lcm.swagger.urls.swagger_info'
111 }
112
113 DATABASES = {
114     'default': {
115         'ENGINE': 'django.db.backends.mysql',
116         'NAME': DB_NAME,
117         'HOST': DB_IP,
118         'PORT': DB_PORT,
119         'USER': DB_USER,
120         'PASSWORD': DB_PASSWD,
121     },
122 }
123
124 lcm.pub.redisco.connection_setup(host=REDIS_HOST, port=REDIS_PORT, password=REDIS_PASSWD, db=0)
125 # CACHE_BACKEND = 'redis_cache.cache://%s@%s:%s' % (REDIS_PASSWD, REDIS_HOST, REDIS_PORT)
126
127 TIME_ZONE = 'UTC'
128
129 # Static files (CSS, JavaScript, Images)
130 # https://docs.djangoproject.com/en/1.6/howto/static-files/
131
132 STATIC_URL = '/static/'
133
134 if platform.system() == 'Windows' or 'test' in sys.argv:
135     LOGGING = {
136         'version': 1,
137         'disable_existing_loggers': True,
138         'formatters': {
139             'standard': {
140                 'format': '%(asctime)s:[%(name)s]:[%(filename)s]-[%(lineno)d] [%(levelname)s]:%(message)s',
141             },
142         },
143         'filters': {
144         },
145         'handlers': {
146             'lcm_handler': {
147                 'level': 'DEBUG',
148                 'class': 'logging.handlers.RotatingFileHandler',
149                 'filename': os.path.join(BASE_DIR, 'logs/runtime_lcm.log'),
150                 'formatter': 'standard',
151                 'maxBytes': 1024 * 1024 * 50,
152                 'backupCount': 5,
153             },
154         },
155
156         'loggers': {
157             'lcm': {
158                 'handlers': ['lcm_handler'],
159                 'level': 'DEBUG',
160                 'propagate': False
161             },
162         }
163     }
164 else:
165     LOGGING_CONFIG = None
166
167     log_path = '/var/log/onap/vfc/gvnfm-vnflcm'
168     if not os.path.exists(log_path):
169         os.makedirs(log_path)
170
171     LOGGING_FILE = os.path.join(BASE_DIR, 'lcm/log.yml')
172     with open(file=LOGGING_FILE, mode='r', encoding="utf-8")as file:
173         logging_yaml = yaml.load(stream=file, Loader=yaml.FullLoader)
174     config.dictConfig(config=logging_yaml)
175
176
177 if 'test' in sys.argv:
178     from lcm.pub.config import config
179     config.REG_TO_MSB_WHEN_START = False
180
181     DATABASES = {}
182     DATABASES['default'] = {
183         'ENGINE': 'django.db.backends.sqlite3',
184         'NAME': ':memory:',
185     }
186     REST_FRAMEWORK = {}
187     import platform
188
189     if platform.system() == 'Linux':
190         TEST_RUNNER = 'xmlrunner.extra.djangotestrunner.XMLTestRunner'
191         TEST_OUTPUT_VERBOSE = True
192         TEST_OUTPUT_DESCRIPTIONS = True
193         TEST_OUTPUT_DIR = 'test-reports'
194
195     import mock
196     from lcm.pub.utils import idutil
197     idutil.get_auto_id = mock.Mock()
198     idutil.get_auto_id.return_value = 1