Skip to content

Commit

Permalink
test/e2e: add netns leak check
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
Luap99 committed Sep 18, 2024
1 parent 2d469e5 commit 755a06a
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions test/e2e/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"errors"
"fmt"
"io"
"io/fs"
"math/rand"
"net"
"net/url"
Expand Down Expand Up @@ -138,10 +139,32 @@ const (
imageCacheDir = "imagecachedir"
)

var netnsFiles []fs.DirEntry

func getNetnsDir() string {
if isRootless() {
var path string
if env, ok := os.LookupEnv("XDG_RUNTIME_DIR"); ok {
path = env
} else {
path = fmt.Sprintf("/run/user/%d", os.Getuid())
}
return filepath.Join(path, "netns")
}
// root is hard coded to
return "/run/netns"
}

var _ = SynchronizedBeforeSuite(func() []byte {
globalTmpDir, err := os.MkdirTemp("", "podman-e2e-")
Expect(err).ToNot(HaveOccurred())

netnsFiles, err = os.ReadDir(getNetnsDir())
// dir might not exists which is fine
if !errors.Is(err, fs.ErrNotExist) {
Expect(err).ToNot(HaveOccurred())
}

// make cache dir
ImageCacheDir = filepath.Join(globalTmpDir, imageCacheDir)
err = os.MkdirAll(ImageCacheDir, 0700)
Expand Down Expand Up @@ -203,6 +226,13 @@ var _ = SynchronizedAfterSuite(func() {
timingsFile = nil
},
func() {
// perform a netns leak check after all tests run
newNetnsFiles, err := os.ReadDir(getNetnsDir())
if !errors.Is(err, fs.ErrNotExist) {
Expect(err).ToNot(HaveOccurred())
}
Expect(newNetnsFiles).To(ConsistOf(netnsFiles), "Netns files were leaked")

testTimings := make(testResultsSorted, 0, 2000)
for i := 1; i <= GinkgoT().ParallelTotal(); i++ {
f, err := os.Open(fmt.Sprintf("%s/timings-%d", LockTmpDir, i))
Expand Down

0 comments on commit 755a06a

Please sign in to comment.