update link to upper-constraints.txt
[modeling/etsicatalog.git] / catalog / 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 platform
17 import sys
18 import yaml
19 from logging import config as log_config
20
21 from catalog.pub.config import config as pub_config
22 from catalog.pub.config.config import DB_NAME, DB_IP, DB_USER, DB_PASSWD, DB_PORT
23
24 # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
25 BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
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 # Application definition
39
40 INSTALLED_APPS = [
41     'django.contrib.auth',
42     'django.contrib.contenttypes',
43     'django.contrib.sessions',
44     'django.contrib.messages',
45     'django.contrib.staticfiles',
46     'django.contrib.admin',
47     'rest_framework',
48     'catalog.pub.database',
49     'catalog.samples',
50     'catalog.swagger',
51     'drf_yasg',
52     # 'django_nose'
53 ]
54 # TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'
55 # drf-yasg
56 SWAGGER_SETTINGS = {
57     'LOGIN_URL': '/admin/login',
58     'LOGOUT_URL': '/admin/logout',
59     'DEFAULT_INFO': 'catalog.swagger.urls.swagger_info'
60 }
61
62 TEMPLATES = [
63     {
64         'BACKEND': 'django.template.backends.django.DjangoTemplates',
65         'DIRS': [],
66         'APP_DIRS': True,
67         'OPTIONS': {
68             'context_processors': [
69                 'django.template.context_processors.debug',
70                 'django.template.context_processors.request',
71                 'django.contrib.auth.context_processors.auth',
72                 'django.contrib.messages.context_processors.messages',
73             ],
74         },
75     },
76 ]
77
78 MIDDLEWARE = [
79     'django.middleware.security.SecurityMiddleware',
80     'django.contrib.sessions.middleware.SessionMiddleware',
81     'django.middleware.common.CommonMiddleware',
82     'django.middleware.csrf.CsrfViewMiddleware',
83     'django.contrib.auth.middleware.AuthenticationMiddleware',
84     'django.contrib.messages.middleware.MessageMiddleware',
85     'django.middleware.clickjacking.XFrameOptionsMiddleware',
86 ]
87
88 ROOT_URLCONF = 'catalog.urls'
89
90 WSGI_APPLICATION = 'catalog.wsgi.application'
91
92 REST_FRAMEWORK = {
93     'DEFAULT_RENDERER_CLASSES': (
94         'rest_framework.renderers.JSONRenderer',
95     ),
96
97     'DEFAULT_PARSER_CLASSES': (
98         'rest_framework.parsers.JSONParser',
99         'rest_framework.parsers.MultiPartParser',
100     )
101 }
102
103 DATABASES = {
104     'default': {
105         'ENGINE': 'django.db.backends.mysql',
106         'NAME': DB_NAME,
107         'HOST': DB_IP,
108         'PORT': DB_PORT,
109         'USER': DB_USER,
110         'PASSWORD': DB_PASSWD,
111     },
112 }
113
114 # DATABASES = {}
115 # DATABASES['default'] = {
116 #     'ENGINE': 'django.db.backends.sqlite3',
117 #     'NAME': ':memory:',
118 # }
119
120 # catalog.pub.redisco.connection_setup(host=REDIS_HOST, port=REDIS_PORT, password=REDIS_PASSWD, db=0)
121 # CACHE_BACKEND = 'redis_cache.cache://%s@%s:%s' % (REDIS_PASSWD, REDIS_HOST, REDIS_PORT)
122
123 TIME_ZONE = 'UTC'
124
125 # Static files (CSS, JavaScript, Images)
126 # https://docs.djangoproject.com/en/1.6/howto/static-files/
127
128 STATIC_URL = '/static/'
129
130 STATICFILES_DIRS = [
131     os.path.join(BASE_DIR, "static")
132 ]
133
134 pub_config.CATALOG_ROOT_PATH = os.path.join(STATICFILES_DIRS[0], "catalog")
135 pub_config.CATALOG_URL_PATH = "static/catalog"
136
137 if platform.system() == 'Windows' or 'test' in sys.argv:
138     LOGGING = {
139         'version': 1,
140         'disable_existing_loggers': True,
141         'formatters': {
142             'standard': {
143                 'format': '%(asctime)s:[%(name)s]:[%(filename)s]-[%(lineno)d] [%(levelname)s]:%(message)s',
144             },
145         },
146         'filters': {
147         },
148         'handlers': {
149             'catalog_handler': {
150                 'level': 'DEBUG',
151                 'class': 'logging.handlers.RotatingFileHandler',
152                 'filename': os.path.join(BASE_DIR, 'logs/runtime_catalog.log'),
153                 'formatter': 'standard',
154                 'maxBytes': 1024 * 1024 * 50,
155                 'backupCount': 5,
156             },
157             'console': {
158                 'level': 'DEBUG',
159                 'class': 'logging.StreamHandler',
160                 'formatter': 'standard'
161             },
162         },
163
164         'loggers': {
165             'catalog': {
166                 'handlers': ['catalog_handler', 'console'],
167                 'level': 'DEBUG',
168                 'propagate': False
169             },
170             'tosca': {
171                 'handlers': ['catalog_handler'],
172                 'level': 'DEBUG',
173                 'propagate': False
174             },
175         }
176     }
177 else:
178     LOGGING_CONFIG = None
179     log_path = '/var/log/onap/modeling/etsicatalog'
180     if not os.path.exists(log_path):
181         os.makedirs(log_path)
182
183     # yaml configuration of logging
184     LOGGING_FILE = os.path.join(BASE_DIR, 'catalog/log.yml')
185     with open(file=LOGGING_FILE, mode='r', encoding="utf-8")as file:
186         logging_yaml = yaml.load(stream=file, Loader=yaml.FullLoader)
187     log_config.dictConfig(config=logging_yaml)
188
189 if 'test' in sys.argv:
190     pub_config.REG_TO_MSB_WHEN_START = False
191
192     DATABASES = {}
193     DATABASES['default'] = {
194         'ENGINE': 'django.db.backends.sqlite3',
195         'NAME': ':memory:',
196     }
197     REST_FRAMEWORK = {}
198
199     if platform.system() == 'Linux':
200         TEST_RUNNER = 'xmlrunner.extra.djangotestrunner.XMLTestRunner'
201         TEST_OUTPUT_VERBOSE = True
202         TEST_OUTPUT_DESCRIPTIONS = True
203         TEST_OUTPUT_DIR = 'test-reports'