Extend cable tracing tests

This commit is contained in:
jeremystretch 2022-05-10 15:46:12 -04:00
parent 4d5bcb65c8
commit bb9eb119a4

View File

@ -228,7 +228,54 @@ class CablePathTestCase(TestCase):
# Check that all CablePaths have been deleted
self.assertEqual(CablePath.objects.count(), 0)
def test_120_multi_term_to_multi_term(self):
def test_120_single_interface_to_multi_interface(self):
"""
[IF1] --C1-- [IF2]
[IF3]
"""
interface1 = Interface.objects.create(device=self.device, name='Interface 1')
interface2 = Interface.objects.create(device=self.device, name='Interface 2')
interface3 = Interface.objects.create(device=self.device, name='Interface 3')
# Create cable 1
cable1 = Cable(terminations=[
CableTermination(cable_end='A', termination=interface1),
CableTermination(cable_end='B', termination=interface2),
CableTermination(cable_end='B', termination=interface3),
])
cable1.save()
path1 = self.assertPathExists(
(interface1, cable1, (interface2, interface3)),
is_complete=True,
is_active=True
)
path2 = self.assertPathExists(
((interface2, interface3), cable1, interface1),
is_complete=True,
is_active=True
)
self.assertEqual(CablePath.objects.count(), 2)
interface1.refresh_from_db()
interface2.refresh_from_db()
interface3.refresh_from_db()
self.assertPathIsSet(interface1, path1)
self.assertPathIsSet(interface2, path2)
self.assertPathIsSet(interface3, path2)
# Delete cable 1
cable1.delete()
# Check that all CablePaths have been deleted
self.assertEqual(CablePath.objects.count(), 0)
interface1.refresh_from_db()
interface2.refresh_from_db()
interface3.refresh_from_db()
self.assertPathIsNotSet(interface1)
self.assertPathIsNotSet(interface2)
self.assertPathIsNotSet(interface3)
def test_121_multi_interface_to_multi_interface(self):
"""
[IF1] --C1-- [IF3]
[IF2] [IF4]
@ -239,14 +286,12 @@ class CablePathTestCase(TestCase):
interface4 = Interface.objects.create(device=self.device, name='Interface 4')
# Create cable 1
cable1 = Cable(
terminations=[
CableTermination(cable_end='A', termination=interface1),
CableTermination(cable_end='A', termination=interface2),
CableTermination(cable_end='B', termination=interface3),
CableTermination(cable_end='B', termination=interface4),
]
)
cable1 = Cable(terminations=[
CableTermination(cable_end='A', termination=interface1),
CableTermination(cable_end='A', termination=interface2),
CableTermination(cable_end='B', termination=interface3),
CableTermination(cable_end='B', termination=interface4),
])
cable1.save()
path1 = self.assertPathExists(
@ -274,6 +319,14 @@ class CablePathTestCase(TestCase):
# Check that all CablePaths have been deleted
self.assertEqual(CablePath.objects.count(), 0)
interface1.refresh_from_db()
interface2.refresh_from_db()
interface3.refresh_from_db()
interface4.refresh_from_db()
self.assertPathIsNotSet(interface1)
self.assertPathIsNotSet(interface2)
self.assertPathIsNotSet(interface3)
self.assertPathIsNotSet(interface4)
def test_201_single_path_via_pass_through(self):
"""
@ -1118,6 +1171,215 @@ class CablePathTestCase(TestCase):
self.assertEqual(CablePath.objects.filter(is_complete=False).count(), 4)
self.assertEqual(CablePath.objects.filter(is_complete=True).count(), 0)
def test_250_interface_to_interface_via_rear_ports(self):
"""
[IF1] --C1-- [FP1] [RP1] --C2-- [RP3] [FP3] --C3-- [IF2]
[FP2] [RP2] [RP4] [FP4]
"""
interface1 = Interface.objects.create(device=self.device, name='Interface 1')
interface2 = Interface.objects.create(device=self.device, name='Interface 2')
rearport1 = RearPort.objects.create(device=self.device, name='Rear Port 1', positions=1)
rearport2 = RearPort.objects.create(device=self.device, name='Rear Port 2', positions=1)
rearport3 = RearPort.objects.create(device=self.device, name='Rear Port 3', positions=1)
rearport4 = RearPort.objects.create(device=self.device, name='Rear Port 4', positions=1)
frontport1 = FrontPort.objects.create(
device=self.device, name='Front Port 1', rear_port=rearport1, rear_port_position=1
)
frontport2 = FrontPort.objects.create(
device=self.device, name='Front Port 2', rear_port=rearport2, rear_port_position=1
)
frontport3 = FrontPort.objects.create(
device=self.device, name='Front Port 3', rear_port=rearport3, rear_port_position=1
)
frontport4 = FrontPort.objects.create(
device=self.device, name='Front Port 4', rear_port=rearport4, rear_port_position=1
)
# Create cables 1-2
cable1 = Cable(terminations=[
CableTermination(cable_end='A', termination=interface1),
CableTermination(cable_end='B', termination=frontport1),
CableTermination(cable_end='B', termination=frontport2),
])
cable1.save()
cable3 = Cable(terminations=[
CableTermination(cable_end='A', termination=interface2),
CableTermination(cable_end='B', termination=frontport3),
CableTermination(cable_end='B', termination=frontport4),
])
cable3.save()
self.assertPathExists(
(interface1, cable1, (frontport1, frontport2), (rearport1, rearport2)),
is_complete=False
)
self.assertPathExists(
(interface2, cable3, (frontport3, frontport4), (rearport3, rearport4)),
is_complete=False
)
self.assertEqual(CablePath.objects.count(), 2)
# Create cable 2
cable2 = Cable(terminations=[
CableTermination(cable_end='A', termination=rearport1),
CableTermination(cable_end='A', termination=rearport2),
CableTermination(cable_end='B', termination=rearport3),
CableTermination(cable_end='B', termination=rearport4),
])
cable2.save()
path1 = self.assertPathExists(
(
interface1, cable1, (frontport1, frontport2), (rearport1, rearport2), cable2,
(rearport3, rearport4), (frontport3, frontport4), cable3, interface2
),
is_complete=True
)
path2 = self.assertPathExists(
(
interface2, cable3, (frontport3, frontport4), (rearport3, rearport4), cable2,
(rearport1, rearport2), (frontport1, frontport2), cable1, interface1
),
is_complete=True
)
self.assertEqual(CablePath.objects.count(), 2)
# Delete cable 2
cable2.delete()
# Check for two partial paths; one from each interface
self.assertEqual(CablePath.objects.filter(is_complete=False).count(), 2)
self.assertEqual(CablePath.objects.filter(is_complete=True).count(), 0)
interface1.refresh_from_db()
interface2.refresh_from_db()
self.assertPathIsSet(interface1, path1)
self.assertPathIsSet(interface2, path2)
def test_251_interfaces_to_interfaces_via_multiposition_rear_ports(self):
"""
[IF1] --C1-- [FP1:1] [RP1] --C3-- [RP2] [FP2:1] --C4-- [IF3]
[FP1:2] [FP2:2]
[IF2] --C2-- [FP1:3] [FP2:3] --C5-- [IF4]
[FP1:4] [FP2:4]
"""
interface1 = Interface.objects.create(device=self.device, name='Interface 1')
interface2 = Interface.objects.create(device=self.device, name='Interface 2')
interface3 = Interface.objects.create(device=self.device, name='Interface 3')
interface4 = Interface.objects.create(device=self.device, name='Interface 4')
rearport1 = RearPort.objects.create(device=self.device, name='Rear Port 1', positions=4)
rearport2 = RearPort.objects.create(device=self.device, name='Rear Port 2', positions=4)
frontport1_1 = FrontPort.objects.create(
device=self.device, name='Front Port 1:1', rear_port=rearport1, rear_port_position=1
)
frontport1_2 = FrontPort.objects.create(
device=self.device, name='Front Port 1:2', rear_port=rearport1, rear_port_position=2
)
frontport1_3 = FrontPort.objects.create(
device=self.device, name='Front Port 1:3', rear_port=rearport1, rear_port_position=3
)
frontport1_4 = FrontPort.objects.create(
device=self.device, name='Front Port 1:4', rear_port=rearport1, rear_port_position=4
)
frontport2_1 = FrontPort.objects.create(
device=self.device, name='Front Port 2:1', rear_port=rearport2, rear_port_position=1
)
frontport2_2 = FrontPort.objects.create(
device=self.device, name='Front Port 2:2', rear_port=rearport2, rear_port_position=2
)
frontport2_3 = FrontPort.objects.create(
device=self.device, name='Front Port 2:3', rear_port=rearport2, rear_port_position=3
)
frontport2_4 = FrontPort.objects.create(
device=self.device, name='Front Port 2:4', rear_port=rearport2, rear_port_position=4
)
# Create cables 1-2
cable1 = Cable(terminations=[
CableTermination(cable_end='A', termination=interface1),
CableTermination(cable_end='B', termination=frontport1_1),
CableTermination(cable_end='B', termination=frontport1_2),
])
cable1.save()
cable2 = Cable(terminations=[
CableTermination(cable_end='A', termination=interface2),
CableTermination(cable_end='B', termination=frontport1_3),
CableTermination(cable_end='B', termination=frontport1_4),
])
cable2.save()
self.assertPathExists(
(interface1, cable1, (frontport1_1, frontport1_2), rearport1),
is_complete=False
)
self.assertPathExists(
(interface2, cable2, (frontport1_3, frontport1_4), rearport1),
is_complete=False
)
self.assertEqual(CablePath.objects.count(), 2)
# Create cable 3
cable3 = Cable(terminations=[
CableTermination(cable_end='A', termination=rearport1),
CableTermination(cable_end='B', termination=rearport2),
])
cable3.save()
self.assertPathExists(
(interface1, cable1, (frontport1_1, frontport1_2), rearport1, cable3, rearport2, (frontport2_1, frontport2_2)),
is_complete=False
)
self.assertPathExists(
(interface2, cable2, (frontport1_3, frontport1_4), rearport1, cable3, rearport2, (frontport2_3, frontport2_4)),
is_complete=False
)
self.assertEqual(CablePath.objects.count(), 2)
# Create cables 4-5
cable4 = Cable(terminations=[
CableTermination(cable_end='A', termination=frontport2_1),
CableTermination(cable_end='A', termination=frontport2_2),
CableTermination(cable_end='B', termination=interface3),
])
cable4.save()
cable5 = Cable(terminations=[
CableTermination(cable_end='A', termination=frontport2_3),
CableTermination(cable_end='A', termination=frontport2_4),
CableTermination(cable_end='B', termination=interface4),
])
cable5.save()
path1 = self.assertPathExists(
(interface1, cable1, (frontport1_1, frontport1_2), rearport1, cable3, rearport2, (frontport2_1, frontport2_2), cable4, interface3),
is_complete=True,
is_active=True
)
path2 = self.assertPathExists(
(interface2, cable2, (frontport1_3, frontport1_4), rearport1, cable3, rearport2, (frontport2_3, frontport2_4), cable5, interface4),
is_complete=True,
is_active=True
)
path3 = self.assertPathExists(
(interface3, cable4, (frontport2_1, frontport2_2), rearport2, cable3, rearport1, (frontport1_1, frontport1_2), cable1, interface1),
is_complete=True,
is_active=True
)
path4 = self.assertPathExists(
(interface4, cable5, (frontport2_3, frontport2_4), rearport2, cable3, rearport1, (frontport1_3, frontport1_4), cable2, interface2),
is_complete=True,
is_active=True
)
self.assertEqual(CablePath.objects.count(), 4)
# Delete cable 3
cable3.delete()
# Check for four partial paths; one from each interface
self.assertEqual(CablePath.objects.filter(is_complete=False).count(), 4)
self.assertEqual(CablePath.objects.filter(is_complete=True).count(), 0)
interface1.refresh_from_db()
interface2.refresh_from_db()
interface3.refresh_from_db()
interface4.refresh_from_db()
self.assertPathIsSet(interface1, path1)
self.assertPathIsSet(interface2, path2)
self.assertPathIsSet(interface3, path3)
self.assertPathIsSet(interface4, path4)
def test_213_multiple_circuits_to_interface(self):
"""
[IF1] --C1-- [CT1] [CT2] --C2-- [CT3] [CT4] --C3-- [IF2]