Fix interface ordering of Loopback1.1 interfaces (or ae0, ae0.1, ae1, ae1.1 in Junipers).

This commit is contained in:
Arnoud Vermeer 2018-07-05 12:01:05 +02:00
parent b10635a9b1
commit f00f717bfb
2 changed files with 11 additions and 4 deletions

View File

@ -44,7 +44,7 @@ class InterfaceQuerySet(QuerySet):
TYPE_RE = r"SUBSTRING({} FROM '^([^0-9]+)')" TYPE_RE = r"SUBSTRING({} FROM '^([^0-9]+)')"
ID_RE = r"CAST(SUBSTRING({} FROM '^(?:[^0-9]+)(\d{{1,9}})$') AS integer)" ID_RE = r"CAST(SUBSTRING({} FROM '^(?:[^0-9]+)(\d{{1,9}})$') AS integer)"
SLOT_RE = r"CAST(SUBSTRING({} FROM '^(?:[^0-9]+)?(\d{{1,9}})\/') AS integer)" SLOT_RE = r"CAST(SUBSTRING({} FROM '^(?:[^0-9]+)?(\d{{1,9}})\/?') AS integer)"
SUBSLOT_RE = r"COALESCE(CAST(SUBSTRING({} FROM '^(?:[^0-9]+)?(?:\d{{1,9}}\/)(\d{{1,9}})') AS integer), 0)" SUBSLOT_RE = r"COALESCE(CAST(SUBSTRING({} FROM '^(?:[^0-9]+)?(?:\d{{1,9}}\/)(\d{{1,9}})') AS integer), 0)"
POSITION_RE = r"COALESCE(CAST(SUBSTRING({} FROM '^(?:[^0-9]+)?(?:\d{{1,9}}\/){{2}}(\d{{1,9}})') AS integer), 0)" POSITION_RE = r"COALESCE(CAST(SUBSTRING({} FROM '^(?:[^0-9]+)?(?:\d{{1,9}}\/){{2}}(\d{{1,9}})') AS integer), 0)"
SUBPOSITION_RE = r"COALESCE(CAST(SUBSTRING({} FROM '^(?:[^0-9]+)?(?:\d{{1,9}}\/){{3}}(\d{{1,9}})') AS integer), 0)" SUBPOSITION_RE = r"COALESCE(CAST(SUBSTRING({} FROM '^(?:[^0-9]+)?(?:\d{{1,9}}\/){{3}}(\d{{1,9}})') AS integer), 0)"

View File

@ -216,10 +216,9 @@ class InterfaceTestCase(TestCase):
device=device1, device=device1,
name='Loopback1' name='Loopback1'
) )
self.assertEqual( self.assertEqual(
list(Interface.objects.all().order_naturally()), list(Interface.objects.all().order_naturally()),
[interface1, interface5, interface4, interface3, interface2, interface6] [interface6, interface1, interface5, interface4, interface3, interface2]
) )
def test_interface_order_natural_subinterfaces(self): def test_interface_order_natural_subinterfaces(self):
@ -256,7 +255,15 @@ class InterfaceTestCase(TestCase):
device=device1, device=device1,
name='GigabitEthernet0' name='GigabitEthernet0'
) )
interface7 = Interface.objects.create(
device=device1,
name='Loopback1'
)
interface8 = Interface.objects.create(
device=device1,
name='Loopback1.1'
)
self.assertEqual( self.assertEqual(
list(Interface.objects.all().order_naturally()), list(Interface.objects.all().order_naturally()),
[interface4, interface3, interface5, interface2, interface1, interface6] [interface6, interface4, interface3, interface5, interface2, interface1, interface7, interface8]
) )