Skip to content

Commit

Permalink
reset all interfaces in case of error to avoid subsequent errors caus…
Browse files Browse the repository at this point in the history
…ed by re-executions of the same command for working interfaces
  • Loading branch information
h0nIg committed Mar 15, 2019
1 parent 2e8fbdf commit 794cbda
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions src/github.com/cppforlife/turbulence/tasks/control_net_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package tasks

import (
"regexp"
"strings"

bosherr "github.com/cloudfoundry/bosh-utils/errors"
boshlog "github.com/cloudfoundry/bosh-utils/logger"
Expand Down Expand Up @@ -96,6 +97,7 @@ func (t ControlNetTask) Execute(stopCh chan struct{}) error {
for _, ifaceName := range ifaceNames {
err := t.configureBandwidth(ifaceName)
if err != nil {
t.resetIfaces(ifaceNames)
return err
}
}
Expand Down Expand Up @@ -128,6 +130,7 @@ func (t ControlNetTask) Execute(stopCh chan struct{}) error {
for _, ifaceName := range ifaceNames {
err := t.configureInterface(ifaceName, opts)
if err != nil {
t.resetIfaces(ifaceNames)
return err
}
}
Expand All @@ -138,14 +141,8 @@ func (t ControlNetTask) Execute(stopCh chan struct{}) error {
case <-stopCh:
}

for _, ifaceName := range ifaceNames {
err := t.resetIface(ifaceName)
if err != nil {
return err
}
}

return nil
return t.resetIfaces(ifaceNames)
}

func (t ControlNetTask) configureInterface(ifaceName string, opts []string) error {
Expand All @@ -172,7 +169,6 @@ func (t ControlNetTask) configureBandwidth(ifaceName string) error {

_, _, _, err = t.cmdRunner.RunCommand("tc", "class", "add", "dev", ifaceName, "parent", "1:", "classid", "1:1", "htb", "rate", t.opts.Bandwidth)
if err != nil {
t.resetIface(ifaceName)
return err
}

Expand Down Expand Up @@ -232,18 +228,29 @@ func (t ControlNetTask) configureDestination(ifaceName string) error {

_, _, _, err := t.cmdRunner.RunCommand("tc", args...)
if err != nil {
t.resetIface(ifaceName)
return err
}
}

return nil
}

func (t ControlNetTask) resetIface(ifaceName string) error {
_, _, _, err := t.cmdRunner.RunCommand("tc", "qdisc", "del", "dev", ifaceName, "root")
if err != nil {
return bosherr.WrapError(err, "Resetting tc")
func (t ControlNetTask) resetIfaces(ifaceNames []string) error {
errors := []error{}
for _, ifaceName := range ifaceNames {
_, _, _, err := t.cmdRunner.RunCommand("tc", "qdisc", "del", "dev", ifaceName, "root")
if err != nil {
errors = append(errors, err)
}
}

if len(errors) != 0 {
msgs := []string{}
for _, error := range errors {
msgs = append(msgs, error.Error())
}

return bosherr.Errorf("Errors detected during reset: %s", strings.Join(msgs," "))
}

return nil
Expand Down

0 comments on commit 794cbda

Please sign in to comment.