bitbake: toaster: make django temp directory configurable

Modify the django settings to make cache, logs and databases save
to a configurable directory with TOASTER_DJANGO_TMPDIR instead of
the machine root level /tmp directory.

In addition, add this variable to the passthroughs for tox.

This change is made to facilitate cleaning test files for runs on
the autobuilder and avoid errors involving the persisted database.

(Bitbake rev: 887aaa91fd54ef24fc3cce42d584b381e37d3343)

Signed-off-by: Alexander Lussier-Cullen <alexander.lussier-cullen@savoirfairelinux.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Alexander Lussier-Cullen
2023-11-23 10:12:15 -05:00
committed by Richard Purdie
parent 6a9db991e7
commit 6a87f5d53b
3 changed files with 7 additions and 5 deletions

View File

@@ -148,6 +148,8 @@ STATICFILES_FINDERS = (
# Make this unique, and don't share it with anybody. # Make this unique, and don't share it with anybody.
SECRET_KEY = 'NOT_SUITABLE_FOR_HOSTED_DEPLOYMENT' SECRET_KEY = 'NOT_SUITABLE_FOR_HOSTED_DEPLOYMENT'
TMPDIR = os.environ.get('TOASTER_DJANGO_TMPDIR', '/tmp')
class InvalidString(str): class InvalidString(str):
def __mod__(self, other): def __mod__(self, other):
from django.template.base import TemplateSyntaxError from django.template.base import TemplateSyntaxError
@@ -214,7 +216,7 @@ CACHES = {
# }, # },
'default': { 'default': {
'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache', 'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
'LOCATION': '/tmp/toaster_cache_%d' % os.getuid(), 'LOCATION': '%s/toaster_cache_%d' % (TMPDIR, os.getuid()),
'TIMEOUT': 1, 'TIMEOUT': 1,
} }
} }
@@ -312,7 +314,7 @@ for t in os.walk(os.path.dirname(currentdir)):
LOGGING = LOGGING_SETTINGS LOGGING = LOGGING_SETTINGS
# Build paths inside the project like this: BASE_DIR / 'subdir'. # Build paths inside the project like this: BASE_DIR / 'subdir'.
BUILDDIR = os.environ.get("BUILDDIR", "/tmp") BUILDDIR = os.environ.get("BUILDDIR", TMPDIR)
# LOG VIEWER # LOG VIEWER
# https://pypi.org/project/django-log-viewer/ # https://pypi.org/project/django-log-viewer/
@@ -325,7 +327,6 @@ LOG_VIEWER_PATTERNS = ['INFO', 'DEBUG', 'WARNING', 'ERROR', 'CRITICAL']
# Optionally you can set the next variables in order to customize the admin: # Optionally you can set the next variables in order to customize the admin:
LOG_VIEWER_FILE_LIST_TITLE = "Logs list" LOG_VIEWER_FILE_LIST_TITLE = "Logs list"
if DEBUG and SQL_DEBUG: if DEBUG and SQL_DEBUG:
LOGGING['loggers']['django.db.backends'] = { LOGGING['loggers']['django.db.backends'] = {
'level': 'DEBUG', 'level': 'DEBUG',

View File

@@ -19,10 +19,10 @@ TEMPLATE_DEBUG = DEBUG
DATABASES = { DATABASES = {
'default': { 'default': {
'ENGINE': 'django.db.backends.sqlite3', 'ENGINE': 'django.db.backends.sqlite3',
'NAME': '/tmp/toaster-test-db.sqlite', 'NAME': '%s/toaster-test-db.sqlite' % TMPDIR,
'TEST': { 'TEST': {
'ENGINE': 'django.db.backends.sqlite3', 'ENGINE': 'django.db.backends.sqlite3',
'NAME': '/tmp/toaster-test-db.sqlite', 'NAME': '%s/toaster-test-db.sqlite' % TMPDIR,
} }
} }
} }

View File

@@ -8,6 +8,7 @@ passenv = *
passenv = passenv =
SSTATE_DIR SSTATE_DIR
DL_DIR DL_DIR
TOASTER_DJANGO_TMPDIR
setenv = setenv =
DJANGO_SETTINGS_MODULE=toastermain.settings_test DJANGO_SETTINGS_MODULE=toastermain.settings_test
TOASTER_BUILDSERVER=1 TOASTER_BUILDSERVER=1