Safely print error
Format plugin code Signed-off-by: Aidan Obley <aobley@pivotal.io>
This commit is contained in:
parent
d2f6472474
commit
fe0cf201f8
@ -105,9 +105,6 @@ var _ = Describe("Basic PTP using cnitool", func() {
|
|||||||
basicBridgeEnv TestEnv
|
basicBridgeEnv TestEnv
|
||||||
chainedBridgeBandwidthEnv TestEnv
|
chainedBridgeBandwidthEnv TestEnv
|
||||||
chainedBridgeBandwidthSession, basicBridgeSession *gexec.Session
|
chainedBridgeBandwidthSession, basicBridgeSession *gexec.Session
|
||||||
chainedBridgeBandwidthPort, basicBridgePort int
|
|
||||||
chainedBridgeIP, basicBridgeIP string
|
|
||||||
runtimeWithLimit, runtimeWithoutLimit time.Duration
|
|
||||||
)
|
)
|
||||||
|
|
||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
@ -154,43 +151,38 @@ var _ = Describe("Basic PTP using cnitool", func() {
|
|||||||
Measure("limits traffic only on the restricted bandwith veth device", func(b Benchmarker) {
|
Measure("limits traffic only on the restricted bandwith veth device", func(b Benchmarker) {
|
||||||
ipRegexp := regexp.MustCompile("10\\.11\\.2\\.\\d{1,3}")
|
ipRegexp := regexp.MustCompile("10\\.11\\.2\\.\\d{1,3}")
|
||||||
|
|
||||||
By(fmt.Sprintf("adding %s to %s\n\n", "chained-bridge-bandwidth", contNS1.ShortName()), func() {
|
By(fmt.Sprintf("adding %s to %s\n\n", "chained-bridge-bandwidth", contNS1.ShortName()))
|
||||||
chainedBridgeBandwidthEnv.runInNS(hostNS, cnitoolBin, "add", "network-chain-test", contNS1.LongName())
|
chainedBridgeBandwidthEnv.runInNS(hostNS, cnitoolBin, "add", "network-chain-test", contNS1.LongName())
|
||||||
chainedBridgeIP = ipRegexp.FindString(chainedBridgeBandwidthEnv.runInNS(contNS1, "ip", "addr"))
|
chainedBridgeIP := ipRegexp.FindString(chainedBridgeBandwidthEnv.runInNS(contNS1, "ip", "addr"))
|
||||||
Expect(chainedBridgeIP).To(ContainSubstring("10.11.2."))
|
Expect(chainedBridgeIP).To(ContainSubstring("10.11.2."))
|
||||||
})
|
|
||||||
|
|
||||||
By(fmt.Sprintf("adding %s to %s\n\n", "basic-bridge", contNS2.ShortName()), func() {
|
By(fmt.Sprintf("adding %s to %s\n\n", "basic-bridge", contNS2.ShortName()))
|
||||||
basicBridgeEnv.runInNS(hostNS, cnitoolBin, "add", "network-chain-test", contNS2.LongName())
|
basicBridgeEnv.runInNS(hostNS, cnitoolBin, "add", "network-chain-test", contNS2.LongName())
|
||||||
basicBridgeIP = ipRegexp.FindString(basicBridgeEnv.runInNS(contNS2, "ip", "addr"))
|
basicBridgeIP := ipRegexp.FindString(basicBridgeEnv.runInNS(contNS2, "ip", "addr"))
|
||||||
Expect(basicBridgeIP).To(ContainSubstring("10.11.2."))
|
Expect(basicBridgeIP).To(ContainSubstring("10.11.2."))
|
||||||
})
|
|
||||||
|
|
||||||
|
var chainedBridgeBandwidthPort, basicBridgePort int
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
By(fmt.Sprintf("starting echo server in %s\n\n", contNS1.ShortName()), func() {
|
By(fmt.Sprintf("starting echo server in %s\n\n", contNS1.ShortName()))
|
||||||
chainedBridgeBandwidthPort, chainedBridgeBandwidthSession, err = startEchoServerInNamespace(contNS1)
|
chainedBridgeBandwidthPort, chainedBridgeBandwidthSession, err = startEchoServerInNamespace(contNS1)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
})
|
|
||||||
|
|
||||||
By(fmt.Sprintf("starting echo server in %s\n\n", contNS2.ShortName()), func() {
|
By(fmt.Sprintf("starting echo server in %s\n\n", contNS2.ShortName()))
|
||||||
basicBridgePort, basicBridgeSession, err = startEchoServerInNamespace(contNS2)
|
basicBridgePort, basicBridgeSession, err = startEchoServerInNamespace(contNS2)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
})
|
|
||||||
|
|
||||||
packetInBytes := 20000 // The shaper needs to 'warm'. Send enough to cause it to throttle,
|
packetInBytes := 20000 // The shaper needs to 'warm'. Send enough to cause it to throttle,
|
||||||
// balanced by run time.
|
// balanced by run time.
|
||||||
|
|
||||||
By(fmt.Sprintf("sending tcp traffic to the chained, bridged, traffic shaped container on ip address '%s:%d'\n\n", chainedBridgeIP, chainedBridgeBandwidthPort), func() {
|
By(fmt.Sprintf("sending tcp traffic to the chained, bridged, traffic shaped container on ip address '%s:%d'\n\n", chainedBridgeIP, chainedBridgeBandwidthPort))
|
||||||
runtimeWithLimit = b.Time("with chained bridge and bandwidth plugins", func() {
|
runtimeWithLimit := b.Time("with chained bridge and bandwidth plugins", func() {
|
||||||
makeTcpClientInNS(hostNS.ShortName(), chainedBridgeIP, chainedBridgeBandwidthPort, packetInBytes)
|
makeTcpClientInNS(hostNS.ShortName(), chainedBridgeIP, chainedBridgeBandwidthPort, packetInBytes)
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
By(fmt.Sprintf("sending tcp traffic to the basic bridged container on ip address '%s:%d'\n\n", basicBridgeIP, basicBridgePort), func() {
|
By(fmt.Sprintf("sending tcp traffic to the basic bridged container on ip address '%s:%d'\n\n", basicBridgeIP, basicBridgePort))
|
||||||
runtimeWithoutLimit = b.Time("with basic bridged plugin", func() {
|
runtimeWithoutLimit := b.Time("with basic bridged plugin", func() {
|
||||||
makeTcpClientInNS(hostNS.ShortName(), basicBridgeIP, basicBridgePort, packetInBytes)
|
makeTcpClientInNS(hostNS.ShortName(), basicBridgeIP, basicBridgePort, packetInBytes)
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
Expect(runtimeWithLimit).To(BeNumerically(">", runtimeWithoutLimit+1000*time.Millisecond))
|
Expect(runtimeWithLimit).To(BeNumerically(">", runtimeWithoutLimit+1000*time.Millisecond))
|
||||||
|
@ -24,9 +24,9 @@ import (
|
|||||||
"github.com/containernetworking/cni/pkg/types/current"
|
"github.com/containernetworking/cni/pkg/types/current"
|
||||||
"github.com/containernetworking/cni/pkg/version"
|
"github.com/containernetworking/cni/pkg/version"
|
||||||
|
|
||||||
|
"errors"
|
||||||
"github.com/containernetworking/plugins/pkg/ip"
|
"github.com/containernetworking/plugins/pkg/ip"
|
||||||
"github.com/vishvananda/netlink"
|
"github.com/vishvananda/netlink"
|
||||||
"errors"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type PluginConf struct {
|
type PluginConf struct {
|
||||||
@ -113,6 +113,10 @@ func getMTU(deviceName string) (int, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getHostInterface(interfaces []*current.Interface) (*current.Interface, error) {
|
func getHostInterface(interfaces []*current.Interface) (*current.Interface, error) {
|
||||||
|
if len(interfaces) == 0 {
|
||||||
|
return nil, errors.New("no interfaces provided")
|
||||||
|
}
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
for _, iface := range interfaces {
|
for _, iface := range interfaces {
|
||||||
if iface.Sandbox == "" { // host interface
|
if iface.Sandbox == "" { // host interface
|
||||||
@ -122,7 +126,7 @@ func getHostInterface(interfaces []*current.Interface) (*current.Interface, erro
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil, errors.New("no host interface found: " + err.Error())
|
return nil, errors.New(fmt.Sprintf("no host interface found. last error: %s", err))
|
||||||
}
|
}
|
||||||
|
|
||||||
func cmdAdd(args *skel.CmdArgs) error {
|
func cmdAdd(args *skel.CmdArgs) error {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user