feat: rebuild app with Qt UI, installer and safer switch sync
- Replace the Tkinter app with a PySide6 UI: sidebar navigation, central profile switcher, autosave, light/dark theme, background tasks with progress and cancel, toasts and a filterable activity log - Split logic into netbox_sync.core (config, NetBox, VMware/Proxmox, VM import, switches) and netbox_sync.ui - Replace the three-dialog import chain with a four-step import wizard; support the global VRF and match VMs per cluster - Expose the previously unreachable VRF/prefix batch tool - Switch sync: no silent LLDP config changes, TOFU host key checks, platform auto-detection, Comware name normalization, fixed AOS-S and Comware LLDP parsing, FQDN/management-IP cable matching, dry-run preview, interface types only set on create - Add PyInstaller onedir spec, Inno Setup installer and build.ps1 - Add pytest suite with an in-memory NetBox fake - Stop tracking the built exe Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
e983791baa
commit
4878275f2a
50 files changed
+7960
-3186
No files matched your search
@@ -0,0 +1,6 @@
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
HERE = Path(__file__).resolve().parent
|
||||
sys.path.insert(0, str(HERE.parent))
|
||||
sys.path.insert(0, str(HERE))
|
||||
@@ -0,0 +1,77 @@
|
||||
"""Tiny in-memory stand-in for the parts of pynetbox the sync code uses."""
|
||||
|
||||
import itertools
|
||||
from types import SimpleNamespace
|
||||
|
||||
_ids = itertools.count(1000)
|
||||
|
||||
|
||||
class Record(SimpleNamespace):
|
||||
def __init__(self, endpoint=None, **values):
|
||||
super().__init__(**values)
|
||||
self._endpoint = endpoint
|
||||
|
||||
def update(self, values):
|
||||
changed = any(getattr(self, key, None) != value for key, value in values.items())
|
||||
for key, value in values.items():
|
||||
setattr(self, key, value)
|
||||
if changed and self._endpoint is not None:
|
||||
self._endpoint.updates.append((self.id, dict(values)))
|
||||
return changed
|
||||
|
||||
|
||||
def _matches(record, key, value):
|
||||
if key == "brief":
|
||||
return True
|
||||
if key.endswith("__ie"):
|
||||
return str(getattr(record, key[:-4], "")).casefold() == str(value).casefold()
|
||||
if key == "vrf_id":
|
||||
vrf = getattr(record, "vrf", None)
|
||||
vrf_id = vrf if isinstance(vrf, int) else getattr(vrf, "id", None)
|
||||
return (vrf_id is None) if value == "null" else vrf_id == value
|
||||
if key == "address":
|
||||
return str(getattr(record, "address", "")).split("/")[0] == str(value).split("/")[0]
|
||||
if key.endswith("_id") and not hasattr(record, key):
|
||||
related = getattr(record, key[:-3], None)
|
||||
return getattr(related, "id", related) == value
|
||||
return getattr(record, key, None) == value
|
||||
|
||||
|
||||
class Endpoint:
|
||||
def __init__(self, records=()):
|
||||
self.records = []
|
||||
self.created = []
|
||||
self.updates = []
|
||||
for values in records:
|
||||
self.records.append(Record(self, **values))
|
||||
|
||||
def all(self):
|
||||
return list(self.records)
|
||||
|
||||
def filter(self, **kwargs):
|
||||
return [record for record in self.records if all(_matches(record, k, v) for k, v in kwargs.items())]
|
||||
|
||||
def get(self, *args, **kwargs):
|
||||
if args:
|
||||
kwargs = {"id": args[0]}
|
||||
found = self.filter(**kwargs)
|
||||
if len(found) > 1:
|
||||
raise ValueError("get() returned more than one result")
|
||||
return found[0] if found else None
|
||||
|
||||
def create(self, payload):
|
||||
record = Record(self, id=next(_ids), cable=None, **payload)
|
||||
self.records.append(record)
|
||||
self.created.append(payload)
|
||||
return record
|
||||
|
||||
|
||||
class FakeNetBox:
|
||||
netbox_version = "4.3.0"
|
||||
|
||||
def __init__(self):
|
||||
self.dcim = SimpleNamespace(devices=Endpoint(), interfaces=Endpoint(), cables=Endpoint(),
|
||||
mac_addresses=Endpoint(), platforms=Endpoint())
|
||||
self.ipam = SimpleNamespace(ip_addresses=Endpoint(), prefixes=Endpoint(), vrfs=Endpoint())
|
||||
self.virtualization = SimpleNamespace(clusters=Endpoint(), virtual_machines=Endpoint(), interfaces=Endpoint())
|
||||
self.tenancy = SimpleNamespace(tenants=Endpoint())
|
||||
@@ -0,0 +1,59 @@
|
||||
import json
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
|
||||
from netbox_sync.core.config import DEFAULT_SETTINGS, ProfileStore
|
||||
|
||||
pytestmark = pytest.mark.skipif(sys.platform != "win32", reason="DPAPI is Windows-only")
|
||||
|
||||
|
||||
def test_roundtrip_encrypts_secrets(tmp_path):
|
||||
store = ProfileStore(tmp_path / "config.json")
|
||||
profiles = {
|
||||
"Kunde A": {
|
||||
"name": "Kunde A",
|
||||
"netbox_url": "https://netbox.example",
|
||||
"netbox_token": "token-123",
|
||||
"netbox_ignore_ssl": True,
|
||||
"sources": [{"id": "s1", "type": "proxmox", "name": "PVE", "url": "https://pve", "token_id": "a@pve!b",
|
||||
"token_secret": "geheim", "enabled": True}],
|
||||
"switches": [{"id": "w1", "name": "sw1", "device_id": 5, "platform": "auto", "host": "10.0.0.1",
|
||||
"port": 22, "username": "admin", "password": "pw", "enabled": True, "_runtime": "x"}],
|
||||
}
|
||||
}
|
||||
settings = dict(DEFAULT_SETTINGS, theme="dark")
|
||||
store.save(profiles, "Kunde A", settings)
|
||||
|
||||
raw = (tmp_path / "config.json").read_text(encoding="utf-8")
|
||||
assert "token-123" not in raw and "geheim" not in raw and '"pw"' not in raw
|
||||
assert "_runtime" not in raw
|
||||
|
||||
loaded, active, loaded_settings = store.load()
|
||||
assert active == "Kunde A"
|
||||
assert loaded_settings["theme"] == "dark"
|
||||
assert loaded["Kunde A"]["netbox_token"] == "token-123"
|
||||
assert loaded["Kunde A"]["sources"][0]["token_secret"] == "geheim"
|
||||
assert loaded["Kunde A"]["switches"][0]["password"] == "pw"
|
||||
|
||||
|
||||
def test_unreadable_secret_does_not_block_loading(tmp_path):
|
||||
path = tmp_path / "config.json"
|
||||
path.write_text(json.dumps({
|
||||
"version": 4,
|
||||
"active_profile": "X",
|
||||
"profiles": [{"name": "X", "netbox_url": "u", "netbox_token_encrypted": "AAAA", "sources": [], "switches": []}],
|
||||
}), encoding="utf-8")
|
||||
store = ProfileStore(path)
|
||||
profiles, _active, settings = store.load()
|
||||
assert profiles["X"]["netbox_token"] == ""
|
||||
assert store.decrypt_failures
|
||||
assert settings == DEFAULT_SETTINGS
|
||||
|
||||
|
||||
def test_legacy_v1_migration(tmp_path):
|
||||
path = tmp_path / "config.json"
|
||||
path.write_text(json.dumps({"esxi_host": "vc", "esxi_user": "u", "esxi_password": "p", "netbox_url": "nb"}),
|
||||
encoding="utf-8")
|
||||
profiles, _active, _settings = ProfileStore(path).load()
|
||||
assert profiles["Standard"]["sources"][0]["host"] == "vc"
|
||||
@@ -0,0 +1,54 @@
|
||||
from types import SimpleNamespace
|
||||
|
||||
from fake_netbox import FakeNetBox, Record
|
||||
|
||||
from netbox_sync.core.switches import build_snapshot, sync_snapshot_to_netbox
|
||||
from test_switches import COMWARE_BRIEF, COMWARE_LLDP
|
||||
|
||||
|
||||
def _setup():
|
||||
nb = FakeNetBox()
|
||||
tenant = SimpleNamespace(id=7, name="Muster")
|
||||
nb.dcim.devices.records += [
|
||||
Record(nb.dcim.devices, id=1, name="access-01", tenant=tenant),
|
||||
Record(nb.dcim.devices, id=2, name="core-sw", tenant=None),
|
||||
]
|
||||
# Interfaces created from the NetBox device type use full Comware names.
|
||||
for index, name in enumerate(("GigabitEthernet1/0/1", "GigabitEthernet1/0/2"), start=1):
|
||||
nb.dcim.interfaces.records.append(Record(nb.dcim.interfaces, id=index, name=name, device=SimpleNamespace(id=1),
|
||||
type=SimpleNamespace(value="1000base-x-sfp"), enabled=True, cable=None))
|
||||
nb.dcim.interfaces.records.append(Record(nb.dcim.interfaces, id=50, name="GigabitEthernet1/0/24",
|
||||
device=SimpleNamespace(id=2), enabled=True, cable=None))
|
||||
snapshot = build_snapshot({"interfaces": COMWARE_BRIEF, "neighbors": COMWARE_LLDP}, "hpe_comware")
|
||||
switch = {"id": "s", "name": "access-01", "device_id": 1}
|
||||
return nb, switch, snapshot
|
||||
|
||||
|
||||
def test_dry_run_writes_nothing():
|
||||
nb, switch, snapshot = _setup()
|
||||
report = sync_snapshot_to_netbox(nb, switch, snapshot, create_cables=True, dry_run=True)
|
||||
assert report["errors"] == []
|
||||
assert report["interfaces_created"] == 1 # Ten-GigabitEthernet1/0/49
|
||||
assert report["interfaces_updated"] == 1 # GE1/0/2 is ADM -> disable
|
||||
assert report["interfaces_unchanged"] == 1
|
||||
assert report["cables_created"] == 1 # FQDN "core-sw.example.local" -> core-sw
|
||||
assert nb.dcim.interfaces.created == [] and nb.dcim.interfaces.updates == [] and nb.dcim.cables.created == []
|
||||
|
||||
|
||||
def test_sync_matches_short_names_and_keeps_existing_types():
|
||||
nb, switch, snapshot = _setup()
|
||||
report = sync_snapshot_to_netbox(nb, switch, snapshot, create_cables=True)
|
||||
assert report["errors"] == []
|
||||
names = [payload["name"] for payload in nb.dcim.interfaces.created]
|
||||
assert names == ["Ten-GigabitEthernet1/0/49"], "no GE1/0/x duplicates next to template interfaces"
|
||||
assert nb.dcim.interfaces.created[0]["type"] == "10gbase-x-sfpp"
|
||||
# Only the admin state changed – the template type must not be overwritten.
|
||||
assert nb.dcim.interfaces.updates == [(2, {"enabled": False})]
|
||||
cable = nb.dcim.cables.created[0]
|
||||
assert cable["a_terminations"][0]["object_id"] == 1
|
||||
assert cable["b_terminations"][0]["object_id"] == 50
|
||||
|
||||
# A second run finds nothing left to do.
|
||||
nb.dcim.interfaces.get(1).cable = True
|
||||
again = sync_snapshot_to_netbox(nb, switch, snapshot, create_cables=True, dry_run=True)
|
||||
assert again["changes"] == []
|
||||
@@ -0,0 +1,203 @@
|
||||
from netbox_sync.core import switches
|
||||
from netbox_sync.core.switches import (
|
||||
CLI_PROMPT,
|
||||
COMWARE_PROMPT,
|
||||
build_snapshot,
|
||||
interface_key,
|
||||
netbox_interface_type,
|
||||
parse_interface_ips,
|
||||
parse_interfaces,
|
||||
parse_neighbors,
|
||||
suggest_platform,
|
||||
)
|
||||
|
||||
AOS_BRIEF = """
|
||||
Status and Counters - Port Status
|
||||
|
||||
| Intrusion Flow Bcast
|
||||
Port Type | Alert Enabled Status Mode Ctrl Limit
|
||||
------------ ---------- + --------- ------- ------ ---------- ----- ------
|
||||
1 100/1000T | No Yes Up 1000FDx off 0
|
||||
2 100/1000T | No No Down 1000FDx off 0
|
||||
49 SFP+SR | No Yes Up 10GigFD off 0
|
||||
Trk1 | No Yes Up 1000FDx off 0
|
||||
switch#
|
||||
"""
|
||||
|
||||
CX_BRIEF = """
|
||||
--------------------------------------------------------------------------------------------------------
|
||||
Port Native Mode Type Enabled Status Reason Speed Description
|
||||
VLAN (Mb/s)
|
||||
--------------------------------------------------------------------------------------------------------
|
||||
1/1/1 1 access 1GbT yes up 1000 Uplink
|
||||
1/1/2 1 access 1GbT no down Administratively down -- --
|
||||
1/1/49 -- routed SFP+DAC1 yes up 10000 --
|
||||
core-sw#
|
||||
"""
|
||||
|
||||
COMWARE_BRIEF = """
|
||||
Brief information on interfaces in bridge mode:
|
||||
Link: ADM - administratively down; Stby - standby
|
||||
Speed: (a) - auto
|
||||
Duplex: (a)/A - auto; H - half; F - full
|
||||
Type: A - access; T - trunk; H - hybrid
|
||||
Interface Link Speed Duplex Type PVID Description
|
||||
GE1/0/1 UP 1G(a) F(a) A 1
|
||||
GE1/0/2 ADM auto A A 1
|
||||
XGE1/0/49 UP 10G F T 1
|
||||
<comware>
|
||||
"""
|
||||
|
||||
COMWARE_LLDP = """
|
||||
LLDP neighbor-information of port 1[GigabitEthernet1/0/1]:
|
||||
LLDP agent nearest-bridge:
|
||||
LLDP neighbor index : 1
|
||||
Update time : 0 days, 0 hours, 1 minutes, 1 seconds
|
||||
Chassis type : MAC address
|
||||
Chassis ID : 0011-2233-4455
|
||||
Port ID type : Interface name
|
||||
Port ID : GigabitEthernet1/0/24
|
||||
Time to live : 121
|
||||
Port description : GigabitEthernet1/0/24 Interface
|
||||
System name : core-sw.example.local
|
||||
Management address type : IPv4
|
||||
Management address : 192.0.2.1
|
||||
<comware>
|
||||
"""
|
||||
|
||||
CX_LLDP = """
|
||||
Port : 1/1/1
|
||||
Neighbor Entries : 1
|
||||
Neighbor Chassis-Name : access-01
|
||||
Neighbor Chassis-ID : 00:11:22:33:44:55
|
||||
Neighbor Port-ID : 1/1/52
|
||||
Neighbor Port-Desc : 1/1/52
|
||||
Neighbor Management-Address : 10.0.0.12
|
||||
|
||||
Port : 1/1/2
|
||||
Neighbor Entries : 1
|
||||
Neighbor Chassis-Name : esx01
|
||||
Neighbor Port-ID : vmnic0
|
||||
core-sw#
|
||||
"""
|
||||
|
||||
AOS_LLDP = """
|
||||
LLDP Remote Device Information Detail
|
||||
|
||||
Local Port : 24
|
||||
ChassisType : mac-address
|
||||
ChassisId : 00 11 22 33 44 55
|
||||
PortType : local
|
||||
PortId : 1/1/1
|
||||
SysName : core-sw
|
||||
System Descr : Aruba JL...
|
||||
PortDescr : 1/1/1
|
||||
switch#
|
||||
"""
|
||||
|
||||
|
||||
def test_aos_brief_uses_columns_and_no_garbage_description():
|
||||
interfaces = {item["name"]: item for item in parse_interfaces(AOS_BRIEF, "aruba_aos")}
|
||||
assert set(interfaces) == {"1", "2", "49", "Trk1"}
|
||||
assert interfaces["1"]["enabled"] and interfaces["1"]["connected"]
|
||||
assert interfaces["1"]["speed_mbps"] == 1000
|
||||
assert not interfaces["2"]["enabled"] and not interfaces["2"]["connected"]
|
||||
assert interfaces["49"]["speed_mbps"] == 10000
|
||||
assert all(item["description"] == "" for item in interfaces.values())
|
||||
assert netbox_interface_type(interfaces["49"]) == "10gbase-x-sfpp"
|
||||
assert netbox_interface_type(interfaces["1"]) == "1000base-t"
|
||||
assert netbox_interface_type(interfaces["Trk1"]) == "lag"
|
||||
|
||||
|
||||
def test_cx_brief():
|
||||
interfaces = {item["name"]: item for item in parse_interfaces(CX_BRIEF, "aruba_cx")}
|
||||
assert set(interfaces) == {"1/1/1", "1/1/2", "1/1/49"}
|
||||
assert interfaces["1/1/1"]["connected"]
|
||||
assert not interfaces["1/1/2"]["enabled"]
|
||||
assert netbox_interface_type(interfaces["1/1/49"]) == "10gbase-x-sfpp"
|
||||
|
||||
|
||||
def test_comware_names_are_expanded_and_adm_is_disabled():
|
||||
interfaces = {item["name"]: item for item in parse_interfaces(COMWARE_BRIEF, "hpe_comware")}
|
||||
assert set(interfaces) == {"GigabitEthernet1/0/1", "GigabitEthernet1/0/2", "Ten-GigabitEthernet1/0/49"}
|
||||
assert not interfaces["GigabitEthernet1/0/2"]["enabled"]
|
||||
assert interfaces["GigabitEthernet1/0/1"]["speed_mbps"] == 1000
|
||||
|
||||
|
||||
def test_interface_key_matches_vendor_spellings():
|
||||
assert interface_key("GE1/0/1") == interface_key("GigabitEthernet1/0/1") == interface_key("Gi1/0/1")
|
||||
assert interface_key("XGE1/0/49") == interface_key("Ten-GigabitEthernet1/0/49") == interface_key("Te1/0/49")
|
||||
assert interface_key("Vlan-interface10") == interface_key("vlan10") == interface_key("Vlan 10")
|
||||
assert interface_key("1/1/1") == "1/1/1"
|
||||
assert interface_key("1/1/1") != interface_key("1/1/11")
|
||||
|
||||
|
||||
def test_comware_lldp_neighbor_and_snapshot_link():
|
||||
neighbors = parse_neighbors(COMWARE_LLDP)
|
||||
assert neighbors == [{
|
||||
"local_port": "GigabitEthernet1/0/1",
|
||||
"system_name": "core-sw.example.local",
|
||||
"remote_port": "GigabitEthernet1/0/24",
|
||||
"port_description": "GigabitEthernet1/0/24 Interface",
|
||||
"management_ip": "192.0.2.1",
|
||||
"protocol": "LLDP",
|
||||
}]
|
||||
snapshot = build_snapshot(
|
||||
{"interfaces": COMWARE_BRIEF, "neighbors": COMWARE_LLDP, "ipv4_interfaces": "", "ipv6_interfaces": ""},
|
||||
"hpe_comware",
|
||||
)
|
||||
linked = next(item for item in snapshot["interfaces"] if item["name"] == "GigabitEthernet1/0/1")
|
||||
assert linked["neighbor"]["system_name"] == "core-sw.example.local"
|
||||
|
||||
|
||||
def test_cx_and_aos_lldp_records():
|
||||
cx = parse_neighbors(CX_LLDP)
|
||||
assert [(item["local_port"], item["system_name"], item["remote_port"]) for item in cx] == [
|
||||
("1/1/1", "access-01", "1/1/52"),
|
||||
("1/1/2", "esx01", "vmnic0"),
|
||||
]
|
||||
assert cx[0]["management_ip"] == "10.0.0.12"
|
||||
aos = parse_neighbors(AOS_LLDP)
|
||||
assert [(item["local_port"], item["system_name"], item["remote_port"]) for item in aos] == [
|
||||
("24", "core-sw", "1/1/1"),
|
||||
]
|
||||
|
||||
|
||||
def test_ip_parsing_creates_virtual_interfaces():
|
||||
ipv4 = """
|
||||
Interface IP Address/Mask VRF Status
|
||||
---------------------------------------------------------
|
||||
vlan10 10.0.10.1/24 default up
|
||||
1/1/49 10.255.0.1/31 default up
|
||||
core-sw#
|
||||
"""
|
||||
entries = parse_interface_ips(ipv4, "", "aruba_cx")
|
||||
assert {"interface": "vlan10", "address": "10.0.10.1/24"} in entries
|
||||
snapshot = build_snapshot({"interfaces": CX_BRIEF, "neighbors": "", "ipv4_interfaces": ipv4}, "aruba_cx")
|
||||
vlan = next(item for item in snapshot["interfaces"] if item["name"] == "vlan10")
|
||||
assert vlan["virtual"] and vlan["ip_addresses"] == ["10.0.10.1/24"]
|
||||
uplink = next(item for item in snapshot["interfaces"] if item["name"] == "1/1/49")
|
||||
assert uplink["ip_addresses"] == ["10.255.0.1/31"]
|
||||
|
||||
|
||||
def test_prompts():
|
||||
assert CLI_PROMPT.search("output\nswitch# ")
|
||||
assert CLI_PROMPT.search("output\n<comware>")
|
||||
assert CLI_PROMPT.search("output\n[comware]")
|
||||
assert not CLI_PROMPT.search("LLDP neighbor-information of port 1[GigabitEthernet1/0/1]:\n")
|
||||
assert COMWARE_PROMPT.search("banner\n<HPE-5130>")
|
||||
assert not COMWARE_PROMPT.search("banner\ncx-switch# ")
|
||||
|
||||
|
||||
def test_suggest_platform():
|
||||
assert suggest_platform("Aruba", "6100 48G CL4 4SFP+") == "aruba_cx"
|
||||
assert suggest_platform("HPE", "Aruba 2930F-48G") == "aruba_aos"
|
||||
assert suggest_platform("HPE", "FlexNetwork 5130 24G") == "hpe_comware"
|
||||
assert suggest_platform("ArubaOS-CX") == "aruba_cx"
|
||||
assert suggest_platform("Cisco", "C9300") == "auto"
|
||||
|
||||
|
||||
def test_speed_parsing():
|
||||
assert switches.speed_mbps("1000FDx") == 1000
|
||||
assert switches.speed_mbps("10GigFD") == 10000
|
||||
assert switches.speed_mbps("UP 1G(a) F(a)") == 1000
|
||||
@@ -0,0 +1,60 @@
|
||||
from types import SimpleNamespace
|
||||
|
||||
from fake_netbox import FakeNetBox, Record
|
||||
|
||||
from netbox_sync.core.vm_sync import VMSyncEngine
|
||||
|
||||
|
||||
def _engine():
|
||||
nb = FakeNetBox()
|
||||
nb.virtualization.clusters.records.append(Record(nb.virtualization.clusters, id=1, name="RZ1",
|
||||
tenant=SimpleNamespace(id=10, name="Muster")))
|
||||
nb.tenancy.tenants.records.append(Record(nb.tenancy.tenants, id=10, name="Muster"))
|
||||
nb.ipam.vrfs.records.append(Record(nb.ipam.vrfs, id=5, name="Muster - Prod", rd=None,
|
||||
tenant=SimpleNamespace(id=10)))
|
||||
engine = VMSyncEngine(nb)
|
||||
engine.load_targets()
|
||||
return nb, engine
|
||||
|
||||
|
||||
VM = {
|
||||
"name": "web01", "source": "vc", "status": "active", "vcpus": 2, "memory": 4096, "disk": 40960,
|
||||
"guest_os": "Debian", "kind": "VM",
|
||||
"interfaces": [{"name": "NIC-0", "mac": "00:50:56:aa:bb:cc", "ips": ["10.20.30.11/24", "fe80::1"]}],
|
||||
}
|
||||
|
||||
|
||||
def test_load_targets_and_cluster_tenant():
|
||||
_nb, engine = _engine()
|
||||
assert engine.clusters == {"RZ1": 1}
|
||||
assert engine.cluster_tenants["RZ1"]["name"] == "Muster"
|
||||
assert [vrf.name for vrf in engine.tenant_vrfs(10)] == ["Muster - Prod"]
|
||||
|
||||
|
||||
def test_detect_and_import_creates_prefix_vm_ip_and_mac():
|
||||
nb, engine = _engine()
|
||||
missing = engine.detect_missing_networks([VM], tenant_id=10, default_vrf_id=5)
|
||||
assert [str(item["suggested_network"]) for item in missing] == ["10.20.30.0/24"]
|
||||
engine.apply_network_plan([{"network": "10.20.30.0/24", "vrf_id": 5, "create_vrf": False, "vrf_name": None}], 10)
|
||||
|
||||
assert engine.sync_vm(VM, cluster_id=1, tenant_id=10, vrf_id=5) == "created"
|
||||
assert nb.ipam.prefixes.created == [{"prefix": "10.20.30.0/24", "status": "active", "tenant": 10, "vrf": 5}]
|
||||
ip = nb.ipam.ip_addresses.created[0]
|
||||
assert ip["address"] == "10.20.30.11/24" and ip["vrf"] == 5 and ip["tenant"] == 10
|
||||
assert nb.dcim.mac_addresses.created[0]["mac_address"] == "00:50:56:AA:BB:CC"
|
||||
vm = nb.virtualization.virtual_machines.records[0]
|
||||
assert vm.primary_ip4 == nb.ipam.ip_addresses.records[0].id
|
||||
|
||||
# Second run updates instead of duplicating.
|
||||
assert engine.sync_vm(VM, cluster_id=1, tenant_id=10, vrf_id=5) == "updated"
|
||||
assert len(nb.virtualization.virtual_machines.records) == 1
|
||||
assert len(nb.ipam.ip_addresses.records) == 1
|
||||
|
||||
|
||||
def test_global_vrf_import():
|
||||
nb, engine = _engine()
|
||||
engine.detect_missing_networks([VM], tenant_id=10, default_vrf_id=None)
|
||||
engine.apply_network_plan([{"network": "10.20.30.0/24", "vrf_id": None, "create_vrf": False, "vrf_name": None}], 10)
|
||||
engine.sync_vm(VM, cluster_id=1, tenant_id=10, vrf_id=None)
|
||||
assert "vrf" not in nb.ipam.prefixes.created[0]
|
||||
assert nb.ipam.ip_addresses.created[0]["vrf"] is None
|
||||
Reference in new issue
Block a user