initialize: only restart networkd once per config

Regression introduced by 9fcf338bf3.

Networkd was erroneously being restarted once per network unit. It
should only restart once for the entire config.
This commit is contained in:
Alex Crawford 2014-12-02 12:46:35 -08:00
parent d0d467813d
commit 2270db3f7a
2 changed files with 19 additions and 7 deletions

View File

@ -200,6 +200,7 @@ func processUnits(units []system.Unit, root string, um system.UnitManager) error
} }
actions := make([]action, 0, len(units)) actions := make([]action, 0, len(units))
reload := false reload := false
restartNetworkd := false
for _, unit := range units { for _, unit := range units {
if unit.Name == "" { if unit.Name == "" {
log.Printf("Skipping unit without name") log.Printf("Skipping unit without name")
@ -251,8 +252,7 @@ func processUnits(units []system.Unit, root string, um system.UnitManager) error
} }
if unit.Group() == "network" { if unit.Group() == "network" {
networkd := system.Unit{Unit: config.Unit{Name: "systemd-networkd.service"}} restartNetworkd = true
actions = append(actions, action{networkd, "restart"})
} else if unit.Command != "" { } else if unit.Command != "" {
actions = append(actions, action{unit, unit.Command}) actions = append(actions, action{unit, unit.Command})
} }
@ -264,6 +264,11 @@ func processUnits(units []system.Unit, root string, um system.UnitManager) error
} }
} }
if restartNetworkd {
networkd := system.Unit{Unit: config.Unit{Name: "systemd-networkd.service"}}
actions = append(actions, action{networkd, "restart"})
}
for _, action := range actions { for _, action := range actions {
log.Printf("Calling unit command %q on %q'", action.command, action.unit.Name) log.Printf("Calling unit command %q on %q'", action.command, action.unit.Name)
res, err := um.RunUnitCommand(action.unit, action.command) res, err := um.RunUnitCommand(action.unit, action.command)

View File

@ -29,10 +29,15 @@ type TestUnitManager struct {
enabled []string enabled []string
masked []string masked []string
unmasked []string unmasked []string
commands map[string]string commands []UnitAction
reload bool reload bool
} }
type UnitAction struct {
unit string
command string
}
func (tum *TestUnitManager) PlaceUnit(u system.Unit) error { func (tum *TestUnitManager) PlaceUnit(u system.Unit) error {
tum.placed = append(tum.placed, u.Name) tum.placed = append(tum.placed, u.Name)
return nil return nil
@ -46,8 +51,7 @@ func (tum *TestUnitManager) EnableUnitFile(u system.Unit) error {
return nil return nil
} }
func (tum *TestUnitManager) RunUnitCommand(u system.Unit, c string) (string, error) { func (tum *TestUnitManager) RunUnitCommand(u system.Unit, c string) (string, error) {
tum.commands = make(map[string]string) tum.commands = append(tum.commands, UnitAction{u.Name, c})
tum.commands[u.Name] = c
return "", nil return "", nil
} }
func (tum *TestUnitManager) DaemonReload() error { func (tum *TestUnitManager) DaemonReload() error {
@ -82,13 +86,16 @@ func TestProcessUnits(t *testing.T) {
}, },
{ {
units: []system.Unit{ units: []system.Unit{
system.Unit{Unit: config.Unit{
Name: "foo.network",
}},
system.Unit{Unit: config.Unit{ system.Unit{Unit: config.Unit{
Name: "bar.network", Name: "bar.network",
}}, }},
}, },
result: TestUnitManager{ result: TestUnitManager{
commands: map[string]string{ commands: []UnitAction{
"systemd-networkd.service": "restart", UnitAction{"systemd-networkd.service", "restart"},
}, },
}, },
}, },