mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-03 01:16:10 +00:00
fix(settings): a relative WEBVIRTCLOUD_LOG_FILE is from the panel directory
WEBVIRTCLOUD_LOG_FILE=panel.log made os.makedirs("") raise while the
settings loaded: the panel did not start. A relative path is now taken
from the panel's directory, like the default data/webvirtcloud.log.
This commit is contained in:
parent
98846b1d4a
commit
13e553ba6f
3 changed files with 19 additions and 5 deletions
|
|
@ -260,10 +260,10 @@ LOCALE_PATHS = [
|
|||
BASE_DIR / "locale",
|
||||
]
|
||||
|
||||
# Resolve the application log path and make sure its directory exists, so a
|
||||
# clean checkout, CI, or a Docker build (none of which create data/) does not
|
||||
# fail when logging is configured.
|
||||
WEBVIRTCLOUD_LOG_FILE = os.getenv("WEBVIRTCLOUD_LOG_FILE", str(BASE_DIR / "data" / "webvirtcloud.log"))
|
||||
# Resolve the application log path (a relative one from the panel's directory)
|
||||
# and make sure its directory exists, so a clean checkout, CI, or a Docker
|
||||
# build (none of which create data/) does not fail when logging is configured.
|
||||
WEBVIRTCLOUD_LOG_FILE = str(BASE_DIR / (os.getenv("WEBVIRTCLOUD_LOG_FILE") or "data/webvirtcloud.log"))
|
||||
os.makedirs(os.path.dirname(WEBVIRTCLOUD_LOG_FILE), exist_ok=True)
|
||||
|
||||
LOGGING = {
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import json
|
|||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
|
||||
from django.conf import settings
|
||||
from django.test import SimpleTestCase, TestCase, override_settings
|
||||
|
|
@ -164,3 +165,16 @@ class EnvFlagTestCase(SimpleTestCase):
|
|||
for var in self.FLAGS:
|
||||
with self.subTest(var), self.assertRaisesRegex(AssertionError, f"{var} must be 1 or 0, not 'true'"):
|
||||
load_settings({var: "true"}, ["DEBUG"])
|
||||
|
||||
|
||||
class LogFileEnvTestCase(SimpleTestCase):
|
||||
def log_file(self, env):
|
||||
return load_settings(env, ["WEBVIRTCLOUD_LOG_FILE"])["WEBVIRTCLOUD_LOG_FILE"]
|
||||
|
||||
def test_a_relative_log_file_is_in_the_panel_directory(self):
|
||||
self.assertEqual(self.log_file({"WEBVIRTCLOUD_LOG_FILE": "data/panel.log"}), str(settings.BASE_DIR / "data" / "panel.log"))
|
||||
|
||||
def test_the_default_and_an_absolute_log_file(self):
|
||||
self.assertEqual(self.log_file({"WEBVIRTCLOUD_LOG_FILE": ""}), str(settings.BASE_DIR / "data" / "webvirtcloud.log"))
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
self.assertEqual(self.log_file({"WEBVIRTCLOUD_LOG_FILE": f"{tmp}/w.log"}), f"{tmp}/w.log")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue