fixed #2584 - validation for connecting front port to corresponding rear port

This commit is contained in:
John Anderson 2018-11-12 22:15:06 -05:00
parent bc8dbfde7c
commit 9543b5e716

View File

@ -2530,9 +2530,19 @@ class Cable(ChangeLoggedModel):
# A termination point cannot be connected to itself
if self.termination_a == self.termination_b:
print("Validation failed: same interface")
raise ValidationError("Cannot connect {} to itself".format(self.termination_a_type))
# A front port cannot be connected to its corresponding rear port
if (
type_a in ['frontport', 'rearport'] and
type_b in ['frontport', 'rearport'] and
(
getattr(self.termination_a, 'rear_port', None) == self.termination_b or
getattr(self.termination_b, 'rear_port', None) == self.termination_a
)
):
raise ValidationError("A front port cannot be connected to it corresponding rear port")
# Check for an existing Cable connected to either termination object
if self.termination_a.cable not in (None, self):
raise ValidationError("{} already has a cable attached (#{})".format(