diff --git a/README.md b/README.md index 70f255f..468b3e9 100644 --- a/README.md +++ b/README.md @@ -232,7 +232,7 @@ Das Plugin unter `netbox_plugin/` ist auf NetBox 4.6.5–4.6.8 begrenzt. Zuerst ```text cd netbox_plugin python -m build -/opt/netbox/venv/bin/pip install dist/netbox_plugin_store-0.1.0-py3-none-any.whl +/opt/netbox/venv/bin/pip install dist/netbox_plugin_store-0.1.1-py3-none-any.whl ``` Das Paket muss außerdem in `/opt/netbox/local_requirements.txt` festgehalten werden. In `configuration.py` wird es zunächst sicher im Dry-run-Modus eingerichtet: diff --git a/netbox_plugin/README.md b/netbox_plugin/README.md index f52fcea..a5d76e5 100644 --- a/netbox_plugin/README.md +++ b/netbox_plugin/README.md @@ -22,7 +22,7 @@ The safe default is intentionally non-mutating. Installing the UI alone never gr Install the wheel into NetBox's virtual environment and persist it in `/opt/netbox/local_requirements.txt`: ```text -netbox-plugin-store==0.1.0 +netbox-plugin-store==0.1.1 ``` Add the plugin to `configuration.py`: diff --git a/netbox_plugin/netbox_plugin_store/runtime.py b/netbox_plugin/netbox_plugin_store/runtime.py index 141e135..be47fd8 100644 --- a/netbox_plugin/netbox_plugin_store/runtime.py +++ b/netbox_plugin/netbox_plugin_store/runtime.py @@ -11,6 +11,12 @@ class RuntimeConfigurationError(RuntimeError): pass +def _netbox_root(django_settings: object) -> Path: + """Return NETBOX_ROOT while supporting NetBox settings that expose paths as strings.""" + base_dir = Path(getattr(django_settings, "BASE_DIR")) + return Path(getattr(django_settings, "NETBOX_ROOT", base_dir.parent)) + + def _argv_list(value: object, setting: str) -> tuple[tuple[str, ...], ...]: if not isinstance(value, (list, tuple)): raise RuntimeConfigurationError(f"{setting} must be a list of argv lists.") @@ -160,11 +166,12 @@ class RuntimeSettings: defaults.update(plugin_settings) release = getattr(django_settings, "RELEASE", None) version = getattr(release, "version", None) or django_settings.VERSION + base_dir = Path(django_settings.BASE_DIR) return cls.from_mapping( defaults, configuration_dir=django_settings.CONFIGURATION_DIR, - netbox_root=getattr(django_settings, "NETBOX_ROOT", django_settings.BASE_DIR.parent), - base_dir=django_settings.BASE_DIR, + netbox_root=_netbox_root(django_settings), + base_dir=base_dir, netbox_version=version, ) diff --git a/netbox_plugin/netbox_plugin_store/version.py b/netbox_plugin/netbox_plugin_store/version.py index 3dc1f76..485f44a 100644 --- a/netbox_plugin/netbox_plugin_store/version.py +++ b/netbox_plugin/netbox_plugin_store/version.py @@ -1 +1 @@ -__version__ = "0.1.0" +__version__ = "0.1.1" diff --git a/netbox_plugin/pyproject.toml b/netbox_plugin/pyproject.toml index f949a4d..d412d00 100644 --- a/netbox_plugin/pyproject.toml +++ b/netbox_plugin/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "netbox-plugin-store" -version = "0.1.0" +version = "0.1.1" description = "A secure NetBox 4.6 plugin lifecycle client for the MrBlake Plugin Store" readme = "README.md" requires-python = ">=3.12" diff --git a/netbox_plugin/tests/test_runtime.py b/netbox_plugin/tests/test_runtime.py new file mode 100644 index 0000000..83d896f --- /dev/null +++ b/netbox_plugin/tests/test_runtime.py @@ -0,0 +1,23 @@ +import unittest +from pathlib import Path +from types import SimpleNamespace + +import _bootstrap # noqa: F401 + +from netbox_plugin_store.runtime import _netbox_root + + +class RuntimePathTests(unittest.TestCase): + def test_netbox_root_falls_back_from_string_base_dir(self): + settings = SimpleNamespace(BASE_DIR="/opt/netbox/netbox") + + self.assertEqual(_netbox_root(settings), Path("/opt/netbox")) + + def test_explicit_netbox_root_accepts_string_paths(self): + settings = SimpleNamespace(BASE_DIR="/srv/netbox/app", NETBOX_ROOT="/opt/netbox") + + self.assertEqual(_netbox_root(settings), Path("/opt/netbox")) + + +if __name__ == "__main__": + unittest.main()