mirror of
https://github.com/netbox-community/netbox.git
synced 2025-12-12 11:29:36 -06:00
Add tests for PortMapping changes
This commit is contained in:
parent
619728a048
commit
107c1f25c8
@ -839,3 +839,205 @@ class CablePathTests(CablePathTestCase):
|
|||||||
is_active=True
|
is_active=True
|
||||||
)
|
)
|
||||||
self.assertEqual(CablePath.objects.count(), 4)
|
self.assertEqual(CablePath.objects.count(), 4)
|
||||||
|
|
||||||
|
def test_304_add_port_mapping_between_connected_ports(self):
|
||||||
|
"""
|
||||||
|
[IF1] --C1-- [FP1] [RP1] --C2-- [IF2]
|
||||||
|
"""
|
||||||
|
interface1 = Interface.objects.create(device=self.device, name='Interface 1')
|
||||||
|
interface2 = Interface.objects.create(device=self.device, name='Interface 2')
|
||||||
|
frontport1 = FrontPort.objects.create(device=self.device, name='Front Port 1')
|
||||||
|
rearport1 = RearPort.objects.create(device=self.device, name='Rear Port 1')
|
||||||
|
cable1 = Cable(
|
||||||
|
a_terminations=[interface1],
|
||||||
|
b_terminations=[frontport1]
|
||||||
|
)
|
||||||
|
cable1.save()
|
||||||
|
cable2 = Cable(
|
||||||
|
a_terminations=[interface2],
|
||||||
|
b_terminations=[rearport1]
|
||||||
|
)
|
||||||
|
cable2.save()
|
||||||
|
|
||||||
|
# Check for incomplete paths
|
||||||
|
self.assertPathExists(
|
||||||
|
(interface1, cable1, frontport1),
|
||||||
|
is_complete=False,
|
||||||
|
is_active=True
|
||||||
|
)
|
||||||
|
self.assertPathExists(
|
||||||
|
(interface2, cable2, rearport1),
|
||||||
|
is_complete=False,
|
||||||
|
is_active=True
|
||||||
|
)
|
||||||
|
|
||||||
|
# Create a PortMapping between frontport1 and rearport1
|
||||||
|
PortMapping.objects.create(
|
||||||
|
device=self.device,
|
||||||
|
front_port=frontport1,
|
||||||
|
front_port_position=1,
|
||||||
|
rear_port=rearport1,
|
||||||
|
rear_port_position=1,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Check that paths are now complete
|
||||||
|
self.assertPathExists(
|
||||||
|
(interface1, cable1, frontport1, rearport1, cable2, interface2),
|
||||||
|
is_complete=True,
|
||||||
|
is_active=True
|
||||||
|
)
|
||||||
|
self.assertPathExists(
|
||||||
|
(interface2, cable2, rearport1, frontport1, cable1, interface1),
|
||||||
|
is_complete=True,
|
||||||
|
is_active=True
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_305_delete_port_mapping_between_connected_ports(self):
|
||||||
|
"""
|
||||||
|
[IF1] --C1-- [FP1] [RP1] --C2-- [IF2]
|
||||||
|
"""
|
||||||
|
interface1 = Interface.objects.create(device=self.device, name='Interface 1')
|
||||||
|
interface2 = Interface.objects.create(device=self.device, name='Interface 2')
|
||||||
|
frontport1 = FrontPort.objects.create(device=self.device, name='Front Port 1')
|
||||||
|
rearport1 = RearPort.objects.create(device=self.device, name='Rear Port 1')
|
||||||
|
cable1 = Cable(
|
||||||
|
a_terminations=[interface1],
|
||||||
|
b_terminations=[frontport1]
|
||||||
|
)
|
||||||
|
cable1.save()
|
||||||
|
cable2 = Cable(
|
||||||
|
a_terminations=[interface2],
|
||||||
|
b_terminations=[rearport1]
|
||||||
|
)
|
||||||
|
cable2.save()
|
||||||
|
portmapping1 = PortMapping.objects.create(
|
||||||
|
device=self.device,
|
||||||
|
front_port=frontport1,
|
||||||
|
front_port_position=1,
|
||||||
|
rear_port=rearport1,
|
||||||
|
rear_port_position=1,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Check for complete paths
|
||||||
|
self.assertPathExists(
|
||||||
|
(interface1, cable1, frontport1, rearport1, cable2, interface2),
|
||||||
|
is_complete=True,
|
||||||
|
is_active=True
|
||||||
|
)
|
||||||
|
self.assertPathExists(
|
||||||
|
(interface2, cable2, rearport1, frontport1, cable1, interface1),
|
||||||
|
is_complete=True,
|
||||||
|
is_active=True
|
||||||
|
)
|
||||||
|
|
||||||
|
# Delete the PortMapping between frontport1 and rearport1
|
||||||
|
portmapping1.delete()
|
||||||
|
|
||||||
|
# Check that paths are no longer complete
|
||||||
|
self.assertPathExists(
|
||||||
|
(interface1, cable1, frontport1),
|
||||||
|
is_complete=False,
|
||||||
|
is_active=True
|
||||||
|
)
|
||||||
|
self.assertPathExists(
|
||||||
|
(interface2, cable2, rearport1),
|
||||||
|
is_complete=False,
|
||||||
|
is_active=True
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_306_change_port_mapping_between_connected_ports(self):
|
||||||
|
"""
|
||||||
|
[IF1] --C1-- [FP1] [RP1] --C3-- [IF3]
|
||||||
|
[IF2] --C2-- [FP2] [RP3] --C4-- [IF4]
|
||||||
|
"""
|
||||||
|
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')
|
||||||
|
frontport1 = FrontPort.objects.create(device=self.device, name='Front Port 1')
|
||||||
|
frontport2 = FrontPort.objects.create(device=self.device, name='Front Port 2')
|
||||||
|
rearport1 = RearPort.objects.create(device=self.device, name='Rear Port 1')
|
||||||
|
rearport2 = RearPort.objects.create(device=self.device, name='Rear Port 2')
|
||||||
|
cable1 = Cable(
|
||||||
|
a_terminations=[interface1],
|
||||||
|
b_terminations=[frontport1]
|
||||||
|
)
|
||||||
|
cable1.save()
|
||||||
|
cable2 = Cable(
|
||||||
|
a_terminations=[interface2],
|
||||||
|
b_terminations=[frontport2]
|
||||||
|
)
|
||||||
|
cable2.save()
|
||||||
|
cable3 = Cable(
|
||||||
|
a_terminations=[interface3],
|
||||||
|
b_terminations=[rearport1]
|
||||||
|
)
|
||||||
|
cable3.save()
|
||||||
|
cable4 = Cable(
|
||||||
|
a_terminations=[interface4],
|
||||||
|
b_terminations=[rearport2]
|
||||||
|
)
|
||||||
|
cable4.save()
|
||||||
|
portmapping1 = PortMapping.objects.create(
|
||||||
|
device=self.device,
|
||||||
|
front_port=frontport1,
|
||||||
|
front_port_position=1,
|
||||||
|
rear_port=rearport1,
|
||||||
|
rear_port_position=1,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Verify expected initial paths
|
||||||
|
self.assertPathExists(
|
||||||
|
(interface1, cable1, frontport1, rearport1, cable3, interface3),
|
||||||
|
is_complete=True,
|
||||||
|
is_active=True
|
||||||
|
)
|
||||||
|
self.assertPathExists(
|
||||||
|
(interface3, cable3, rearport1, frontport1, cable1, interface1),
|
||||||
|
is_complete=True,
|
||||||
|
is_active=True
|
||||||
|
)
|
||||||
|
|
||||||
|
# Delete and replace the PortMapping to connect interface1 to interface4
|
||||||
|
portmapping1.delete()
|
||||||
|
portmapping2 = PortMapping.objects.create(
|
||||||
|
device=self.device,
|
||||||
|
front_port=frontport1,
|
||||||
|
front_port_position=1,
|
||||||
|
rear_port=rearport2,
|
||||||
|
rear_port_position=1,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Verify expected new paths
|
||||||
|
self.assertPathExists(
|
||||||
|
(interface1, cable1, frontport1, rearport2, cable4, interface4),
|
||||||
|
is_complete=True,
|
||||||
|
is_active=True
|
||||||
|
)
|
||||||
|
self.assertPathExists(
|
||||||
|
(interface4, cable4, rearport2, frontport1, cable1, interface1),
|
||||||
|
is_complete=True,
|
||||||
|
is_active=True
|
||||||
|
)
|
||||||
|
|
||||||
|
# Delete and replace the PortMapping to connect interface2 to interface4
|
||||||
|
portmapping2.delete()
|
||||||
|
PortMapping.objects.create(
|
||||||
|
device=self.device,
|
||||||
|
front_port=frontport2,
|
||||||
|
front_port_position=1,
|
||||||
|
rear_port=rearport2,
|
||||||
|
rear_port_position=1,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Verify expected new paths
|
||||||
|
self.assertPathExists(
|
||||||
|
(interface2, cable2, frontport2, rearport2, cable4, interface4),
|
||||||
|
is_complete=True,
|
||||||
|
is_active=True
|
||||||
|
)
|
||||||
|
self.assertPathExists(
|
||||||
|
(interface4, cable4, rearport2, frontport2, cable2, interface2),
|
||||||
|
is_complete=True,
|
||||||
|
is_active=True
|
||||||
|
)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user