Clean up cable profiles

This commit is contained in:
Jeremy Stretch
2025-11-17 12:38:51 -05:00
parent 576c0db77d
commit 5a7f86a6f5
2 changed files with 26 additions and 21 deletions

View File

@@ -9,10 +9,8 @@ class BaseCableProfile:
a_max_connections = None a_max_connections = None
b_max_connections = None b_max_connections = None
# Number of A & B terminations must match
symmetrical = True
def clean(self, cable): def clean(self, cable):
# Enforce maximum connection limits
if self.a_max_connections and len(cable.a_terminations) > self.a_max_connections: if self.a_max_connections and len(cable.a_terminations) > self.a_max_connections:
raise ValidationError({ raise ValidationError({
'a_terminations': _( 'a_terminations': _(
@@ -31,14 +29,6 @@ class BaseCableProfile:
max=self.b_max_connections, 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): def get_mapped_position(self, side, position):
""" """
@@ -80,18 +70,19 @@ class StraightMultiCableProfile(BaseCableProfile):
class Shuffle2x2MPO8CableProfile(BaseCableProfile): class Shuffle2x2MPO8CableProfile(BaseCableProfile):
a_max_connections = 8 a_max_connections = 8
b_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): def get_mapped_position(self, side, position):
return { return self._mapping.get(position)
1: 1,
2: 2,
3: 5,
4: 6,
5: 3,
6: 4,
7: 7,
8: 8,
}.get(position)
class Shuffle4x4MPO8CableProfile(BaseCableProfile): class Shuffle4x4MPO8CableProfile(BaseCableProfile):

View File

@@ -377,12 +377,14 @@ class CablePathTests(CablePathTestCase):
a_terminations=[interfaces[0], interfaces[1]], a_terminations=[interfaces[0], interfaces[1]],
b_terminations=[frontport1], b_terminations=[frontport1],
) )
cable1.clean()
cable1.save() cable1.save()
cable2 = Cable( cable2 = Cable(
profile=CableProfileChoices.STRAIGHT_MULTI, profile=CableProfileChoices.STRAIGHT_MULTI,
a_terminations=[rearport1], a_terminations=[rearport1],
b_terminations=[interfaces[2], interfaces[3]] b_terminations=[interfaces[2], interfaces[3]]
) )
cable2.clean()
cable2.save() cable2.save()
paths = [ paths = [
@@ -456,30 +458,35 @@ class CablePathTests(CablePathTestCase):
a_terminations=[interfaces[0], interfaces[1]], a_terminations=[interfaces[0], interfaces[1]],
b_terminations=[frontport1_1] b_terminations=[frontport1_1]
) )
cable1.clean()
cable1.save() cable1.save()
cable2 = Cable( cable2 = Cable(
profile=CableProfileChoices.STRAIGHT_MULTI, profile=CableProfileChoices.STRAIGHT_MULTI,
a_terminations=[interfaces[2], interfaces[3]], a_terminations=[interfaces[2], interfaces[3]],
b_terminations=[frontport1_2] b_terminations=[frontport1_2]
) )
cable2.clean()
cable2.save() cable2.save()
cable3 = Cable( cable3 = Cable(
profile=CableProfileChoices.STRAIGHT_SINGLE, profile=CableProfileChoices.STRAIGHT_SINGLE,
a_terminations=[rearport1], a_terminations=[rearport1],
b_terminations=[rearport2] b_terminations=[rearport2]
) )
cable3.clean()
cable3.save() cable3.save()
cable4 = Cable( cable4 = Cable(
profile=CableProfileChoices.STRAIGHT_MULTI, profile=CableProfileChoices.STRAIGHT_MULTI,
a_terminations=[frontport2_1], a_terminations=[frontport2_1],
b_terminations=[interfaces[4], interfaces[5]] b_terminations=[interfaces[4], interfaces[5]]
) )
cable4.clean()
cable4.save() cable4.save()
cable5 = Cable( cable5 = Cable(
profile=CableProfileChoices.STRAIGHT_MULTI, profile=CableProfileChoices.STRAIGHT_MULTI,
a_terminations=[frontport2_2], a_terminations=[frontport2_2],
b_terminations=[interfaces[6], interfaces[7]] b_terminations=[interfaces[6], interfaces[7]]
) )
cable5.clean()
cable5.save() cable5.save()
paths = [ paths = [
@@ -592,12 +599,14 @@ class CablePathTests(CablePathTestCase):
a_terminations=[interfaces[0], interfaces[1]], a_terminations=[interfaces[0], interfaces[1]],
b_terminations=[circuittermination1] b_terminations=[circuittermination1]
) )
cable1.clean()
cable1.save() cable1.save()
cable2 = Cable( cable2 = Cable(
profile=CableProfileChoices.STRAIGHT_MULTI, profile=CableProfileChoices.STRAIGHT_MULTI,
a_terminations=[circuittermination2], a_terminations=[circuittermination2],
b_terminations=[interfaces[2], interfaces[3]] b_terminations=[interfaces[2], interfaces[3]]
) )
cable2.clean()
cable2.save() cable2.save()
# Check for two complete paths in either direction # Check for two complete paths in either direction
@@ -671,17 +680,20 @@ class CablePathTests(CablePathTestCase):
a_terminations=[interfaces[0]], a_terminations=[interfaces[0]],
b_terminations=[front_ports[0], front_ports[1]] b_terminations=[front_ports[0], front_ports[1]]
) )
cable1.clean()
cable1.save() cable1.save()
cable2 = Cable( cable2 = Cable(
a_terminations=[rear_ports[0], rear_ports[1]], a_terminations=[rear_ports[0], rear_ports[1]],
b_terminations=[rear_ports[2], rear_ports[3]] b_terminations=[rear_ports[2], rear_ports[3]]
) )
cable2.clean()
cable2.save() cable2.save()
cable3 = Cable( cable3 = Cable(
profile=CableProfileChoices.STRAIGHT_MULTI, profile=CableProfileChoices.STRAIGHT_MULTI,
a_terminations=[interfaces[1]], a_terminations=[interfaces[1]],
b_terminations=[front_ports[2], front_ports[3]] b_terminations=[front_ports[2], front_ports[3]]
) )
cable3.clean()
cable3.save() cable3.save()
# Check for one complete path in either direction # Check for one complete path in either direction
@@ -739,12 +751,14 @@ class CablePathTests(CablePathTestCase):
a_terminations=[interfaces[0], interfaces[1]], a_terminations=[interfaces[0], interfaces[1]],
b_terminations=[frontport1, frontport2] b_terminations=[frontport1, frontport2]
) )
cable1.clean()
cable1.save() cable1.save()
cable2 = Cable( cable2 = Cable(
profile=CableProfileChoices.STRAIGHT_MULTI, profile=CableProfileChoices.STRAIGHT_MULTI,
a_terminations=[rearport1, rearport2], a_terminations=[rearport1, rearport2],
b_terminations=[interfaces[2], interfaces[3]] b_terminations=[interfaces[2], interfaces[3]]
) )
cable2.clean()
cable2.save() cable2.save()
for path in CablePath.objects.all(): for path in CablePath.objects.all():