Skip to content

Commit 0eb7b4e

Browse files
committed
Add license file for dynaconf
1 parent 6436ffa commit 0eb7b4e

File tree

5 files changed

+87
-19
lines changed

5 files changed

+87
-19
lines changed

awx/main/tests/unit/test_settings.py

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
from django.conf import settings
2-
from awx.settings import REST_FRAMEWORK
3-
from awx.settings.functions import toggle_feature_flags, merge_application_name
4-
51
LOCAL_SETTINGS = (
62
'ALLOWED_HOSTS',
73
'BROADCAST_WEBSOCKET_PORT',
@@ -18,11 +14,15 @@
1814

1915
def test_postprocess_auth_basic_enabled():
2016
"""The final loaded settings should have basic auth enabled."""
17+
from awx.settings import REST_FRAMEWORK
18+
2119
assert 'awx.api.authentication.LoggedBasicAuthentication' in REST_FRAMEWORK['DEFAULT_AUTHENTICATION_CLASSES']
2220

2321

2422
def test_default_settings():
2523
"""Ensure that all default settings are present in the snapshot."""
24+
from django.conf import settings
25+
2626
for k in dir(settings):
2727
if k not in settings.DEFAULTS_SNAPSHOT or k in LOCAL_SETTINGS:
2828
continue
@@ -33,34 +33,35 @@ def test_default_settings():
3333

3434
def test_django_conf_settings_is_awx_settings():
3535
"""Ensure that the settings loaded from dynaconf are the same as the settings delivered to django."""
36-
assert settings.REST_FRAMEWORK is REST_FRAMEWORK
36+
from django.conf import settings
37+
from awx.settings import REST_FRAMEWORK
38+
39+
assert settings.REST_FRAMEWORK == REST_FRAMEWORK
3740

3841

3942
def test_dynaconf_is_awx_settings():
4043
"""Ensure that the settings loaded from dynaconf are the same as the settings delivered to django."""
41-
assert settings.DYNACONF.REST_FRAMEWORK is REST_FRAMEWORK
44+
from django.conf import settings
45+
from awx.settings import REST_FRAMEWORK
4246

47+
assert settings.DYNACONF.REST_FRAMEWORK == REST_FRAMEWORK
4348

44-
def test_production_settings_can_be_directly_imported():
45-
"""Ensure that the production settings can be directly imported."""
46-
from awx.settings.production import REST_FRAMEWORK
47-
from awx.settings.production import DEBUG
4849

49-
assert settings.REST_FRAMEWORK is REST_FRAMEWORK
50-
assert DEBUG is False
51-
52-
53-
def test_development_settings_can_be_directly_imported():
50+
def test_development_settings_can_be_directly_imported(monkeypatch):
5451
"""Ensure that the development settings can be directly imported."""
52+
monkeypatch.setenv('AWX_MODE', 'development')
53+
from django.conf import settings
5554
from awx.settings.development import REST_FRAMEWORK
5655
from awx.settings.development import DEBUG # actually set on defaults.py and not overridden in development.py
5756

58-
assert settings.REST_FRAMEWORK is REST_FRAMEWORK
57+
assert settings.REST_FRAMEWORK == REST_FRAMEWORK
5958
assert DEBUG is True
6059

6160

6261
def test_toggle_feature_flags():
6362
"""Ensure that the toggle_feature_flags function works as expected."""
63+
from awx.settings.functions import toggle_feature_flags
64+
6465
settings = {
6566
"FLAGS": {
6667
"FEATURE_SOME_PLATFORM_FLAG_ENABLED": [
@@ -80,8 +81,12 @@ def test_toggle_feature_flags():
8081

8182
def test_merge_application_name():
8283
"""Ensure that the merge_application_name function works as expected."""
84+
from awx.settings.functions import merge_application_name
85+
8386
settings = {
8487
"DATABASES__default__ENGINE": "django.db.backends.postgresql",
8588
"CLUSTER_HOST_ID": "test-cluster-host-id",
8689
}
87-
assert merge_application_name(settings) == {"DATABASES__default__OPTIONS__application_name": "test-cluster-host-id"}
90+
result = merge_application_name(settings)["DATABASES__default__OPTIONS__application_name"]
91+
assert result.startswith("awx-")
92+
assert "test-cluster" in result

awx/settings/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88
load_standard_settings_files,
99
validate,
1010
)
11-
from .functions import merge_application_name, toggle_feature_flags
11+
from .functions import merge_application_name, toggle_feature_flags, add_backwards_compatibility
12+
13+
14+
add_backwards_compatibility()
15+
1216

1317
# Create a the standard DYNACONF instance which will come with DAB defaults
1418
# This loads defaults.py and environment specific file e.g: development_defaults.py

awx/settings/functions.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
from typing import Any
23
from dynaconf import Dynaconf
34
from dynaconf.utils.functional import empty
@@ -30,3 +31,40 @@ def merge_application_name(settings):
3031
if "sqlite3" not in settings.get("DATABASES__default__ENGINE", ""):
3132
data["DATABASES__default__OPTIONS__application_name"] = get_application_name(settings.get("CLUSTER_HOST_ID"))
3233
return data
34+
35+
36+
def add_backwards_compatibility():
37+
"""Add backwards compatibility for AWX_MODE.
38+
39+
Before dynaconf integration the usage of AWX settings was supported to be just
40+
DJANGO_SETTINGS_MODULE=awx.settings.production or DJANGO_SETTINGS_MODULE=awx.settings.development
41+
(development_quiet and development_kube were also supported).
42+
43+
With dynaconf the DJANGO_SETTINGS_MODULE should be set always to "awx.settings" as the only entry point
44+
for settings and then "AWX_MODE" can be set to any of production,development,quiet,kube
45+
or a combination of them separated by comma.
46+
47+
E.g:
48+
49+
export DJANGO_SETTINGS_MODULE=awx.settings
50+
export AWX_MODE=production
51+
awx-manage [command]
52+
dynaconf [command]
53+
54+
If pointing `DJANGO_SETTINGS_MODULE` to `awx.settings.production` or `awx.settings.development` then
55+
this function will set `AWX_MODE` to the correct value.
56+
"""
57+
django_settings_module = os.getenv("DJANGO_SETTINGS_MODULE", "awx.settings")
58+
if django_settings_module == "awx.settings":
59+
return
60+
61+
current_mode = os.getenv("AWX_MODE", "")
62+
for _module_name in ["development", "production", "development_quiet", "development_kube"]:
63+
if django_settings_module == f"awx.settings.{_module_name}":
64+
_mode = current_mode.split(",")
65+
if "development_" in _module_name and "development" not in current_mode:
66+
_mode.append("development")
67+
_mode_fragment = _module_name.replace("development_", "")
68+
if _mode_fragment not in _mode:
69+
_mode.append(_mode_fragment)
70+
os.environ["AWX_MODE"] = ",".join(_mode)

licenses/dynaconf.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2015 Bruno Rocha
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

requirements/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ djangorestframework-yaml==2.0.0
163163
# via -r /awx_devel/requirements/requirements.in
164164
durationpy==0.9
165165
# via kubernetes
166-
dynaconf==3.2.9
166+
dynaconf==3.2.10
167167
# via -r /awx_devel/requirements/requirements.in
168168
enum-compat==0.0.3
169169
# via asn1

0 commit comments

Comments
 (0)