OpenStack Dashboard (Horizon)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

settings.py 9.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  2. # not use this file except in compliance with the License. You may obtain
  3. # a copy of the License at
  4. #
  5. # http://www.apache.org/licenses/LICENSE-2.0
  6. #
  7. # Unless required by applicable law or agreed to in writing, software
  8. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  9. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  10. # License for the specific language governing permissions and limitations
  11. # under the License.
  12. import os
  13. import tempfile
  14. import six
  15. from django.utils.translation import pgettext_lazy
  16. from horizon.test.settings import * # noqa: F403,H303
  17. from horizon.utils import secret_key
  18. from openstack_dashboard import exceptions
  19. from horizon.utils.escape import monkeypatch_escape
  20. # this is used to protect from client XSS attacks, but it's worth
  21. # enabling in our test setup to find any issues it might cause
  22. monkeypatch_escape()
  23. from openstack_dashboard.utils import settings as settings_utils
  24. TEST_DIR = os.path.dirname(os.path.abspath(__file__))
  25. ROOT_PATH = os.path.abspath(os.path.join(TEST_DIR, ".."))
  26. MEDIA_ROOT = os.path.abspath(os.path.join(ROOT_PATH, '..', 'media'))
  27. MEDIA_URL = '/media/'
  28. STATIC_ROOT = os.path.abspath(os.path.join(ROOT_PATH, '..', 'static'))
  29. STATIC_URL = '/static/'
  30. WEBROOT = '/'
  31. SECRET_KEY = secret_key.generate_or_read_from_file(
  32. os.path.join(tempfile.gettempdir(), '.secret_key_store'))
  33. ROOT_URLCONF = 'openstack_dashboard.test.urls'
  34. TEMPLATES[0]['DIRS'] = [
  35. os.path.join(TEST_DIR, 'templates')
  36. ]
  37. TEMPLATES[0]['OPTIONS']['context_processors'].append(
  38. 'openstack_dashboard.context_processors.openstack'
  39. )
  40. CUSTOM_THEME_PATH = 'themes/default'
  41. # 'key', 'label', 'path'
  42. AVAILABLE_THEMES = [
  43. (
  44. 'default',
  45. pgettext_lazy('Default style theme', 'Default'),
  46. 'themes/default'
  47. ), (
  48. 'material',
  49. pgettext_lazy("Google's Material Design style theme", "Material"),
  50. 'themes/material'
  51. ),
  52. ]
  53. SELECTABLE_THEMES = [
  54. (
  55. 'default',
  56. pgettext_lazy('Default style theme', 'Default'),
  57. 'themes/default'
  58. ),
  59. ]
  60. # Theme Static Directory
  61. THEME_COLLECTION_DIR = 'themes'
  62. COMPRESS_OFFLINE = False
  63. INSTALLED_APPS = (
  64. 'django.contrib.contenttypes',
  65. 'django.contrib.auth',
  66. 'django.contrib.sessions',
  67. 'django.contrib.staticfiles',
  68. 'django.contrib.messages',
  69. 'django.contrib.humanize',
  70. 'django_nose',
  71. 'openstack_auth',
  72. 'compressor',
  73. 'horizon',
  74. 'openstack_dashboard',
  75. )
  76. AUTHENTICATION_BACKENDS = ('openstack_auth.backend.KeystoneBackend',)
  77. SITE_BRANDING = 'OpenStack'
  78. HORIZON_CONFIG = {
  79. "password_validator": {
  80. "regex": '^.{8,18}$',
  81. "help_text": "Password must be between 8 and 18 characters."
  82. },
  83. 'user_home': None,
  84. 'help_url': "http://docs.openstack.org",
  85. 'exceptions': {'recoverable': exceptions.RECOVERABLE,
  86. 'not_found': exceptions.NOT_FOUND,
  87. 'unauthorized': exceptions.UNAUTHORIZED},
  88. 'angular_modules': [],
  89. 'js_files': [],
  90. }
  91. ANGULAR_FEATURES = {
  92. 'images_panel': False, # Use the legacy panel so unit tests are still run
  93. 'flavors_panel': False,
  94. 'roles_panel': False,
  95. }
  96. STATICFILES_DIRS = settings_utils.get_xstatic_dirs(
  97. settings_utils.BASE_XSTATIC_MODULES, HORIZON_CONFIG
  98. )
  99. # Load the pluggable dashboard settings
  100. import openstack_dashboard.enabled
  101. INSTALLED_APPS = list(INSTALLED_APPS) # Make sure it's mutable
  102. settings_utils.update_dashboards(
  103. [
  104. openstack_dashboard.enabled,
  105. ],
  106. HORIZON_CONFIG,
  107. INSTALLED_APPS,
  108. )
  109. OPENSTACK_PROFILER = {'enabled': False}
  110. settings_utils.find_static_files(HORIZON_CONFIG, AVAILABLE_THEMES,
  111. THEME_COLLECTION_DIR, ROOT_PATH)
  112. # Set to 'legacy' or 'direct' to allow users to upload images to glance via
  113. # Horizon server. When enabled, a file form field will appear on the create
  114. # image form. If set to 'off', there will be no file form field on the create
  115. # image form. See documentation for deployment considerations.
  116. HORIZON_IMAGES_UPLOAD_MODE = 'legacy'
  117. AVAILABLE_REGIONS = [
  118. ('http://localhost:5000/v3', 'local'),
  119. ('http://remote:5000/v3', 'remote'),
  120. ]
  121. OPENSTACK_API_VERSIONS = {
  122. "identity": 3,
  123. "image": 2
  124. }
  125. OPENSTACK_KEYSTONE_URL = "http://localhost:5000/v3"
  126. OPENSTACK_KEYSTONE_DEFAULT_ROLE = "_member_"
  127. OPENSTACK_KEYSTONE_MULTIDOMAIN_SUPPORT = True
  128. OPENSTACK_KEYSTONE_DEFAULT_DOMAIN = 'test_domain'
  129. OPENSTACK_KEYSTONE_FEDERATION_MANAGEMENT = True
  130. OPENSTACK_KEYSTONE_BACKEND = {
  131. 'name': 'native',
  132. 'can_edit_user': True,
  133. 'can_edit_group': True,
  134. 'can_edit_project': True,
  135. 'can_edit_domain': True,
  136. 'can_edit_role': True
  137. }
  138. OPENSTACK_CINDER_FEATURES = {
  139. 'enable_backup': True,
  140. }
  141. OPENSTACK_NEUTRON_NETWORK = {
  142. 'enable_router': True,
  143. 'enable_quotas': False, # Enabled in specific tests only
  144. 'enable_distributed_router': False,
  145. }
  146. OPENSTACK_HYPERVISOR_FEATURES = {
  147. 'can_set_mount_point': False,
  148. 'can_set_password': True,
  149. }
  150. OPENSTACK_IMAGE_BACKEND = {
  151. 'image_formats': [
  152. ('', 'Select format'),
  153. ('aki', 'AKI - Amazon Kernel Image'),
  154. ('ami', 'AMI - Amazon Machine Image'),
  155. ('ari', 'ARI - Amazon Ramdisk Image'),
  156. ('iso', 'ISO - Optical Disk Image'),
  157. ('ploop', 'PLOOP - Virtuozzo/Parallels Loopback Disk'),
  158. ('qcow2', 'QCOW2 - QEMU Emulator'),
  159. ('raw', 'Raw'),
  160. ('vdi', 'VDI'),
  161. ('vhd', 'VHD'),
  162. ('vmdk', 'VMDK')
  163. ]
  164. }
  165. LOGGING['loggers'].update(
  166. {
  167. 'openstack_dashboard': {
  168. 'handlers': ['test'],
  169. 'propagate': False,
  170. },
  171. 'openstack_auth': {
  172. 'handlers': ['test'],
  173. 'propagate': False,
  174. },
  175. 'novaclient': {
  176. 'handlers': ['test'],
  177. 'propagate': False,
  178. },
  179. 'keystoneclient': {
  180. 'handlers': ['test'],
  181. 'propagate': False,
  182. },
  183. 'glanceclient': {
  184. 'handlers': ['test'],
  185. 'propagate': False,
  186. },
  187. 'neutronclient': {
  188. 'handlers': ['test'],
  189. 'propagate': False,
  190. },
  191. 'oslo_policy': {
  192. 'handlers': ['test'],
  193. 'propagate': False,
  194. },
  195. 'stevedore': {
  196. 'handlers': ['test'],
  197. 'propagate': False,
  198. },
  199. 'iso8601': {
  200. 'handlers': ['null'],
  201. 'propagate': False,
  202. },
  203. }
  204. )
  205. SECURITY_GROUP_RULES = {
  206. 'all_tcp': {
  207. 'name': 'ALL TCP',
  208. 'ip_protocol': 'tcp',
  209. 'from_port': '1',
  210. 'to_port': '65535',
  211. },
  212. 'http': {
  213. 'name': 'HTTP',
  214. 'ip_protocol': 'tcp',
  215. 'from_port': '80',
  216. 'to_port': '80',
  217. },
  218. }
  219. NOSE_ARGS = ['--nocapture',
  220. '--nologcapture',
  221. '--cover-package=openstack_dashboard',
  222. '--cover-inclusive',
  223. '--all-modules']
  224. # TODO(amotoki): Need to investigate why --with-html-output
  225. # is unavailable in python3.
  226. # NOTE(amotoki): Most horizon plugins import this module in their test
  227. # settings and they do not necessarily have nosehtmloutput in test-reqs.
  228. # Assuming nosehtmloutput potentially breaks plugins tests,
  229. # we check the availability of htmloutput module (from nosehtmloutput).
  230. try:
  231. import htmloutput # noqa: F401
  232. has_html_output = True
  233. except ImportError:
  234. has_html_output = False
  235. if six.PY2 and has_html_output:
  236. NOSE_ARGS += ['--with-html-output',
  237. '--html-out-file=ut_openstack_dashboard_nose_results.html']
  238. POLICY_FILES_PATH = os.path.join(ROOT_PATH, "conf")
  239. POLICY_FILES = {
  240. 'identity': 'keystone_policy.json',
  241. 'compute': 'nova_policy.json'
  242. }
  243. # The openstack_auth.user.Token object isn't JSON-serializable ATM
  244. SESSION_SERIALIZER = 'django.contrib.sessions.serializers.PickleSerializer'
  245. REST_API_SETTING_1 = 'foo'
  246. REST_API_SETTING_2 = 'bar'
  247. REST_API_SECURITY = 'SECURITY'
  248. REST_API_REQUIRED_SETTINGS = ['REST_API_SETTING_1']
  249. REST_API_ADDITIONAL_SETTINGS = ['REST_API_SETTING_2']
  250. ALLOWED_PRIVATE_SUBNET_CIDR = {'ipv4': [], 'ipv6': []}
  251. # --------------------
  252. # Test-only settings
  253. # --------------------
  254. # TEST_GLOBAL_MOCKS_ON_PANELS: defines what and how methods should be
  255. # mocked globally for unit tests and Selenium tests.
  256. # 'method' is required. 'return_value' and 'side_effect'
  257. # are optional and passed to mock.patch().
  258. TEST_GLOBAL_MOCKS_ON_PANELS = {
  259. 'aggregates': {
  260. 'method': ('openstack_dashboard.dashboards.admin'
  261. '.aggregates.panel.Aggregates.can_access'),
  262. 'return_value': True,
  263. },
  264. 'domains': {
  265. 'method': ('openstack_dashboard.dashboards.identity'
  266. '.domains.panel.Domains.can_access'),
  267. 'return_value': True,
  268. },
  269. 'server_groups': {
  270. 'method': ('openstack_dashboard.dashboards.project'
  271. '.server_groups.panel.ServerGroups.can_access'),
  272. 'return_value': True,
  273. },
  274. 'trunk-project': {
  275. 'method': ('openstack_dashboard.dashboards.project'
  276. '.trunks.panel.Trunks.can_access'),
  277. 'return_value': True,
  278. },
  279. 'trunk-admin': {
  280. 'method': ('openstack_dashboard.dashboards.admin'
  281. '.trunks.panel.Trunks.can_access'),
  282. 'return_value': True,
  283. },
  284. 'qos': {
  285. 'method': ('openstack_dashboard.dashboards.project'
  286. '.network_qos.panel.NetworkQoS.can_access'),
  287. 'return_value': True,
  288. },
  289. }