Compare commits

...

2 Commits

Author SHA1 Message Date
Jeremy Stretch
3fea22dcd0 Fix bug in Breakout2C4Px8C1PShuffleCableProfile; improve error handling 2025-12-15 14:38:34 -05:00
Jeremy Stretch
c1ce532422 Rename shuffle profiles 2025-12-15 14:30:41 -05:00
4 changed files with 46 additions and 49 deletions

View File

@@ -59,11 +59,17 @@ class BaseCableProfile:
"""
Given a terminating object, return the peer terminating object (if any) on the opposite end of the cable.
"""
connector, position = self.get_mapped_position(
termination.cable_end,
termination.cable_connector,
position
)
try:
connector, position = self.get_mapped_position(
termination.cable_end,
termination.cable_connector,
position
)
except TypeError:
raise ValueError(
f"Could not map connector {termination.cable_connector} position {position} on side "
f"{termination.cable_end}"
)
try:
ct = CableTermination.objects.get(
cable=termination.cable,
@@ -296,7 +302,7 @@ class Breakout1C6Px6C1PCableProfile(BaseCableProfile):
}
class Shuffle2C4PCableProfile(BaseCableProfile):
class Trunk2C4PShuffleCableProfile(BaseCableProfile):
a_connectors = {
1: 4,
2: 4,
@@ -314,7 +320,7 @@ class Shuffle2C4PCableProfile(BaseCableProfile):
}
class Shuffle4C4PCableProfile(BaseCableProfile):
class Trunk4C4PShuffleCableProfile(BaseCableProfile):
a_connectors = {
1: 4,
2: 4,
@@ -342,10 +348,7 @@ class Shuffle4C4PCableProfile(BaseCableProfile):
}
class ShuffleBreakout2x8CableProfile(BaseCableProfile):
"""
Temporary solution for mapping 2 front/rear ports to 8 discrete interfaces
"""
class Breakout2C4Px8C1PShuffleCableProfile(BaseCableProfile):
a_connectors = {
1: 4,
2: 4,
@@ -382,6 +385,6 @@ class ShuffleBreakout2x8CableProfile(BaseCableProfile):
}
def get_mapped_position(self, side, connector, position):
if side.lower() == CableEndChoices.SIDE_A:
if side.upper() == CableEndChoices.SIDE_A:
return self._a_mapping.get((connector, position))
return self._b_mapping.get((connector, position))

View File

@@ -1734,66 +1734,60 @@ class CableProfileChoices(ChoiceSet):
TRUNK_2C1P = 'trunk-2c1p'
TRUNK_2C2P = 'trunk-2c2p'
TRUNK_2C4P = 'trunk-2c4p'
TRUNK_2C4P_SHUFFLE = 'trunk-2c4p-shuffle'
TRUNK_2C6P = 'trunk-2c6p'
TRUNK_2C8P = 'trunk-2c8p'
TRUNK_2C12P = 'trunk-2c12p'
TRUNK_4C1P = 'trunk-4c1p'
TRUNK_4C2P = 'trunk-4c2p'
TRUNK_4C4P = 'trunk-4c4p'
TRUNK_4C4P_SHUFFLE = 'trunk-4c4p-shuffle'
TRUNK_4C6P = 'trunk-4c6p'
TRUNK_4C8P = 'trunk-4c8p'
TRUNK_8C4P = 'trunk-8c4p'
# Breakouts
BREAKOUT_1C4P_4C1P = 'breakout-1c4p-4c1p'
BREAKOUT_1C6P_6C1P = 'breakout-1c6p-6c1p'
SHUFFLE_BREAKOUT_2X8 = 'shuffle-breakout-2x8'
# Shuffles
SHUFFLE_2C4P = 'shuffle-2c4p'
SHUFFLE_4C4P = 'shuffle-4c4p'
BREAKOUT_2C4P_8C1P_SHUFFLE = 'breakout-2c4p-8c1p-shuffle'
CHOICES = (
(
_('Single'),
(
(SINGLE_1C1P, _('Single (1C1P)')),
(SINGLE_1C2P, _('Single (1C2P)')),
(SINGLE_1C4P, _('Single (1C4P)')),
(SINGLE_1C6P, _('Single (1C6P)')),
(SINGLE_1C8P, _('Single (1C8P)')),
(SINGLE_1C12P, _('Single (1C12P)')),
(SINGLE_1C16P, _('Single (1C16P)')),
(SINGLE_1C1P, _('1C1P')),
(SINGLE_1C2P, _('1C2P')),
(SINGLE_1C4P, _('1C4P')),
(SINGLE_1C6P, _('1C6P')),
(SINGLE_1C8P, _('1C8P')),
(SINGLE_1C12P, _('1C12P')),
(SINGLE_1C16P, _('1C16P')),
),
),
(
_('Trunk'),
(
(TRUNK_2C1P, _('Trunk (2C1P)')),
(TRUNK_2C2P, _('Trunk (2C2P)')),
(TRUNK_2C4P, _('Trunk (2C4P)')),
(TRUNK_2C6P, _('Trunk (2C6P)')),
(TRUNK_2C8P, _('Trunk (2C8P)')),
(TRUNK_2C12P, _('Trunk (2C12P)')),
(TRUNK_4C1P, _('Trunk (4C1P)')),
(TRUNK_4C2P, _('Trunk (4C2P)')),
(TRUNK_4C4P, _('Trunk (4C4P)')),
(TRUNK_4C6P, _('Trunk (4C6P)')),
(TRUNK_4C8P, _('Trunk (4C8P)')),
(TRUNK_8C4P, _('Trunk (8C4P)')),
(TRUNK_2C1P, _('2C1P trunk')),
(TRUNK_2C2P, _('2C2P trunk')),
(TRUNK_2C4P, _('2C4P trunk')),
(TRUNK_2C4P_SHUFFLE, _('2C4P trunk (shuffle)')),
(TRUNK_2C6P, _('2C6P trunk')),
(TRUNK_2C8P, _('2C8P trunk')),
(TRUNK_2C12P, _('2C12P trunk')),
(TRUNK_4C1P, _('4C1P trunk')),
(TRUNK_4C2P, _('4C2P trunk')),
(TRUNK_4C4P, _('4C4P trunk')),
(TRUNK_4C4P_SHUFFLE, _('4C4P trunk (shuffle)')),
(TRUNK_4C6P, _('4C6P trunk')),
(TRUNK_4C8P, _('4C8P trunk')),
(TRUNK_8C4P, _('8C4P trunk')),
),
),
(
_('Breakout'),
(
(BREAKOUT_1C4P_4C1P, _('Breakout (1C4P/4C1P)')),
(BREAKOUT_1C6P_6C1P, _('Breakout (1C6P/6C1P)')),
),
),
(
_('Shuffle'),
(
(SHUFFLE_2C4P, _('Shuffle (2C4P)')),
(SHUFFLE_4C4P, _('Shuffle (4C4P)')),
(SHUFFLE_BREAKOUT_2X8, _('Shuffle breakout (2x8)')),
(BREAKOUT_1C4P_4C1P, _('1C4P:4C1P breakout')),
(BREAKOUT_1C6P_6C1P, _('1C6P:6C1P breakout')),
(BREAKOUT_2C4P_8C1P_SHUFFLE, _('2C4P:8C1P breakout (shuffle)')),
),
),
)

