Jeremy Stretch 6 лет назад
Родитель
Сommit
2571f22ae5

+ 0 - 1
docs/release-notes/version-2.7.md

@@ -15,7 +15,6 @@
 ### Bug Fixes
 ### Bug Fixes
 
 
 * [#4326](https://github.com/netbox-community/netbox/issues/4326) - Exclude Python modules without Script classes from scripts list
 * [#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
 * [#4337](https://github.com/netbox-community/netbox/issues/4337) - Allow bulk editing/deletion of all device components matching a query
 * [#4337](https://github.com/netbox-community/netbox/issues/4337) - Allow bulk editing/deletion of all device components matching a query
 
 
 ---
 ---

+ 24 - 17
netbox/dcim/tests/test_natural_ordering.py

@@ -19,14 +19,9 @@ class NaturalOrderingTestCase(TestCase):
             device_type=devicetype, device_role=devicerole, name='Test Device 1', site=site
             device_type=devicetype, device_role=devicerole, name='Test Device 1', site=site
         )
         )
 
 
-    def _compare_names(self, queryset, names):
-
-        for i, obj in enumerate(queryset):
-            self.assertEqual(obj.name, names[i])
-
     def test_interface_ordering_numeric(self):
     def test_interface_ordering_numeric(self):
 
 
-        INTERFACES = (
+        INTERFACES = [
             '0',
             '0',
             '0.1',
             '0.1',
             '0.2',
             '0.2',
@@ -53,17 +48,20 @@ class NaturalOrderingTestCase(TestCase):
             '1:2.1',
             '1:2.1',
             '1:2.2',
             '1:2.2',
             '1:2.10',
             '1:2.10',
-        )
+        ]
 
 
         for name in INTERFACES:
         for name in INTERFACES:
             iface = Interface(device=self.device, name=name)
             iface = Interface(device=self.device, name=name)
             iface.save()
             iface.save()
 
 
-        self._compare_names(Interface.objects.filter(device=self.device), INTERFACES)
+        self.assertListEqual(
+            list(Interface.objects.filter(device=self.device).values_list('name', flat=True)),
+            INTERFACES
+        )
 
 
     def test_interface_ordering_linux(self):
     def test_interface_ordering_linux(self):
 
 
-        INTERFACES = (
+        INTERFACES = [
             'eth0',
             'eth0',
             'eth0.1',
             'eth0.1',
             'eth0.2',
             'eth0.2',
@@ -74,17 +72,20 @@ class NaturalOrderingTestCase(TestCase):
             'eth1.2',
             'eth1.2',
             'eth1.100',
             'eth1.100',
             'lo0',
             'lo0',
-        )
+        ]
 
 
         for name in INTERFACES:
         for name in INTERFACES:
             iface = Interface(device=self.device, name=name)
             iface = Interface(device=self.device, name=name)
             iface.save()
             iface.save()
 
 
-        self._compare_names(Interface.objects.filter(device=self.device), INTERFACES)
+        self.assertListEqual(
+            list(Interface.objects.filter(device=self.device).values_list('name', flat=True)),
+            INTERFACES
+        )
 
 
     def test_interface_ordering_junos(self):
     def test_interface_ordering_junos(self):
 
 
-        INTERFACES = (
+        INTERFACES = [
             'xe-0/0/0',
             'xe-0/0/0',
             'xe-0/0/1',
             'xe-0/0/1',
             'xe-0/0/2',
             'xe-0/0/2',
@@ -124,17 +125,20 @@ class NaturalOrderingTestCase(TestCase):
             'irb.10',
             'irb.10',
             'irb.100',
             'irb.100',
             'lo0',
             'lo0',
-        )
+        ]
 
 
         for name in INTERFACES:
         for name in INTERFACES:
             iface = Interface(device=self.device, name=name)
             iface = Interface(device=self.device, name=name)
             iface.save()
             iface.save()
 
 
-        self._compare_names(Interface.objects.filter(device=self.device), INTERFACES)
+        self.assertListEqual(
+            list(Interface.objects.filter(device=self.device).values_list('name', flat=True)),
+            INTERFACES
+        )
 
 
     def test_interface_ordering_ios(self):
     def test_interface_ordering_ios(self):
 
 
-        INTERFACES = (
+        INTERFACES = [
             'GigabitEthernet0/1',
             'GigabitEthernet0/1',
             'GigabitEthernet0/2',
             'GigabitEthernet0/2',
             'GigabitEthernet0/10',
             'GigabitEthernet0/10',
@@ -148,10 +152,13 @@ class NaturalOrderingTestCase(TestCase):
             'FastEthernet1',
             'FastEthernet1',
             'FastEthernet2',
             'FastEthernet2',
             'FastEthernet10',
             'FastEthernet10',
-        )
+        ]
 
 
         for name in INTERFACES:
         for name in INTERFACES:
             iface = Interface(device=self.device, name=name)
             iface = Interface(device=self.device, name=name)
             iface.save()
             iface.save()
 
 
-        self._compare_names(Interface.objects.filter(device=self.device), INTERFACES)
+        self.assertListEqual(
+            list(Interface.objects.filter(device=self.device).values_list('name', flat=True)),
+            INTERFACES
+        )

+ 1 - 2
netbox/utilities/ordering.py

@@ -75,8 +75,7 @@ def naturalize_interface(value, max_length):
         if part is not None:
         if part is not None:
             output += part.rjust(6, '0')
             output += part.rjust(6, '0')
         else:
         else:
-            # Append a "null" signifier to ensure ordering before a zero value
-            output += '......'
+            output += '000000'
 
 
     # Finally, naturalize any remaining text and append it
     # Finally, naturalize any remaining text and append it
     if match.group('remainder') is not None and len(output) < max_length:
     if match.group('remainder') is not None and len(output) < max_length:

+ 16 - 16
netbox/utilities/tests/test_ordering.py

@@ -31,28 +31,28 @@ class NaturalizationTestCase(TestCase):
         # Original, naturalized
         # Original, naturalized
         data = (
         data = (
             # IOS/JunOS-style
             # IOS/JunOS-style
-            ('Gi', '9999999999999999Gi..................'),
-            ('Gi1', '9999999999999999Gi000001............'),
-            ('Gi1.0', '9999999999999999Gi000001......000000'),
-            ('Gi1.1', '9999999999999999Gi000001......000001'),
-            ('Gi1:0', '9999999999999999Gi000001000000......'),
+            ('Gi', '9999999999999999Gi000000000000000000'),
+            ('Gi1', '9999999999999999Gi000001000000000000'),
+            ('Gi1.0', '9999999999999999Gi000001000000000000'),
+            ('Gi1.1', '9999999999999999Gi000001000000000001'),
+            ('Gi1:0', '9999999999999999Gi000001000000000000'),
             ('Gi1:0.0', '9999999999999999Gi000001000000000000'),
             ('Gi1:0.0', '9999999999999999Gi000001000000000000'),
             ('Gi1:0.1', '9999999999999999Gi000001000000000001'),
             ('Gi1:0.1', '9999999999999999Gi000001000000000001'),
-            ('Gi1:1', '9999999999999999Gi000001000001......'),
+            ('Gi1:1', '9999999999999999Gi000001000001000000'),
             ('Gi1:1.0', '9999999999999999Gi000001000001000000'),
             ('Gi1:1.0', '9999999999999999Gi000001000001000000'),
             ('Gi1:1.1', '9999999999999999Gi000001000001000001'),
             ('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', '0001999999999999Gi000002000000000000'),
+            ('Gi1/2/3', '0001000299999999Gi000003000000000000'),
+            ('Gi1/2/3/4', '0001000200039999Gi000004000000000000'),
+            ('Gi1/2/3/4/5', '0001000200030004Gi000005000000000000'),
+            ('Gi1/2/3/4/5:6', '0001000200030004Gi000005000006000000'),
             ('Gi1/2/3/4/5:6.7', '0001000200030004Gi000005000006000007'),
             ('Gi1/2/3/4/5:6.7', '0001000200030004Gi000005000006000007'),
             # Generic
             # Generic
-            ('Interface 1', '9999999999999999Interface 000001............'),
-            ('Interface 1 (other)', '9999999999999999Interface 000001............ (other)'),
-            ('Interface 99', '9999999999999999Interface 000099............'),
-            ('PCIe1-p1', '9999999999999999PCIe000001............-p00000001'),
-            ('PCIe1-p99', '9999999999999999PCIe000001............-p00000099'),
+            ('Interface 1', '9999999999999999Interface 000001000000000000'),
+            ('Interface 1 (other)', '9999999999999999Interface 000001000000000000 (other)'),
+            ('Interface 99', '9999999999999999Interface 000099000000000000'),
+            ('PCIe1-p1', '9999999999999999PCIe000001000000000000-p00000001'),
+            ('PCIe1-p99', '9999999999999999PCIe000001000000000000-p00000099'),
         )
         )
 
 
         for origin, naturalized in data:
         for origin, naturalized in data: