networkd: Reverse lexicographic order of generated unit files

This commit is contained in:
Alex Crawford 2014-07-17 20:47:37 -07:00
parent 0b82cd074d
commit 1b10a3a187
2 changed files with 16 additions and 12 deletions

View File

@ -277,13 +277,17 @@ func markConfigDepths(interfaceMap map[string]networkInterface) {
} }
} }
for _, iface := range rootInterfaceMap { for _, iface := range rootInterfaceMap {
setDepth(iface, 0) setDepth(iface)
} }
} }
func setDepth(iface networkInterface, depth int) { func setDepth(iface networkInterface) int {
iface.setConfigDepth(depth) maxDepth := 0
for _, child := range iface.Children() { for _, child := range iface.Children() {
setDepth(child, depth+1) if depth := setDepth(child); depth > maxDepth {
maxDepth = depth
} }
}
iface.setConfigDepth(maxDepth)
return (maxDepth + 1)
} }

View File

@ -310,7 +310,7 @@ func TestBuildInterfacesBlindBond(t *testing.T) {
name: "bond0", name: "bond0",
config: configMethodManual{}, config: configMethodManual{},
children: []networkInterface{}, children: []networkInterface{},
configDepth: 1, configDepth: 0,
}, },
[]string{"eth0"}, []string{"eth0"},
map[string]string{}, map[string]string{},
@ -320,7 +320,7 @@ func TestBuildInterfacesBlindBond(t *testing.T) {
name: "eth0", name: "eth0",
config: configMethodManual{}, config: configMethodManual{},
children: []networkInterface{bond0}, children: []networkInterface{bond0},
configDepth: 0, configDepth: 1,
}, },
} }
expect := []InterfaceGenerator{bond0, eth0} expect := []InterfaceGenerator{bond0, eth0}
@ -348,7 +348,7 @@ func TestBuildInterfacesBlindVLAN(t *testing.T) {
name: "vlan0", name: "vlan0",
config: configMethodManual{}, config: configMethodManual{},
children: []networkInterface{}, children: []networkInterface{},
configDepth: 1, configDepth: 0,
}, },
0, 0,
"eth0", "eth0",
@ -358,7 +358,7 @@ func TestBuildInterfacesBlindVLAN(t *testing.T) {
name: "eth0", name: "eth0",
config: configMethodManual{}, config: configMethodManual{},
children: []networkInterface{vlan0}, children: []networkInterface{vlan0},
configDepth: 0, configDepth: 1,
}, },
} }
expect := []InterfaceGenerator{eth0, vlan0} expect := []InterfaceGenerator{eth0, vlan0}
@ -423,7 +423,7 @@ func TestBuildInterfaces(t *testing.T) {
name: "vlan1", name: "vlan1",
config: configMethodManual{}, config: configMethodManual{},
children: []networkInterface{}, children: []networkInterface{},
configDepth: 2, configDepth: 0,
}, },
1, 1,
"bond0", "bond0",
@ -433,7 +433,7 @@ func TestBuildInterfaces(t *testing.T) {
name: "vlan0", name: "vlan0",
config: configMethodManual{}, config: configMethodManual{},
children: []networkInterface{}, children: []networkInterface{},
configDepth: 1, configDepth: 0,
}, },
0, 0,
"eth0", "eth0",
@ -443,7 +443,7 @@ func TestBuildInterfaces(t *testing.T) {
name: "bond1", name: "bond1",
config: configMethodManual{}, config: configMethodManual{},
children: []networkInterface{}, children: []networkInterface{},
configDepth: 2, configDepth: 0,
}, },
[]string{"bond0"}, []string{"bond0"},
map[string]string{}, map[string]string{},
@ -466,7 +466,7 @@ func TestBuildInterfaces(t *testing.T) {
name: "eth0", name: "eth0",
config: configMethodManual{}, config: configMethodManual{},
children: []networkInterface{bond0, vlan0}, children: []networkInterface{bond0, vlan0},
configDepth: 0, configDepth: 2,
}, },
} }
expect := []InterfaceGenerator{eth0, bond0, bond1, vlan0, vlan1} expect := []InterfaceGenerator{eth0, bond0, bond1, vlan0, vlan1}