Fix NetBox string path compatibility
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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`:
|
||||
|
||||
@@ -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,
|
||||
)
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
__version__ = "0.1.0"
|
||||
__version__ = "0.1.1"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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()
|
||||
Reference in New Issue
Block a user