Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion netboxlabs/diode/sdk/ingester.py
Original file line number Diff line number Diff line change
Expand Up @@ -7007,7 +7007,10 @@ def __new__(
if site is not None:
if device is not None and not device.HasField("site"):
device.site.CopyFrom(site)
if cluster is not None and not cluster.HasField("scope_site"):
# scope_site shares a oneof with scope_location/region/site_group, so
# HasField("scope_site") is False while a sibling holds the scope and
# CopyFrom would silently clear it.
if cluster is not None and not cluster.WhichOneof("scope"):
cluster.scope_site.CopyFrom(site)
if role is not None:
if device is not None and not device.HasField("role"):
Expand Down
17 changes: 17 additions & 0 deletions tests/test_ingester.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
Prefix,
Role,
Site,
SiteGroup,
Tag,
VirtualDisk,
VMInterface,
Expand Down Expand Up @@ -608,6 +609,22 @@ def test_virtual_machine_instantiation_with_cluster_without_site():
assert virtual_machine.cluster.scope_site.name == "Site1"


def test_virtual_machine_instantiation_keeps_cluster_scope_site_group():
"""Check VirtualMachine leaves a cluster that is already scoped to a SiteGroup untouched."""
cluster = Cluster(name="gc-us-east1", scope_site_group=SiteGroup(name="SiteGroup1"))

virtual_machine = VirtualMachine(
name="vm1",
cluster=cluster,
site=Site(name="Site1"),
)

assert cluster.WhichOneof("scope") == "scope_site_group"
assert cluster.scope_site_group.name == "SiteGroup1"
assert virtual_machine.cluster.WhichOneof("scope") == "scope_site_group"
assert virtual_machine.cluster.scope_site_group.name == "SiteGroup1"


def test_virtual_disk_instantiation_with_all_fields():
"""Check VirtualDisk instantiation with all fields."""
virtual_disk = VirtualDisk(
Expand Down
Loading