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 92eb5eb48b
commit 8c936f10c5
2 changed files with 14 additions and 5 deletions

View File

@ -313,6 +313,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 {
dst := unit.Destination(root) dst := unit.Destination(root)
if unit.Content != "" { if unit.Content != "" {
@ -349,7 +350,7 @@ func processUnits(units []system.Unit, root string, um system.UnitManager) error
} }
if unit.Group() == "network" { if unit.Group() == "network" {
actions = append(actions, action{"systemd-networkd.service", "restart"}) restartNetworkd = true
} else if unit.Command != "" { } else if unit.Command != "" {
actions = append(actions, action{unit.Name, unit.Command}) actions = append(actions, action{unit.Name, unit.Command})
} }
@ -361,6 +362,10 @@ func processUnits(units []system.Unit, root string, um system.UnitManager) error
} }
} }
if restartNetworkd {
actions = append(actions, action{"systemd-networkd.service", "restart"})
}
for _, action := range actions { for _, action := range actions {
log.Printf("Calling unit command '%s %s'", action.command, action.unit) log.Printf("Calling unit command '%s %s'", action.command, action.unit)
res, err := um.RunUnitCommand(action.command, action.unit) res, err := um.RunUnitCommand(action.command, action.unit)

View File

@ -384,10 +384,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(unit *system.Unit, dst string) error { func (tum *TestUnitManager) PlaceUnit(unit *system.Unit, dst string) error {
tum.placed = append(tum.placed, unit.Name) tum.placed = append(tum.placed, unit.Name)
return nil return nil
@ -397,8 +402,7 @@ func (tum *TestUnitManager) EnableUnitFile(unit string, runtime bool) error {
return nil return nil
} }
func (tum *TestUnitManager) RunUnitCommand(command, unit string) (string, error) { func (tum *TestUnitManager) RunUnitCommand(command, unit string) (string, error) {
tum.commands = make(map[string]string) tum.commands = append(tum.commands, UnitAction{unit, command})
tum.commands[unit] = command
return "", nil return "", nil
} }
func (tum *TestUnitManager) DaemonReload() error { func (tum *TestUnitManager) DaemonReload() error {
@ -438,7 +442,7 @@ func TestProcessUnits(t *testing.T) {
if err := processUnits(units, "", tum); err != nil { if err := processUnits(units, "", tum); err != nil {
t.Fatalf("unexpected error calling processUnits: %v", err) t.Fatalf("unexpected error calling processUnits: %v", err)
} }
if _, ok := tum.commands["systemd-networkd.service"]; !ok { if len(tum.commands) != 1 || (tum.commands[0] != UnitAction{"systemd-networkd.service", "restart"}) {
t.Errorf("expected systemd-networkd.service to be reloaded!") t.Errorf("expected systemd-networkd.service to be reloaded!")
} }