Skip to content

Commit 3906b83

Browse files
committed
reset all interfaces in case of error to avoid subsequent errors caused by re-executions of the same command for working interfaces
1 parent e972bc5 commit 3906b83

1 file changed

Lines changed: 20 additions & 13 deletions

File tree

src/github.com/cppforlife/turbulence/tasks/control_net_task.go

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package tasks
22

33
import (
44
"regexp"
5+
"strings"
56

67
bosherr "github.com/cloudfoundry/bosh-utils/errors"
78
boshlog "github.com/cloudfoundry/bosh-utils/logger"
@@ -96,6 +97,7 @@ func (t ControlNetTask) Execute(stopCh chan struct{}) error {
9697
for _, ifaceName := range ifaceNames {
9798
err := t.configureBandwidth(ifaceName)
9899
if err != nil {
100+
t.resetIfaces(ifaceNames)
99101
return err
100102
}
101103
}
@@ -128,6 +130,7 @@ func (t ControlNetTask) Execute(stopCh chan struct{}) error {
128130
for _, ifaceName := range ifaceNames {
129131
err := t.configureInterface(ifaceName, opts)
130132
if err != nil {
133+
t.resetIfaces(ifaceNames)
131134
return err
132135
}
133136
}
@@ -138,14 +141,8 @@ func (t ControlNetTask) Execute(stopCh chan struct{}) error {
138141
case <-stopCh:
139142
}
140143

141-
for _, ifaceName := range ifaceNames {
142-
err := t.resetIface(ifaceName)
143-
if err != nil {
144-
return err
145-
}
146-
}
147144

148-
return nil
145+
return t.resetIfaces(ifaceNames)
149146
}
150147

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

173170
_, _, _, err = t.cmdRunner.RunCommand("tc", "class", "add", "dev", ifaceName, "parent", "1:0", "classid", "1:1", "htb", "rate", t.opts.Bandwidth)
174171
if err != nil {
175-
t.resetIface(ifaceName)
176172
return err
177173
}
178174

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

233229
_, _, _, err := t.cmdRunner.RunCommand("tc", args...)
234230
if err != nil {
235-
t.resetIface(ifaceName)
236231
return err
237232
}
238233
}
239234

240235
return nil
241236
}
242237

243-
func (t ControlNetTask) resetIface(ifaceName string) error {
244-
_, _, _, err := t.cmdRunner.RunCommand("tc", "qdisc", "del", "dev", ifaceName, "root")
245-
if err != nil {
246-
return bosherr.WrapError(err, "Resetting tc")
238+
func (t ControlNetTask) resetIfaces(ifaceNames []string) error {
239+
errors := []error{}
240+
for _, ifaceName := range ifaceNames {
241+
_, _, _, err := t.cmdRunner.RunCommand("tc", "qdisc", "del", "dev", ifaceName, "root")
242+
if err != nil {
243+
errors = append(errors, err)
244+
}
245+
}
246+
247+
if len(errors) != 0 {
248+
msgs := []string{}
249+
for _, error := range errors {
250+
msgs = append(msgs, error.Error())
251+
}
252+
253+
return bosherr.Errorf("Errors detected during reset: %s", strings.Join(msgs," "))
247254
}
248255

249256
return nil

0 commit comments

Comments
 (0)