feat: tenant group VRFs for switch networks, remembered network decisions, in-app updates
- Networks tab offers the VRFs of the switch's tenant group and finds existing prefixes there; network decisions are stored per profile and shared by all switches (per-switch choices are migrated) - Decided networks and VLANs sit in a collapsed, editable section - Check the Gitea releases on start (or on demand in the settings); after confirmation the installer runs silently and restarts the application, the portable EXE swaps itself; a version can be skipped - Installer restarts the application after a silent update Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
3db5e83f0a
commit
e499d854a9
13 files changed
+600
-101
No files matched your search
@@ -136,7 +136,8 @@ def test_missing_vlans_prefixes_and_vrfs_are_only_created_when_approved():
|
||||
plan = plan_switch_sync(nb, switch, snapshot)
|
||||
assert [(item["vid"], item["netbox_id"], item["method"], item["new_name"]) for item in plan["vlans"]] == [
|
||||
(1, None, "new", "VLAN1"), (10, 110, "vid", "VLAN10"), (20, None, "new", "Clients")]
|
||||
assert plan["networks"] == [{"network": "10.1.0.0/24", "vrf": "", "existing_vrfs": [], "create": True}]
|
||||
assert plan["networks"] == [{"network": "10.1.0.0/24", "vrf_id": 0, "vrf_name": "", "existing": [],
|
||||
"create": True, "stored": False}]
|
||||
|
||||
# Not approved: nothing is created, only the existing VLAN 10 is assigned.
|
||||
report = sync_snapshot_to_netbox(nb, switch, snapshot, create_cables=False, dry_run=True)
|
||||
@@ -146,8 +147,7 @@ def test_missing_vlans_prefixes_and_vrfs_are_only_created_when_approved():
|
||||
assert nb.dcim.interfaces.get(1).untagged_vlan == 110 and nb.dcim.interfaces.get(1).mode == "access"
|
||||
assert nb.ipam.ip_addresses.created[0]["tenant"] == 7 and nb.ipam.ip_addresses.created[0]["vrf"] is None
|
||||
|
||||
switch.update({"vlan_map": {"20": {"action": "new", "name": "Clients"}}, "create_prefixes": ["10.1.0.0/24"],
|
||||
"network_vrfs": {"10.1.0.0/24": "Kunde-Mgmt"}})
|
||||
switch.update({"vlan_map": {"20": {"action": "new", "name": "Clients"}}, "network_map": {"10.1.0.0/24": {"vrf_id": None, "vrf_name": "Kunde-Mgmt", "create": True}}})
|
||||
report = sync_snapshot_to_netbox(nb, switch, snapshot, create_cables=False)
|
||||
assert report["errors"] == []
|
||||
assert nb.ipam.vrfs.created == [{"name": "Kunde-Mgmt", "tenant": 7}]
|
||||
@@ -242,3 +242,41 @@ def test_vlan_decisions_move_from_switches_to_the_profile(tmp_path):
|
||||
loaded = store.load()[0]["Kunde"]
|
||||
assert loaded["vlan_map"] == {"5": {"action": "ignore"}}
|
||||
assert "vlan_map" not in loaded["switches"][0] and "create_vlans" not in loaded["switches"][0]
|
||||
|
||||
|
||||
def test_vrfs_of_the_tenant_group_are_offered_and_found():
|
||||
nb, switch, snapshot = _numbered_setup()
|
||||
group = SimpleNamespace(id=3, name="Kunde")
|
||||
rz = SimpleNamespace(id=8, name="RZ")
|
||||
nb.ipam.vrfs.records += [
|
||||
Record(nb.ipam.vrfs, id=60, name="Mgmt", tenant=rz, tenant_group=group),
|
||||
Record(nb.ipam.vrfs, id=61, name="Fremd", tenant=SimpleNamespace(id=99), tenant_group=None),
|
||||
]
|
||||
nb.ipam.prefixes.records.append(Record(nb.ipam.prefixes, id=70, prefix="10.10.167.0/24", vrf=SimpleNamespace(id=60)))
|
||||
snapshot["interfaces"][0]["ip_addresses"] = ["10.10.167.5/24"]
|
||||
|
||||
plan = plan_switch_sync(nb, switch, snapshot)
|
||||
assert plan["vrfs"] == [{"id": 60, "label": "Mgmt (RZ)"}], "group VRFs only"
|
||||
assert plan["networks"][0] == {"network": "10.10.167.0/24", "vrf_id": 60, "vrf_name": "", "existing": [60],
|
||||
"create": True, "stored": False}
|
||||
|
||||
switch["network_map"] = {"10.10.167.0/24": {"vrf_id": 60, "vrf_name": "", "create": False}}
|
||||
report = sync_snapshot_to_netbox(nb, switch, snapshot, create_cables=False)
|
||||
assert report["errors"] == [] and report["prefixes_created"] == 0 and nb.ipam.vrfs.created == []
|
||||
assert nb.ipam.ip_addresses.created[0]["vrf"] == 60
|
||||
assert plan_switch_sync(nb, switch, snapshot)["networks"][0]["stored"] is True
|
||||
|
||||
|
||||
def test_legacy_network_choices_still_work_and_migrate(tmp_path):
|
||||
nb, switch, snapshot = _numbered_setup()
|
||||
snapshot["interfaces"][0]["ip_addresses"] = ["10.1.0.1/24"]
|
||||
switch.update({"network_vrfs": {"10.1.0.0/24": ""}, "create_prefixes": ["10.1.0.0/24"]})
|
||||
report = sync_snapshot_to_netbox(nb, switch, snapshot, create_cables=False, dry_run=True)
|
||||
assert report["prefixes_created"] == 1
|
||||
|
||||
from netbox_sync.core.config import ProfileStore
|
||||
store = ProfileStore(tmp_path / "config.json")
|
||||
store.save({"Kunde": {"name": "Kunde", "switches": [dict(switch, password="x")]}}, "Kunde")
|
||||
loaded = store.load()[0]["Kunde"]
|
||||
assert loaded["network_map"] == {"10.1.0.0/24": {"vrf_id": None, "vrf_name": "", "create": True}}
|
||||
assert "network_vrfs" not in loaded["switches"][0]
|
||||
@@ -0,0 +1,75 @@
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
|
||||
from netbox_sync.core import updater
|
||||
|
||||
RELEASE = {
|
||||
"tag_name": "v4.7.0", "name": "Netbox-Import-Desktop v4.7.0", "body": "- neu", "draft": False,
|
||||
"prerelease": False, "html_url": "https://example.invalid/releases/tag/v4.7.0",
|
||||
"assets": [
|
||||
{"name": "NetBox VM Import.exe", "size": 4, "browser_download_url": "https://example.invalid/portable"},
|
||||
{"name": "NetBoxSynchronizer-Setup-4.7.0.exe", "size": 4, "browser_download_url": "https://example.invalid/setup"},
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
class _Response:
|
||||
def __init__(self, payload=None, chunks=(), length=None):
|
||||
self.payload, self.chunks = payload, chunks
|
||||
self.headers = {"Content-Length": str(length)} if length else {}
|
||||
|
||||
def raise_for_status(self):
|
||||
return None
|
||||
|
||||
def json(self):
|
||||
return self.payload
|
||||
|
||||
def iter_content(self, _size):
|
||||
return iter(self.chunks)
|
||||
|
||||
def __enter__(self):
|
||||
return self
|
||||
|
||||
def __exit__(self, *_args):
|
||||
return False
|
||||
|
||||
|
||||
def test_versions_are_compared_numerically():
|
||||
assert updater.parse_version("v4.10.0") > updater.parse_version("4.9.3")
|
||||
assert updater.parse_version("v5") == (5, 0, 0)
|
||||
|
||||
|
||||
def test_newer_release_is_offered_with_matching_assets(monkeypatch):
|
||||
monkeypatch.setattr(updater.requests, "get", lambda *_a, **_k: _Response(RELEASE))
|
||||
release = updater.check_for_update("4.6.0")
|
||||
assert release["version"] == "4.7.0" and release["notes"] == "- neu"
|
||||
assert updater.pick_asset(release, "portable")[0] == "NetBox VM Import.exe"
|
||||
assert updater.pick_asset(release, "installer")[0] == "NetBoxSynchronizer-Setup-4.7.0.exe"
|
||||
assert updater.check_for_update("4.7.0") is None
|
||||
monkeypatch.setattr(updater.requests, "get", lambda *_a, **_k: _Response(dict(RELEASE, prerelease=True)))
|
||||
assert updater.check_for_update("4.6.0") is None
|
||||
|
||||
|
||||
def test_incomplete_download_is_discarded(monkeypatch, tmp_path):
|
||||
monkeypatch.setattr(updater.requests, "get", lambda *_a, **_k: _Response(chunks=[b"ab"]))
|
||||
with pytest.raises(updater.UpdateError):
|
||||
updater.download({"url": "x", "size": 4}, tmp_path / "setup.exe")
|
||||
assert list(tmp_path.iterdir()) == []
|
||||
monkeypatch.setattr(updater.requests, "get", lambda *_a, **_k: _Response(chunks=[b"ab", b"cd"]))
|
||||
target = updater.download({"url": "x", "size": 4}, tmp_path / "setup.exe")
|
||||
assert target.read_bytes() == b"abcd"
|
||||
|
||||
|
||||
def test_portable_exe_is_swapped_and_restarted(monkeypatch, tmp_path):
|
||||
exe = tmp_path / "NetBox VM Import.exe"
|
||||
exe.write_bytes(b"old")
|
||||
new = tmp_path / "NetBox VM Import.new.exe"
|
||||
new.write_bytes(b"new")
|
||||
started = []
|
||||
monkeypatch.setattr(sys, "executable", str(exe))
|
||||
monkeypatch.setattr(updater.subprocess, "Popen", lambda args, **_kwargs: started.append(args))
|
||||
updater.apply_portable(new)
|
||||
assert exe.read_bytes() == b"new" and not new.exists()
|
||||
assert (tmp_path / "NetBox VM Import.old.exe").read_bytes() == b"old"
|
||||
assert started == [[str(exe)]]
|
||||
Reference in new issue
Block a user