From 03d6e25dea40647f270bb99abbfb59415e08bfd5 Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Mon, 27 Jun 2022 16:40:40 -0400 Subject: [PATCH] Remove obsolete validation logic --- netbox/dcim/models/cables.py | 27 -------------------- netbox/dcim/tests/test_models.py | 43 ++------------------------------ 2 files changed, 2 insertions(+), 68 deletions(-) diff --git a/netbox/dcim/models/cables.py b/netbox/dcim/models/cables.py index f13c77d15..8f31c77f2 100644 --- a/netbox/dcim/models/cables.py +++ b/netbox/dcim/models/cables.py @@ -126,17 +126,6 @@ class Cable(NetBoxModel): def clean(self): super().clean() - # TODO: Is this validation still necessary? - # # Check that two connected RearPorts have the same number of positions (if both are >1) - # if isinstance(self.termination_a, RearPort) and isinstance(self.termination_b, RearPort): - # if self.termination_a.positions > 1 and self.termination_b.positions > 1: - # if self.termination_a.positions != self.termination_b.positions: - # raise ValidationError( - # f"{self.termination_a} has {self.termination_a.positions} position(s) but " - # f"{self.termination_b} has {self.termination_b.positions}. " - # f"Both terminations must have the same number of positions (if greater than one)." - # ) - # Validate length and length_unit if self.length is not None and not self.length_unit: raise ValidationError("Must specify a unit when setting a cable length") @@ -153,10 +142,6 @@ class Cable(NetBoxModel): # Check that all termination objects for either end are of the same type for terms in (a_terminations, b_terminations): if terms and len(terms) > 1: - if not all(t.termination.parent_object == terms[0].termination.parent_object for t in terms[1:]): - raise ValidationError( - "All terminations on one end of a cable must belong to the same parent object." - ) if not all(t.termination_type == terms[0].termination_type for t in terms[1:]): raise ValidationError( "Cannot connect different termination types to same end of cable." @@ -175,18 +160,6 @@ class Cable(NetBoxModel): for cabletermination in [*a_terminations, *b_terminations]: cabletermination.clean() - # TODO - # # 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") - def save(self, *args, **kwargs): _created = self.pk is None diff --git a/netbox/dcim/tests/test_models.py b/netbox/dcim/tests/test_models.py index 84a5fc1a1..d97823e7c 100644 --- a/netbox/dcim/tests/test_models.py +++ b/netbox/dcim/tests/test_models.py @@ -537,20 +537,11 @@ class CableTestCase(TestCase): """ The clean method should have a check to ensure only compatible port types can be connected by a cable """ - # An interface cannot be connected to a power port - cable = Cable(a_terminations=[self.interface1, self.interface2], b_terminations=[self.interface3]) + # An interface cannot be connected to a power port, for example + cable = Cable(a_terminations=[self.interface1], b_terminations=[self.power_port1]) with self.assertRaises(ValidationError): cable.clean() - # TODO: Remove this? - # def test_cable_front_port_cannot_connect_to_corresponding_rear_port(self): - # """ - # A cable cannot connect a front port to its corresponding rear port - # """ - # cable = Cable(a_terminations=[self.front_port1], b_terminations=[self.rear_port1]) - # with self.assertRaises(ValidationError): - # cable.clean() - def test_cable_cannot_terminate_to_a_provider_network_circuittermination(self): """ Neither side of a cable can be terminated to a CircuitTermination which is attached to a ProviderNetwork @@ -559,36 +550,6 @@ class CableTestCase(TestCase): with self.assertRaises(ValidationError): cable.clean() - # TODO: Remove this? - # def test_rearport_connections(self): - # """ - # Test various combinations of RearPort connections. - # """ - # # Connecting a single-position RearPort to a multi-position RearPort is ok - # Cable(a_terminations=[self.rear_port1], b_terminations=[self.rear_port2]).full_clean() - # - # # Connecting a single-position RearPort to an Interface is ok - # Cable(a_terminations=[self.rear_port1], b_terminations=[self.interface3]).full_clean() - # - # # Connecting a single-position RearPort to a CircuitTermination is ok - # Cable(a_terminations=[self.rear_port1], b_terminations=[self.circuittermination1]).full_clean() - # - # # Connecting a multi-position RearPort to another RearPort with the same number of positions is ok - # Cable(a_terminations=[self.rear_port3], b_terminations=[self.rear_port4]).full_clean() - # - # # Connecting a multi-position RearPort to an Interface is ok - # Cable(a_terminations=[self.rear_port2], b_terminations=[self.interface3]).full_clean() - # - # # Connecting a multi-position RearPort to a CircuitTermination is ok - # Cable(a_terminations=[self.rear_port2], b_terminations=[self.circuittermination1]).full_clean() - # - # # Connecting a two-position RearPort to a three-position RearPort is NOT ok - # with self.assertRaises( - # ValidationError, - # msg='Connecting a 2-position RearPort to a 3-position RearPort should fail' - # ): - # Cable(a_terminations=[self.rear_port2], b_terminations=[self.rear_port3]).full_clean() - def test_cable_cannot_terminate_to_a_virtual_interface(self): """ A cable cannot terminate to a virtual interface