From bb3f37ca3588c508eb97a1a15139ecc67c0d4578 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Tue, 10 Mar 2020 10:03:42 -0400 Subject: [PATCH] Fixes #4336: Ensure interfaces without a channel/unit are ordered before a channel/unit of zero --- docs/release-notes/version-2.7.md | 1 + netbox/utilities/ordering.py | 3 ++- netbox/utilities/tests/test_ordering.py | 34 +++++++++++++++---------- 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/docs/release-notes/version-2.7.md b/docs/release-notes/version-2.7.md index 4c238dac3..d63f1d908 100644 --- a/docs/release-notes/version-2.7.md +++ b/docs/release-notes/version-2.7.md @@ -15,6 +15,7 @@ ### Bug Fixes * [#4326](https://github.com/netbox-community/netbox/issues/4326) - Exclude Python modules without Script classes from scripts list +* [#4336](https://github.com/netbox-community/netbox/issues/4336) - Ensure interfaces without a channel/unit are ordered before a channel/unit of zero --- diff --git a/netbox/utilities/ordering.py b/netbox/utilities/ordering.py index 346a99488..bd450780a 100644 --- a/netbox/utilities/ordering.py +++ b/netbox/utilities/ordering.py @@ -75,7 +75,8 @@ def naturalize_interface(value, max_length): if part is not None: output += part.rjust(6, '0') else: - output += '000000' + # Append a "null" signifier to ensure ordering before a zero value + output += '......' # Finally, naturalize any remaining text and append it if match.group('remainder') is not None and len(output) < max_length: diff --git a/netbox/utilities/tests/test_ordering.py b/netbox/utilities/tests/test_ordering.py index 30692f46a..47b9348f6 100644 --- a/netbox/utilities/tests/test_ordering.py +++ b/netbox/utilities/tests/test_ordering.py @@ -31,22 +31,28 @@ class NaturalizationTestCase(TestCase): # Original, naturalized data = ( # IOS/JunOS-style - ('Gi', '9999999999999999Gi000000000000000000'), - ('Gi1', '9999999999999999Gi000001000000000000'), - ('Gi1/2', '0001999999999999Gi000002000000000000'), - ('Gi1/2/3', '0001000299999999Gi000003000000000000'), - ('Gi1/2/3/4', '0001000200039999Gi000004000000000000'), - ('Gi1/2/3/4/5', '0001000200030004Gi000005000000000000'), - ('Gi1/2/3/4/5:6', '0001000200030004Gi000005000006000000'), + ('Gi', '9999999999999999Gi..................'), + ('Gi1', '9999999999999999Gi000001............'), + ('Gi1.0', '9999999999999999Gi000001......000000'), + ('Gi1.1', '9999999999999999Gi000001......000001'), + ('Gi1:0', '9999999999999999Gi000001000000......'), + ('Gi1:0.0', '9999999999999999Gi000001000000000000'), + ('Gi1:0.1', '9999999999999999Gi000001000000000001'), + ('Gi1:1', '9999999999999999Gi000001000001......'), + ('Gi1:1.0', '9999999999999999Gi000001000001000000'), + ('Gi1:1.1', '9999999999999999Gi000001000001000001'), + ('Gi1/2', '0001999999999999Gi000002............'), + ('Gi1/2/3', '0001000299999999Gi000003............'), + ('Gi1/2/3/4', '0001000200039999Gi000004............'), + ('Gi1/2/3/4/5', '0001000200030004Gi000005............'), + ('Gi1/2/3/4/5:6', '0001000200030004Gi000005000006......'), ('Gi1/2/3/4/5:6.7', '0001000200030004Gi000005000006000007'), - ('Gi1:2', '9999999999999999Gi000001000002000000'), - ('Gi1:2.3', '9999999999999999Gi000001000002000003'), # Generic - ('Interface 1', '9999999999999999Interface 000001000000000000'), - ('Interface 1 (other)', '9999999999999999Interface 000001000000000000 (other)'), - ('Interface 99', '9999999999999999Interface 000099000000000000'), - ('PCIe1-p1', '9999999999999999PCIe000001000000000000-p00000001'), - ('PCIe1-p99', '9999999999999999PCIe000001000000000000-p00000099'), + ('Interface 1', '9999999999999999Interface 000001............'), + ('Interface 1 (other)', '9999999999999999Interface 000001............ (other)'), + ('Interface 99', '9999999999999999Interface 000099............'), + ('PCIe1-p1', '9999999999999999PCIe000001............-p00000001'), + ('PCIe1-p99', '9999999999999999PCIe000001............-p00000099'), ) for origin, naturalized in data: