mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-22 20:12:00 -06:00
Move CABLE_TRACE_MAX_LENGTH to settings
This commit is contained in:
parent
cdf7aa1ea5
commit
bfe6d393a7
@ -2,6 +2,7 @@ import itertools
|
|||||||
import logging
|
import logging
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
from django.contrib.contenttypes.fields import GenericForeignKey
|
from django.contrib.contenttypes.fields import GenericForeignKey
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
from django.db import models
|
from django.db import models
|
||||||
@ -533,7 +534,7 @@ class CablePath(models.Model):
|
|||||||
"""
|
"""
|
||||||
from circuits.models import CircuitTermination
|
from circuits.models import CircuitTermination
|
||||||
|
|
||||||
max_length = max_length or 99999
|
max_length = max_length or settings.CABLE_TRACE_MAX_LENGTH
|
||||||
|
|
||||||
if not terminations:
|
if not terminations:
|
||||||
return None
|
return None
|
||||||
|
@ -2349,7 +2349,8 @@ class CablePathTestCase(TestCase):
|
|||||||
def test_detect_infinite_loop(self):
|
def test_detect_infinite_loop(self):
|
||||||
"""
|
"""
|
||||||
Tests the ability to detect a non-resolving path and break out with a logged warning.
|
Tests the ability to detect a non-resolving path and break out with a logged warning.
|
||||||
No assertion; test will fail by falling into a non-terminating loop in CablePath.from_origin()
|
Assertion will fail if max_length is exceeded (meaning infinite loop detection failed), or not reached
|
||||||
|
(meaning this test is no longer valid as existing synthetic path no longer creates an infinite loop).
|
||||||
[IF1] --C1-- [FP1][Test Device][Rear Splice]
|
[IF1] --C1-- [FP1][Test Device][Rear Splice]
|
||||||
[FP2] --C2-- [ Rear Splice
|
[FP2] --C2-- [ Rear Splice
|
||||||
"""
|
"""
|
||||||
@ -2381,7 +2382,9 @@ class CablePathTestCase(TestCase):
|
|||||||
CableTermination.objects.create(cable=cable_2, cable_end='A', termination_type=ct_frontport, termination_id=front_port_2.id)
|
CableTermination.objects.create(cable=cable_2, cable_end='A', termination_type=ct_frontport, termination_id=front_port_2.id)
|
||||||
CableTermination.objects.create(cable=cable_2, cable_end='B', termination_type=ct_rearport, termination_id=rear_splice.id)
|
CableTermination.objects.create(cable=cable_2, cable_end='B', termination_type=ct_rearport, termination_id=rear_splice.id)
|
||||||
|
|
||||||
cable_1.save(max_length=50)
|
max_length = 50
|
||||||
|
|
||||||
|
cable_1.save(max_length=max_length)
|
||||||
a_terminations = []
|
a_terminations = []
|
||||||
b_terminations = []
|
b_terminations = []
|
||||||
for t in cable_1.terminations.all():
|
for t in cable_1.terminations.all():
|
||||||
@ -2389,7 +2392,7 @@ class CablePathTestCase(TestCase):
|
|||||||
a_terminations.append(t.termination)
|
a_terminations.append(t.termination)
|
||||||
else:
|
else:
|
||||||
b_terminations.append(t.termination)
|
b_terminations.append(t.termination)
|
||||||
cp = CablePath.from_origin(a_terminations, max_length=50)
|
cp = CablePath.from_origin(a_terminations, max_length=max_length)
|
||||||
self.assertEqual(len(cp.path), 50)
|
self.assertEqual(len(cp.path), max_length)
|
||||||
cp = CablePath.from_origin(b_terminations, max_length=10)
|
cp = CablePath.from_origin(b_terminations, max_length=max_length)
|
||||||
self.assertEqual(len(cp.path), 3)
|
self.assertLess(len(cp.path), max_length)
|
||||||
|
@ -72,6 +72,7 @@ AUTH_PASSWORD_VALIDATORS = getattr(configuration, 'AUTH_PASSWORD_VALIDATORS', [
|
|||||||
},
|
},
|
||||||
])
|
])
|
||||||
BASE_PATH = trailing_slash(getattr(configuration, 'BASE_PATH', ''))
|
BASE_PATH = trailing_slash(getattr(configuration, 'BASE_PATH', ''))
|
||||||
|
CABLE_TRACE_MAX_LENGTH = getattr(configuration, 'CABLE_TRACE_MAX_LENGTH', 99999)
|
||||||
CHANGELOG_SKIP_EMPTY_CHANGES = getattr(configuration, 'CHANGELOG_SKIP_EMPTY_CHANGES', True)
|
CHANGELOG_SKIP_EMPTY_CHANGES = getattr(configuration, 'CHANGELOG_SKIP_EMPTY_CHANGES', True)
|
||||||
CENSUS_REPORTING_ENABLED = getattr(configuration, 'CENSUS_REPORTING_ENABLED', True)
|
CENSUS_REPORTING_ENABLED = getattr(configuration, 'CENSUS_REPORTING_ENABLED', True)
|
||||||
CORS_ORIGIN_ALLOW_ALL = getattr(configuration, 'CORS_ORIGIN_ALLOW_ALL', False)
|
CORS_ORIGIN_ALLOW_ALL = getattr(configuration, 'CORS_ORIGIN_ALLOW_ALL', False)
|
||||||
|
Loading…
Reference in New Issue
Block a user