From e94d00c2c1cfba7d83a790891ca72d761c059dbb Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Wed, 2 Apr 2025 13:59:49 -0400 Subject: [PATCH] Fix tests --- netbox/ipam/tests/test_models.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/netbox/ipam/tests/test_models.py b/netbox/ipam/tests/test_models.py index 62eb74123..f41c93539 100644 --- a/netbox/ipam/tests/test_models.py +++ b/netbox/ipam/tests/test_models.py @@ -211,16 +211,25 @@ class TestPrefix(TestCase): IPAddress(address=IPNetwork('10.0.0.5/26')), IPAddress(address=IPNetwork('10.0.0.7/26')), )) + # Range is not marked as populated, so it doesn't count against available IP space IPRange.objects.create( start_address=IPNetwork('10.0.0.9/26'), - end_address=IPNetwork('10.0.0.12/26') + end_address=IPNetwork('10.0.0.10/26') + ) + # Populated range reduces available IP space + IPRange.objects.create( + start_address=IPNetwork('10.0.0.12/26'), + end_address=IPNetwork('10.0.0.13/26'), + mark_populated=True ) missing_ips = IPSet([ '10.0.0.2/32', '10.0.0.4/32', '10.0.0.6/32', '10.0.0.8/32', - '10.0.0.13/32', + '10.0.0.9/32', + '10.0.0.10/32', + '10.0.0.11/32', '10.0.0.14/32', ]) available_ips = parent_prefix.get_available_ips() @@ -286,8 +295,12 @@ class TestPrefix(TestCase): ]) self.assertEqual(prefix.get_utilization(), 32 / 254 * 100) # ~12.5% utilization - # Create a child range with 32 additional IPs - IPRange.objects.create(start_address=IPNetwork('10.0.0.33/24'), end_address=IPNetwork('10.0.0.64/24')) + # Create a utilized child range with 32 additional IPs + IPRange.objects.create( + start_address=IPNetwork('10.0.0.33/24'), + end_address=IPNetwork('10.0.0.64/24'), + mark_utilized=True + ) self.assertEqual(prefix.get_utilization(), 64 / 254 * 100) # ~25% utilization #