Skip to content

Commit 755a06a

Browse files
committed
test/e2e: add netns leak check
Like we do in system tests now check for netns leaks in e2e as well. Now because things run in parallel and this dir is shared we cannot test after each test only once per suite. This will be a PITA to debug if leaks happen as the netns files do not contain the container ID and are just random bytes (maybe we should change this?) Fixes #23715 Signed-off-by: Paul Holzinger <[email protected]>
1 parent 2d469e5 commit 755a06a

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

test/e2e/common_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"errors"
99
"fmt"
1010
"io"
11+
"io/fs"
1112
"math/rand"
1213
"net"
1314
"net/url"
@@ -138,10 +139,32 @@ const (
138139
imageCacheDir = "imagecachedir"
139140
)
140141

142+
var netnsFiles []fs.DirEntry
143+
144+
func getNetnsDir() string {
145+
if isRootless() {
146+
var path string
147+
if env, ok := os.LookupEnv("XDG_RUNTIME_DIR"); ok {
148+
path = env
149+
} else {
150+
path = fmt.Sprintf("/run/user/%d", os.Getuid())
151+
}
152+
return filepath.Join(path, "netns")
153+
}
154+
// root is hard coded to
155+
return "/run/netns"
156+
}
157+
141158
var _ = SynchronizedBeforeSuite(func() []byte {
142159
globalTmpDir, err := os.MkdirTemp("", "podman-e2e-")
143160
Expect(err).ToNot(HaveOccurred())
144161

162+
netnsFiles, err = os.ReadDir(getNetnsDir())
163+
// dir might not exists which is fine
164+
if !errors.Is(err, fs.ErrNotExist) {
165+
Expect(err).ToNot(HaveOccurred())
166+
}
167+
145168
// make cache dir
146169
ImageCacheDir = filepath.Join(globalTmpDir, imageCacheDir)
147170
err = os.MkdirAll(ImageCacheDir, 0700)
@@ -203,6 +226,13 @@ var _ = SynchronizedAfterSuite(func() {
203226
timingsFile = nil
204227
},
205228
func() {
229+
// perform a netns leak check after all tests run
230+
newNetnsFiles, err := os.ReadDir(getNetnsDir())
231+
if !errors.Is(err, fs.ErrNotExist) {
232+
Expect(err).ToNot(HaveOccurred())
233+
}
234+
Expect(newNetnsFiles).To(ConsistOf(netnsFiles), "Netns files were leaked")
235+
206236
testTimings := make(testResultsSorted, 0, 2000)
207237
for i := 1; i <= GinkgoT().ParallelTotal(); i++ {
208238
f, err := os.Open(fmt.Sprintf("%s/timings-%d", LockTmpDir, i))

0 commit comments

Comments
 (0)