From 5a7f86a6f583ba5d4fdafce568ad44d5948ca755 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Mon, 17 Nov 2025 12:38:51 -0500 Subject: [PATCH] Clean up cable profiles --- netbox/dcim/cable_profiles.py | 33 ++++++++++----------------- netbox/dcim/tests/test_cablepaths2.py | 14 ++++++++++++ 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/netbox/dcim/cable_profiles.py b/netbox/dcim/cable_profiles.py index 818c90fa8..4251cd4d9 100644 --- a/netbox/dcim/cable_profiles.py +++ b/netbox/dcim/cable_profiles.py @@ -9,10 +9,8 @@ class BaseCableProfile: a_max_connections = None b_max_connections = None - # Number of A & B terminations must match - symmetrical = True - def clean(self, cable): + # Enforce maximum connection limits if self.a_max_connections and len(cable.a_terminations) > self.a_max_connections: raise ValidationError({ 'a_terminations': _( @@ -31,14 +29,6 @@ class BaseCableProfile: max=self.b_max_connections, ) }) - if self.symmetrical and len(cable.a_terminations) != len(cable.b_terminations): - raise ValidationError({ - 'b_terminations': _( - 'Number of A and B terminations must be equal for profile {profile}' - ).format( - profile=cable.get_profile_display(), - ) - }) def get_mapped_position(self, side, position): """ @@ -80,18 +70,19 @@ class StraightMultiCableProfile(BaseCableProfile): class Shuffle2x2MPO8CableProfile(BaseCableProfile): a_max_connections = 8 b_max_connections = 8 + _mapping = { + 1: 1, + 2: 2, + 3: 5, + 4: 6, + 5: 3, + 6: 4, + 7: 7, + 8: 8, + } def get_mapped_position(self, side, position): - return { - 1: 1, - 2: 2, - 3: 5, - 4: 6, - 5: 3, - 6: 4, - 7: 7, - 8: 8, - }.get(position) + return self._mapping.get(position) class Shuffle4x4MPO8CableProfile(BaseCableProfile): diff --git a/netbox/dcim/tests/test_cablepaths2.py b/netbox/dcim/tests/test_cablepaths2.py index 8e9a4961f..c7895c6d2 100644 --- a/netbox/dcim/tests/test_cablepaths2.py +++ b/netbox/dcim/tests/test_cablepaths2.py @@ -377,12 +377,14 @@ class CablePathTests(CablePathTestCase): a_terminations=[interfaces[0], interfaces[1]], b_terminations=[frontport1], ) + cable1.clean() cable1.save() cable2 = Cable( profile=CableProfileChoices.STRAIGHT_MULTI, a_terminations=[rearport1], b_terminations=[interfaces[2], interfaces[3]] ) + cable2.clean() cable2.save() paths = [ @@ -456,30 +458,35 @@ class CablePathTests(CablePathTestCase): a_terminations=[interfaces[0], interfaces[1]], b_terminations=[frontport1_1] ) + cable1.clean() cable1.save() cable2 = Cable( profile=CableProfileChoices.STRAIGHT_MULTI, a_terminations=[interfaces[2], interfaces[3]], b_terminations=[frontport1_2] ) + cable2.clean() cable2.save() cable3 = Cable( profile=CableProfileChoices.STRAIGHT_SINGLE, a_terminations=[rearport1], b_terminations=[rearport2] ) + cable3.clean() cable3.save() cable4 = Cable( profile=CableProfileChoices.STRAIGHT_MULTI, a_terminations=[frontport2_1], b_terminations=[interfaces[4], interfaces[5]] ) + cable4.clean() cable4.save() cable5 = Cable( profile=CableProfileChoices.STRAIGHT_MULTI, a_terminations=[frontport2_2], b_terminations=[interfaces[6], interfaces[7]] ) + cable5.clean() cable5.save() paths = [ @@ -592,12 +599,14 @@ class CablePathTests(CablePathTestCase): a_terminations=[interfaces[0], interfaces[1]], b_terminations=[circuittermination1] ) + cable1.clean() cable1.save() cable2 = Cable( profile=CableProfileChoices.STRAIGHT_MULTI, a_terminations=[circuittermination2], b_terminations=[interfaces[2], interfaces[3]] ) + cable2.clean() cable2.save() # Check for two complete paths in either direction @@ -671,17 +680,20 @@ class CablePathTests(CablePathTestCase): a_terminations=[interfaces[0]], b_terminations=[front_ports[0], front_ports[1]] ) + cable1.clean() cable1.save() cable2 = Cable( a_terminations=[rear_ports[0], rear_ports[1]], b_terminations=[rear_ports[2], rear_ports[3]] ) + cable2.clean() cable2.save() cable3 = Cable( profile=CableProfileChoices.STRAIGHT_MULTI, a_terminations=[interfaces[1]], b_terminations=[front_ports[2], front_ports[3]] ) + cable3.clean() cable3.save() # Check for one complete path in either direction @@ -739,12 +751,14 @@ class CablePathTests(CablePathTestCase): a_terminations=[interfaces[0], interfaces[1]], b_terminations=[frontport1, frontport2] ) + cable1.clean() cable1.save() cable2 = Cable( profile=CableProfileChoices.STRAIGHT_MULTI, a_terminations=[rearport1, rearport2], b_terminations=[interfaces[2], interfaces[3]] ) + cable2.clean() cable2.save() for path in CablePath.objects.all():