Improve handling of links with multi-terminations

This commit is contained in:
Daniel Sheppard 2023-09-12 13:24:00 -05:00
parent de216aadf7
commit 359b366b27
2 changed files with 20 additions and 6 deletions

View File

@ -551,8 +551,12 @@ class CablePath(models.Model):
is_complete = False is_complete = False
is_split = True is_split = True
# Step 4: Record the links # Step 4: Record the links, keeping cables in order to allow for SVG rendering
path.append([object_to_path_node(link) for link in links]) cables = []
for link in links:
if object_to_path_node(link) not in cables:
cables.append(object_to_path_node(link))
path.append(cables)
# Step 5: Update the path status if a link is not connected # Step 5: Update the path status if a link is not connected
links_status = [link.status for link in links if link.status != LinkStatusChoices.STATUS_CONNECTED] links_status = [link.status for link in links if link.status != LinkStatusChoices.STATUS_CONNECTED]
@ -782,3 +786,15 @@ class CablePath(models.Model):
return [ return [
ct.get_peer_termination() for ct in nodes ct.get_peer_termination() for ct in nodes
] ]
def get_asymmetric_nodes(self):
"""
Return all available next segments in a split cable path.
"""
from circuits.models import CircuitTermination
asymmetric_nodes = []
for nodes in self.path_objects:
if type(nodes[0]) in [RearPort, FrontPort, CircuitTermination]:
asymmetric_nodes.extend([node for node in nodes if node.link is None])
return asymmetric_nodes

View File

@ -50,9 +50,7 @@ class CablePathTestCase(TestCase):
path.append([object_to_path_node(node) for node in step]) path.append([object_to_path_node(node) for node in step])
else: else:
path.append([object_to_path_node(step)]) path.append([object_to_path_node(step)])
return CablePath.objects.filter(path=path, **kwargs).first()
cablepath = CablePath.objects.filter(path=path, **kwargs).first()
return cablepath
def assertPathExists(self, nodes, **kwargs): def assertPathExists(self, nodes, **kwargs):
""" """
@ -333,7 +331,7 @@ class CablePathTestCase(TestCase):
is_active=True is_active=True
) )
path2 = self.assertPathExists( path2 = self.assertPathExists(
((interface3, interface4), (cable1, cable1), (interface1, interface2)), ((interface3, interface4), cable1, (interface1, interface2)),
is_complete=True, is_complete=True,
is_active=True is_active=True
) )