mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-25 00:36:11 -06:00
Catch AssertionError's in signals. Handle accordingly
This commit is contained in:
parent
0b10131564
commit
7c09eb298d
@ -478,8 +478,11 @@ class CablePath(models.Model):
|
||||
Cable or WirelessLink connects (interfaces, console ports, circuit termination, etc.). All terminations must be
|
||||
of the same type and must belong to the same parent object.
|
||||
"""
|
||||
import logging
|
||||
from circuits.models import CircuitTermination
|
||||
|
||||
logger = logging.getLogger('netbox.dcim.cablepath')
|
||||
|
||||
if not terminations:
|
||||
return None
|
||||
|
||||
@ -558,6 +561,7 @@ class CablePath(models.Model):
|
||||
pk__in=[t.rear_port_id for t in remote_terminations]
|
||||
)
|
||||
if len(rear_ports) > 1:
|
||||
logger.warning(f'All rear-port positions do not match. Cannot continue path trace.')
|
||||
assert all(rp.positions == 1 for rp in rear_ports)
|
||||
elif rear_ports[0].positions > 1:
|
||||
position_stack.append([fp.rear_port_position for fp in remote_terminations])
|
||||
|
@ -95,7 +95,11 @@ def update_connected_endpoints(instance, created, raw=False, **kwargs):
|
||||
if not nodes:
|
||||
continue
|
||||
if isinstance(nodes[0], PathEndpoint):
|
||||
try:
|
||||
create_cablepath(nodes)
|
||||
except AssertionError:
|
||||
# This is likely an unsupported path. Catch the assertion error and don't save the path
|
||||
logger.error(f'Unsupported path from nodes: {[node.name for node in nodes].join(",")}')
|
||||
else:
|
||||
rebuild_paths(nodes)
|
||||
|
||||
|
@ -49,12 +49,20 @@ def rebuild_paths(terminations):
|
||||
"""
|
||||
Rebuild all CablePaths which traverse the specified nodes.
|
||||
"""
|
||||
import logging
|
||||
from dcim.models import CablePath
|
||||
|
||||
logger = logging.getLogger('netbox.dcim.cable')
|
||||
|
||||
for obj in terminations:
|
||||
cable_paths = CablePath.objects.filter(_nodes__contains=obj)
|
||||
|
||||
with transaction.atomic():
|
||||
for cp in cable_paths:
|
||||
cp.delete()
|
||||
try:
|
||||
create_cablepath(cp.origins)
|
||||
except AssertionError:
|
||||
# This is likely an unsupported path. Catch the assertion error and don't save the path
|
||||
logger.error(f'Unsupported path from cable path: {cp._nodes}')
|
||||
pass
|
||||
|
Loading…
Reference in New Issue
Block a user