From a575d0a8f979efd6b6ff3d4ef5a88a9e20214d93 Mon Sep 17 00:00:00 2001 From: Rudi Chiarito Date: Sat, 2 Jan 2016 23:51:53 -0500 Subject: [PATCH] Fix: deal properly with tc qdisc show returning "noqueue" --- pkg/util/bandwidth/linux.go | 6 ++++++ pkg/util/bandwidth/linux_test.go | 16 +++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/pkg/util/bandwidth/linux.go b/pkg/util/bandwidth/linux.go index dd45e822bac1..b5aeaa714878 100644 --- a/pkg/util/bandwidth/linux.go +++ b/pkg/util/bandwidth/linux.go @@ -224,6 +224,12 @@ func (t *tcShaper) interfaceExists() (bool, string, error) { if len(value) == 0 { return false, "", nil } + // Newer versions of tc and/or the kernel return the following instead of nothing: + // qdisc noqueue 0: root refcnt 2 + fields := strings.Fields(value) + if len(fields) > 1 && fields[1] == "noqueue" { + return false, "", nil + } return true, value, nil } diff --git a/pkg/util/bandwidth/linux_test.go b/pkg/util/bandwidth/linux_test.go index a1ac3e216b3e..c1103e35c51a 100644 --- a/pkg/util/bandwidth/linux_test.go +++ b/pkg/util/bandwidth/linux_test.go @@ -490,11 +490,11 @@ func TestReconcileInterfaceExists(t *testing.T) { } } -func TestReconcileInterfaceDoesntExist(t *testing.T) { +func testReconcileInterfaceHasNoData(t *testing.T, output string) { fcmd := exec.FakeCmd{ CombinedOutputScript: []exec.FakeCombinedOutputAction{ - func() ([]byte, error) { return []byte("\n"), nil }, - func() ([]byte, error) { return []byte("\n"), nil }, + func() ([]byte, error) { return []byte(output), nil }, + func() ([]byte, error) { return []byte(output), nil }, }, } @@ -547,6 +547,16 @@ func TestReconcileInterfaceDoesntExist(t *testing.T) { } } +func TestReconcileInterfaceDoesntExist(t *testing.T) { + testReconcileInterfaceHasNoData(t, "\n") +} + +var tcQdiscNoqueue = "qdisc noqueue 0: root refcnt 2 \n" + +func TestReconcileInterfaceExistsWithNoqueue(t *testing.T) { + testReconcileInterfaceHasNoData(t, tcQdiscNoqueue) +} + var tcQdiscWrong = []string{ "qdisc htb 2: root refcnt 2 r2q 10 default 30 direct_packets_stat 0\n", "qdisc foo 1: root refcnt 2 r2q 10 default 30 direct_packets_stat 0\n",