From 028ac8034b1f2e8afd26bdcb257454227be162cd Mon Sep 17 00:00:00 2001 From: Wojciech Tyczynski Date: Thu, 18 May 2017 11:35:49 +0200 Subject: [PATCH] Remove SaveAll from iptables interface --- pkg/kubelet/network/hostport/fake_iptables.go | 14 ----- pkg/util/iptables/iptables.go | 12 ----- pkg/util/iptables/iptables_test.go | 53 ------------------- pkg/util/iptables/testing/fake.go | 4 -- 4 files changed, 83 deletions(-) diff --git a/pkg/kubelet/network/hostport/fake_iptables.go b/pkg/kubelet/network/hostport/fake_iptables.go index d8c05baddc..e6dde8f52c 100644 --- a/pkg/kubelet/network/hostport/fake_iptables.go +++ b/pkg/kubelet/network/hostport/fake_iptables.go @@ -246,20 +246,6 @@ func (f *fakeIPTables) Save(tableName utiliptables.Table) ([]byte, error) { return data.Bytes(), nil } -func (f *fakeIPTables) SaveAll() ([]byte, error) { - data := bytes.NewBuffer(nil) - for _, table := range f.tables { - tableData, err := f.Save(table.name) - if err != nil { - return nil, err - } - if _, err = data.Write(tableData); err != nil { - return nil, err - } - } - return data.Bytes(), nil -} - func (f *fakeIPTables) restore(restoreTableName utiliptables.Table, data []byte, flush utiliptables.FlushFlag) error { buf := bytes.NewBuffer(data) var tableName utiliptables.Table diff --git a/pkg/util/iptables/iptables.go b/pkg/util/iptables/iptables.go index 2d3c24dcac..1b369b3294 100644 --- a/pkg/util/iptables/iptables.go +++ b/pkg/util/iptables/iptables.go @@ -56,8 +56,6 @@ type Interface interface { IsIpv6() bool // Save calls `iptables-save` for table. Save(table Table) ([]byte, error) - // SaveAll calls `iptables-save`. - SaveAll() ([]byte, error) // Restore runs `iptables-restore` passing data through []byte. // table is the Table to restore // data should be formatted like the output of Save() @@ -317,16 +315,6 @@ func (runner *runner) Save(table Table) ([]byte, error) { return runner.exec.Command(cmdIPTablesSave, args...).CombinedOutput() } -// SaveAll is part of Interface. -func (runner *runner) SaveAll() ([]byte, error) { - runner.mu.Lock() - defer runner.mu.Unlock() - - // run and return - glog.V(4).Infof("running iptables-save") - return runner.exec.Command(cmdIPTablesSave, []string{}...).CombinedOutput() -} - // Restore is part of Interface. func (runner *runner) Restore(table Table, data []byte, flush FlushFlag, counters RestoreCountersFlag) error { // setup args diff --git a/pkg/util/iptables/iptables_test.go b/pkg/util/iptables/iptables_test.go index 5fb921d522..62b8416709 100644 --- a/pkg/util/iptables/iptables_test.go +++ b/pkg/util/iptables/iptables_test.go @@ -884,59 +884,6 @@ COMMIT } } -func TestSaveAll(t *testing.T) { - output := `# Generated by iptables-save v1.6.0 on Thu Jan 19 11:38:09 2017 -*filter -:INPUT ACCEPT [15079:38410730] -:FORWARD ACCEPT [0:0] -:OUTPUT ACCEPT [11045:521562] -COMMIT -# Completed on Thu Jan 19 11:38:09 2017` - - fcmd := exec.FakeCmd{ - CombinedOutputScript: []exec.FakeCombinedOutputAction{ - // iptables version check - func() ([]byte, error) { return []byte("iptables v1.9.22"), nil }, - // iptables-restore version check - func() ([]byte, error) { return []byte("iptables-restore v1.9.22"), nil }, - func() ([]byte, error) { return []byte(output), nil }, - func() ([]byte, error) { return nil, &exec.FakeExitError{Status: 1} }, - }, - } - fexec := exec.FakeExec{ - CommandScript: []exec.FakeCommandAction{ - func(cmd string, args ...string) exec.Cmd { return exec.InitFakeCmd(&fcmd, cmd, args...) }, - func(cmd string, args ...string) exec.Cmd { return exec.InitFakeCmd(&fcmd, cmd, args...) }, - func(cmd string, args ...string) exec.Cmd { return exec.InitFakeCmd(&fcmd, cmd, args...) }, - func(cmd string, args ...string) exec.Cmd { return exec.InitFakeCmd(&fcmd, cmd, args...) }, - }, - } - runner := New(&fexec, dbus.NewFake(nil, nil), ProtocolIpv4) - defer runner.Destroy() - // Success. - o, err := runner.SaveAll() - if err != nil { - t.Fatalf("expected success, got %v", err) - } - - if string(o[:len(output)]) != output { - t.Errorf("expected output to be equal to mocked one, got %v", o) - } - - if fcmd.CombinedOutputCalls != 3 { - t.Errorf("expected 3 CombinedOutput() calls, got %d", fcmd.CombinedOutputCalls) - } - if !sets.NewString(fcmd.CombinedOutputLog[2]...).HasAll("iptables-save") { - t.Errorf("wrong CombinedOutput() log, got %s", fcmd.CombinedOutputLog[2]) - } - - // Failure. - _, err = runner.SaveAll() - if err == nil { - t.Errorf("expected failure") - } -} - func TestRestore(t *testing.T) { fcmd := exec.FakeCmd{ CombinedOutputScript: []exec.FakeCombinedOutputAction{ diff --git a/pkg/util/iptables/testing/fake.go b/pkg/util/iptables/testing/fake.go index 16cd90ba30..3ab40cf6dc 100644 --- a/pkg/util/iptables/testing/fake.go +++ b/pkg/util/iptables/testing/fake.go @@ -78,10 +78,6 @@ func (f *FakeIPTables) Save(table iptables.Table) ([]byte, error) { return lines, nil } -func (*FakeIPTables) SaveAll() ([]byte, error) { - return make([]byte, 0), nil -} - func (*FakeIPTables) Restore(table iptables.Table, data []byte, flush iptables.FlushFlag, counters iptables.RestoreCountersFlag) error { return nil }