ddc2a86a92cdb9776f5e1a90e51137e19bcad75e
[vfc/nfvo/driver/vnfm/svnfm.git] / zte / vmanager / driver / settings.py
1 # Copyright 2016-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 from logging import config
19 from onaplogging import monkey
20 monkey.patch_all()
21
22 # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
23
24 BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
25
26
27 # Quick-start development settings - unsuitable for production
28 # See https://docs.djangoproject.com/en/1.9/howto/deployment/checklist/
29
30 # SECURITY WARNING: keep the secret key used in production secret!
31 SECRET_KEY = '3o-wney!99y)^h3v)0$j16l9=fdjxcb+a8g+q3tfbahcnu2b0o'
32
33 # SECURITY WARNING: don't run with debug turned on in production!
34 DEBUG = True
35
36 ALLOWED_HOSTS = ['*']
37
38
39 # Application definition
40
41 INSTALLED_APPS = [
42     'django.contrib.auth',
43     'django.contrib.contenttypes',
44     'django.contrib.sessions',
45     'django.contrib.messages',
46     'django.contrib.staticfiles',
47     'rest_framework',
48     'driver.pub.database',
49     'driver.interfaces',
50     'driver.swagger',
51     'drf_yasg',
52 ]
53
54 MIDDLEWARE_CLASSES = [
55     'django.middleware.security.SecurityMiddleware',
56     'django.contrib.sessions.middleware.SessionMiddleware',
57     'django.middleware.common.CommonMiddleware',
58     'django.middleware.csrf.CsrfViewMiddleware',
59     'django.contrib.auth.middleware.AuthenticationMiddleware',
60     'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
61     'django.contrib.messages.middleware.MessageMiddleware',
62     'django.middleware.clickjacking.XFrameOptionsMiddleware',
63     'driver.middleware.LogContextMiddleware',
64 ]
65
66 ROOT_URLCONF = 'driver.urls'
67
68 WSGI_APPLICATION = 'driver.wsgi.application'
69
70
71 REST_FRAMEWORK = {
72     'DEFAULT_RENDERER_CLASSES': (
73         'rest_framework.renderers.JSONRenderer',
74     ),
75
76     'DEFAULT_PARSER_CLASSES': (
77         'rest_framework.parsers.JSONParser',
78         'rest_framework.parsers.MultiPartParser',
79     )
80 }
81
82 # drf-yasg
83 TEMPLATES = [
84     {
85         'BACKEND': 'django.template.backends.django.DjangoTemplates',
86         'DIRS': [],
87         'APP_DIRS': True,
88         'OPTIONS': {
89             'context_processors': [
90                 'django.template.context_processors.debug',
91                 'django.template.context_processors.request',
92                 'django.contrib.auth.context_processors.auth',
93                 'django.contrib.messages.context_processors.messages',
94             ],
95         },
96     },
97 ]
98
99 SWAGGER_SETTINGS = {
100     'LOGIN_URL': '/admin/login',
101     'LOGOUT_URL': '/admin/logout',
102
103     'DEFAULT_INFO': 'driver.swagger.urls.swagger_info'
104 }
105
106 DATABASES = {
107     'default': {
108         'ENGINE': 'django.db.backends.sqlite3',
109         'NAME': ':memory:',
110     },
111 }
112
113 TIME_ZONE = 'UTC'
114
115 # Static files (CSS, JavaScript, Images)
116 # https://docs.djangoproject.com/en/1.6/howto/static-files/
117
118 STATIC_URL = '/static/'
119
120 if platform.system() == 'Windows' or 'test' in sys.argv:
121     LOGGING = {
122         'version': 1,
123         'disable_existing_loggers': True,
124         'formatters': {
125             'standard': {
126                 'format': '%(asctime)s:[%(name)s]:[%(filename)s]-[%(lineno)d] [%(levelname)s]:%(message)s',
127             },
128         },
129         'filters': {
130         },
131         'handlers': {
132             'driver_handler': {
133                 'level': 'DEBUG',
134                 'class': 'logging.handlers.RotatingFileHandler',
135                 'filename': os.path.join(
136                     BASE_DIR,
137                     'logs/runtime_driver.log'),
138                 'formatter': 'standard',
139                 'maxBytes': 1024 * 1024 * 50,
140                 'backupCount': 5,
141             },
142         },
143         'loggers': {
144             'driver': {
145                 'handlers': ['driver_handler'],
146                 'level': 'DEBUG',
147                 'propagate': False},
148         }}
149 else:
150     LOGGING_CONFIG = None
151     # yaml configuration of logging
152     LOGGING_FILE = os.path.join(BASE_DIR, 'driver/log.yml')
153     config.yamlConfig(filepath=LOGGING_FILE, watchDog=True)
154
155
156 if 'test' in sys.argv:
157
158     from driver.pub.config import config
159     config.REG_TO_MSB_WHEN_START = False
160     REST_FRAMEWORK = {}
161     if platform.system() == 'Linux':
162         TEST_RUNNER = 'xmlrunner.extra.djangotestrunner.XMLTestRunner'
163         TEST_OUTPUT_VERBOSE = True
164         TEST_OUTPUT_DESCRIPTIONS = True
165         TEST_OUTPUT_DIR = 'test-reports'