Skip to content

Commit

Permalink
Fixes #17400: Handle cablepaths directly via multiple single-position…
Browse files Browse the repository at this point in the history
… rear ports
  • Loading branch information
eriktm authored and jeremystretch committed Oct 15, 2024
1 parent 55fad2f commit 111a1ad
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
8 changes: 8 additions & 0 deletions netbox/dcim/models/cables.py
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,14 @@ def from_origin(cls, terminations):
rear_port_id=remote_terminations[0].pk,
rear_port_position__in=position_stack.pop()
)
# If all rear ports have a single position, we can just get the front ports
elif all([rp.positions == 1 for rp in remote_terminations]):
front_ports = FrontPort.objects.filter(rear_port_id__in=[rp.pk for rp in remote_terminations])

if len(front_ports) != len(remote_terminations):
# Some rear ports does not have a front port
is_split = True
break
else:
# No position indicated: path has split, so we stop at the RearPorts
is_split = True
Expand Down
43 changes: 43 additions & 0 deletions netbox/dcim/tests/test_cablepaths.py
Original file line number Diff line number Diff line change
Expand Up @@ -2060,6 +2060,49 @@ def test_221_non_symmetric_paths(self):
# Test SVG generation
CableTraceSVG(interface1).render()

def test_222_single_path_via_multiple_singleposition_rear_ports(self):
"""
[IF1] --C1-- [FP1] [RP1] --C2-- [IF2]
[FP2] [RP2]
"""
interface1 = Interface.objects.create(device=self.device, name='Interface 1')
interface2 = Interface.objects.create(device=self.device, name='Interface 2')
rearport1 = RearPort.objects.create(device=self.device, name='Rear Port 1', positions=1)
rearport2 = RearPort.objects.create(device=self.device, name='Rear Port 2', positions=1)
frontport1 = FrontPort.objects.create(
device=self.device, name='Front Port 1', rear_port=rearport1, rear_port_position=1
)
frontport2 = FrontPort.objects.create(
device=self.device, name='Front Port 2', rear_port=rearport2, rear_port_position=1
)

cable1 = Cable(
a_terminations=[interface1],
b_terminations=[frontport1, frontport2]
)
cable1.save()
self.assertEqual(CablePath.objects.count(), 1)

cable2 = Cable(
a_terminations=[rearport1, rearport2],
b_terminations=[interface2]
)
cable2.save()
self.assertEqual(CablePath.objects.count(), 2)

self.assertPathExists(
(interface1, cable1, (frontport1, frontport2), (rearport1, rearport2), cable2, interface2),
is_complete=True
)
self.assertPathExists(
(interface2, cable2, (rearport1, rearport2), (frontport1, frontport2), cable1, interface1),
is_complete=True
)

# Test SVG generation both directions
CableTraceSVG(interface1).render()
CableTraceSVG(interface2).render()

def test_301_create_path_via_existing_cable(self):
"""
[IF1] --C1-- [FP1] [RP1] --C2-- [RP2] [FP2] --C3-- [IF2]
Expand Down

0 comments on commit 111a1ad

Please sign in to comment.