From 7223f12f399b943c03d9ec4e85502756bf847129 Mon Sep 17 00:00:00 2001 From: Antonio Ojea Date: Wed, 10 Feb 2021 09:27:28 +0100 Subject: [PATCH] =?UTF-8?q?don=C2=B4t=20leak=20files=20on=20iptables=20tes?= =?UTF-8?q?ts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit the iptables restore function, if it considers that the --wait flag is not supported, creates a lock file to mimic the iptables behaviour. The test should take this into account and remove the file. --- pkg/util/iptables/iptables_test.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pkg/util/iptables/iptables_test.go b/pkg/util/iptables/iptables_test.go index c2ff33773ec..efd85e0176a 100644 --- a/pkg/util/iptables/iptables_test.go +++ b/pkg/util/iptables/iptables_test.go @@ -1025,6 +1025,9 @@ func TestRestoreAllWaitOldIptablesRestore(t *testing.T) { }, } lockPath14x, lockPath16x := getLockPaths() + // the lockPath14x is a UNIX socket which is cleaned up automatically on close, but the + // lockPath16x is a plain file which is not cleaned up. + defer os.Remove(lockPath16x) runner := newInternal(&fexec, ProtocolIPv4, lockPath14x, lockPath16x) err := runner.RestoreAll([]byte{}, NoFlushTables, RestoreCounters) @@ -1077,7 +1080,10 @@ func TestRestoreAllGrabNewLock(t *testing.T) { if err != nil { t.Fatalf("expected to open %s, got %v", lockPath16x, err) } - defer runLock.Close() + defer func() { + runLock.Close() + os.Remove(lockPath16x) + }() if err := grabIptablesFileLock(runLock); err != nil { t.Errorf("expected to lock %s, got %v", lockPath16x, err) @@ -1111,6 +1117,9 @@ func TestRestoreAllGrabOldLock(t *testing.T) { }, } lockPath14x, lockPath16x := getLockPaths() + // the lockPath14x is a UNIX socket which is cleaned up automatically on close, but the + // lockPath16x is a plain file which is not cleaned up. + defer os.Remove(lockPath16x) runner := newInternal(&fexec, ProtocolIPv4, lockPath14x, lockPath16x) var runLock *net.UnixListener