View File

@@ -147,20 +147,20 @@ class Cable(PrimaryModel):
CableProfileChoices.TRUNK_2C1P: cable_profiles.Trunk2C1PCableProfile,
CableProfileChoices.TRUNK_2C2P: cable_profiles.Trunk2C2PCableProfile,
CableProfileChoices.TRUNK_2C4P: cable_profiles.Trunk2C4PCableProfile,
CableProfileChoices.TRUNK_2C4P_SHUFFLE: cable_profiles.Trunk2C4PShuffleCableProfile,
CableProfileChoices.TRUNK_2C6P: cable_profiles.Trunk2C6PCableProfile,
CableProfileChoices.TRUNK_2C8P: cable_profiles.Trunk2C8PCableProfile,
CableProfileChoices.TRUNK_2C12P: cable_profiles.Trunk2C12PCableProfile,
CableProfileChoices.TRUNK_4C1P: cable_profiles.Trunk4C1PCableProfile,
CableProfileChoices.TRUNK_4C2P: cable_profiles.Trunk4C2PCableProfile,
CableProfileChoices.TRUNK_4C4P: cable_profiles.Trunk4C4PCableProfile,
CableProfileChoices.TRUNK_4C4P_SHUFFLE: cable_profiles.Trunk4C4PShuffleCableProfile,
CableProfileChoices.TRUNK_4C6P: cable_profiles.Trunk4C6PCableProfile,
CableProfileChoices.TRUNK_4C8P: cable_profiles.Trunk4C8PCableProfile,
CableProfileChoices.TRUNK_8C4P: cable_profiles.Trunk8C4PCableProfile,
CableProfileChoices.BREAKOUT_1C4P_4C1P: cable_profiles.Breakout1C4Px4C1PCableProfile,
CableProfileChoices.BREAKOUT_1C6P_6C1P: cable_profiles.Breakout1C6Px6C1PCableProfile,
CableProfileChoices.SHUFFLE_2C4P: cable_profiles.Shuffle2C4PCableProfile,
CableProfileChoices.SHUFFLE_4C4P: cable_profiles.Shuffle4C4PCableProfile,
CableProfileChoices.SHUFFLE_BREAKOUT_2X8: cable_profiles.ShuffleBreakout2x8CableProfile,
CableProfileChoices.BREAKOUT_2C4P_8C1P_SHUFFLE: cable_profiles.Breakout2C4Px8C1PShuffleCableProfile,
}.get(self.profile)
def _get_x_terminations(self, side):

View File

@@ -710,7 +710,7 @@ class CablePathTests(CablePathTestCase):
cable.save()
cables.append(cable)
shuffle_cable = Cable(
profile=CableProfileChoices.SHUFFLE_2C4P,
profile=CableProfileChoices.TRUNK_2C4P_SHUFFLE,
a_terminations=rear_ports[0:2],
b_terminations=rear_ports[2:4],
)