mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-16 20:22:53 -06:00
Fixes #4604: Multi-position rear ports may only be connected to other rear ports
This commit is contained in:
parent
b7a96a33ef
commit
e14e217fcd
@ -5,6 +5,7 @@ v2.8.4 (FUTURE)
|
|||||||
### Bug Fixes
|
### Bug Fixes
|
||||||
|
|
||||||
* [#4598](https://github.com/netbox-community/netbox/issues/4598) - Display error message when invalid cable length is specified
|
* [#4598](https://github.com/netbox-community/netbox/issues/4598) - Display error message when invalid cable length is specified
|
||||||
|
* [#4604](https://github.com/netbox-community/netbox/issues/4604) - Multi-position rear ports may only be connected to other rear ports
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
@ -2182,23 +2182,29 @@ class Cable(ChangeLoggedModel):
|
|||||||
|
|
||||||
# Check that termination types are compatible
|
# Check that termination types are compatible
|
||||||
if type_b not in COMPATIBLE_TERMINATION_TYPES.get(type_a):
|
if type_b not in COMPATIBLE_TERMINATION_TYPES.get(type_a):
|
||||||
raise ValidationError("Incompatible termination types: {} and {}".format(
|
raise ValidationError(
|
||||||
self.termination_a_type, self.termination_b_type
|
f"Incompatible termination types: {self.termination_a_type} and {self.termination_b_type}"
|
||||||
))
|
)
|
||||||
|
|
||||||
# A RearPort with multiple positions must be connected to a component with an equal number of positions
|
# A RearPort with multiple positions must be connected to a RearPort with an equal number of positions
|
||||||
if isinstance(self.termination_a, RearPort) and isinstance(self.termination_b, RearPort):
|
for term_a, term_b in [
|
||||||
if self.termination_a.positions != self.termination_b.positions:
|
(self.termination_a, self.termination_b),
|
||||||
raise ValidationError(
|
(self.termination_b, self.termination_a)
|
||||||
"{} has {} positions and {} has {}. Both terminations must have the same number of positions.".format(
|
]:
|
||||||
self.termination_a, self.termination_a.positions,
|
if isinstance(term_a, RearPort) and term_a.positions > 1:
|
||||||
self.termination_b, self.termination_b.positions
|
if not isinstance(term_b, RearPort):
|
||||||
|
raise ValidationError(
|
||||||
|
"Rear ports with multiple positions may only be connected to other rear ports"
|
||||||
|
)
|
||||||
|
elif term_a.positions != term_b.positions:
|
||||||
|
raise ValidationError(
|
||||||
|
f"{term_a} has {term_a.positions} position(s) but {term_b} has {term_b.positions}. "
|
||||||
|
f"Both terminations must have the same number of positions."
|
||||||
)
|
)
|
||||||
)
|
|
||||||
|
|
||||||
# A termination point cannot be connected to itself
|
# A termination point cannot be connected to itself
|
||||||
if self.termination_a == self.termination_b:
|
if self.termination_a == self.termination_b:
|
||||||
raise ValidationError("Cannot connect {} to itself".format(self.termination_a_type))
|
raise ValidationError(f"Cannot connect {self.termination_a_type} to itself")
|
||||||
|
|
||||||
# A front port cannot be connected to its corresponding rear port
|
# A front port cannot be connected to its corresponding rear port
|
||||||
if (
|
if (
|
||||||
|
Loading…
Reference in New Issue
Block a user