From 1b10a3a18756209a88d83755e1af5d7c157ade84 Mon Sep 17 00:00:00 2001 From: Alex Crawford Date: Thu, 17 Jul 2014 20:47:37 -0700 Subject: [PATCH] networkd: Reverse lexicographic order of generated unit files --- network/interface.go | 12 ++++++++---- network/interface_test.go | 16 ++++++++-------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/network/interface.go b/network/interface.go index e8e4752..0f34739 100644 --- a/network/interface.go +++ b/network/interface.go @@ -277,13 +277,17 @@ func markConfigDepths(interfaceMap map[string]networkInterface) { } } for _, iface := range rootInterfaceMap { - setDepth(iface, 0) + setDepth(iface) } } -func setDepth(iface networkInterface, depth int) { - iface.setConfigDepth(depth) +func setDepth(iface networkInterface) int { + maxDepth := 0 for _, child := range iface.Children() { - setDepth(child, depth+1) + if depth := setDepth(child); depth > maxDepth { + maxDepth = depth + } } + iface.setConfigDepth(maxDepth) + return (maxDepth + 1) } diff --git a/network/interface_test.go b/network/interface_test.go index eaf1aff..4eb3299 100644 --- a/network/interface_test.go +++ b/network/interface_test.go @@ -310,7 +310,7 @@ func TestBuildInterfacesBlindBond(t *testing.T) { name: "bond0", config: configMethodManual{}, children: []networkInterface{}, - configDepth: 1, + configDepth: 0, }, []string{"eth0"}, map[string]string{}, @@ -320,7 +320,7 @@ func TestBuildInterfacesBlindBond(t *testing.T) { name: "eth0", config: configMethodManual{}, children: []networkInterface{bond0}, - configDepth: 0, + configDepth: 1, }, } expect := []InterfaceGenerator{bond0, eth0} @@ -348,7 +348,7 @@ func TestBuildInterfacesBlindVLAN(t *testing.T) { name: "vlan0", config: configMethodManual{}, children: []networkInterface{}, - configDepth: 1, + configDepth: 0, }, 0, "eth0", @@ -358,7 +358,7 @@ func TestBuildInterfacesBlindVLAN(t *testing.T) { name: "eth0", config: configMethodManual{}, children: []networkInterface{vlan0}, - configDepth: 0, + configDepth: 1, }, } expect := []InterfaceGenerator{eth0, vlan0} @@ -423,7 +423,7 @@ func TestBuildInterfaces(t *testing.T) { name: "vlan1", config: configMethodManual{}, children: []networkInterface{}, - configDepth: 2, + configDepth: 0, }, 1, "bond0", @@ -433,7 +433,7 @@ func TestBuildInterfaces(t *testing.T) { name: "vlan0", config: configMethodManual{}, children: []networkInterface{}, - configDepth: 1, + configDepth: 0, }, 0, "eth0", @@ -443,7 +443,7 @@ func TestBuildInterfaces(t *testing.T) { name: "bond1", config: configMethodManual{}, children: []networkInterface{}, - configDepth: 2, + configDepth: 0, }, []string{"bond0"}, map[string]string{}, @@ -466,7 +466,7 @@ func TestBuildInterfaces(t *testing.T) { name: "eth0", config: configMethodManual{}, children: []networkInterface{bond0, vlan0}, - configDepth: 0, + configDepth: 2, }, } expect := []InterfaceGenerator{eth0, bond0, bond1, vlan0, vlan1}