Skip to content

Commit

Permalink
test/e2e: use custom network config dir where needed
Browse files Browse the repository at this point in the history
Since commit f250560 the play kube command uses its own network.
this is racy be design because we create the network followed by
creating/running pod/containers. This means in the meantime another
prune or reset process could wipe out the network config because we have
to share the network config directory by design in the test.

The problem is we only have one host netns which is shared between
tests. If the network config dir is not shared we cannot make conflict
checks for interface names and ip address. This results in different
tests trying to use the same interface and/or ip address which will
cause runtime failures in CNI and netavark.

The only solution I see is to make sure only the reset/prune tests are
using a custom network dir. This makes sure they do not wipe configs
that are otherwise required by other parallel running tests.

Fixes #17946

Signed-off-by: Paul Holzinger <[email protected]>
  • Loading branch information
Luap99 committed Apr 6, 2023
1 parent b39cdff commit dc9a65e
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 20 deletions.
1 change: 1 addition & 0 deletions test/e2e/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,7 @@ RUN ls /dev/test1`, ALPINE)

It("podman system reset must clean host shared cache", func() {
SkipIfRemote("podman-remote does not have system reset -f")
useCustomNetworkDir(podmanTest, tempdir)
podmanTest.AddImageToRWStore(ALPINE)
session := podmanTest.Podman([]string{"build", "--pull-never", "--file", "build/cache/Dockerfilecachewrite", "build/cache/"})
session.WaitWithDefaultTimeout()
Expand Down
12 changes: 12 additions & 0 deletions test/e2e/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1198,3 +1198,15 @@ func WaitForService(address url.URL) {
}
Expect(err).ShouldNot(HaveOccurred())
}

// useCustomNetworkDir makes sure this test uses a custom network dir.
// This needs to be called for all test they may remove networks from other tests,
// so netwokr prune, system prune, or system reset.
// see https://github.com/containers/podman/issues/17946
func useCustomNetworkDir(podmanTest *PodmanTestIntegration, tempdir string) {
// set custom network directory to prevent flakes since the dir is shared with all tests by default
podmanTest.NetworkConfigDir = tempdir
if IsRemote() {
podmanTest.RestartRemoteService()
}
}
12 changes: 2 additions & 10 deletions test/e2e/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -726,11 +726,7 @@ var _ = Describe("Podman network", func() {
})

It("podman network prune --filter", func() {
// set custom network directory to prevent flakes since the dir is shared with all tests by default
podmanTest.NetworkConfigDir = tempdir
if IsRemote() {
podmanTest.RestartRemoteService()
}
useCustomNetworkDir(podmanTest, tempdir)
net1 := "macvlan" + stringid.GenerateRandomID() + "net1"

nc := podmanTest.Podman([]string{"network", "create", net1})
Expand Down Expand Up @@ -774,11 +770,7 @@ var _ = Describe("Podman network", func() {
})

It("podman network prune", func() {
// set custom network directory to prevent flakes since the dir is shared with all tests by default
podmanTest.NetworkConfigDir = tempdir
if IsRemote() {
podmanTest.RestartRemoteService()
}
useCustomNetworkDir(podmanTest, tempdir)
// Create two networks
// Check they are there
// Run a container on one of them
Expand Down
14 changes: 8 additions & 6 deletions test/e2e/prune_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ var _ = Describe("Podman prune", func() {
})

It("podman system image prune unused images", func() {
useCustomNetworkDir(podmanTest, tempdir)
podmanTest.AddImageToRWStore(ALPINE)
podmanTest.BuildImage(pruneImage, "alpine_bash:latest", "true")
prune := podmanTest.Podman([]string{"system", "prune", "-a", "--force"})
Expand Down Expand Up @@ -260,12 +261,7 @@ var _ = Describe("Podman prune", func() {
})

It("podman system prune networks", func() {
// set custom network directory to prevent flakes since the dir is shared with all tests by default
podmanTest.NetworkConfigDir = tempdir
if IsRemote() {
podmanTest.RestartRemoteService()
}

useCustomNetworkDir(podmanTest, tempdir)
// Create new network.
session := podmanTest.Podman([]string{"network", "create", "test"})
session.WaitWithDefaultTimeout()
Expand Down Expand Up @@ -308,6 +304,7 @@ var _ = Describe("Podman prune", func() {
})

It("podman system prune - pod,container stopped", func() {
useCustomNetworkDir(podmanTest, tempdir)
session := podmanTest.Podman([]string{"pod", "create"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
Expand Down Expand Up @@ -340,6 +337,7 @@ var _ = Describe("Podman prune", func() {
})

It("podman system prune with running, exited pod and volume prune set true", func() {
useCustomNetworkDir(podmanTest, tempdir)
// Start and stop a pod to get it in exited state.
session := podmanTest.Podman([]string{"pod", "create"})
session.WaitWithDefaultTimeout()
Expand Down Expand Up @@ -417,6 +415,7 @@ var _ = Describe("Podman prune", func() {
})

It("podman system prune - with dangling images true", func() {
useCustomNetworkDir(podmanTest, tempdir)
session := podmanTest.Podman([]string{"pod", "create"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
Expand Down Expand Up @@ -465,6 +464,7 @@ var _ = Describe("Podman prune", func() {
})

It("podman system prune --volumes --filter", func() {
useCustomNetworkDir(podmanTest, tempdir)
session := podmanTest.Podman([]string{"volume", "create", "--label", "label1=value1", "myvol1"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
Expand Down Expand Up @@ -531,6 +531,7 @@ var _ = Describe("Podman prune", func() {
})

It("podman system prune --external leaves referenced containers", func() {
useCustomNetworkDir(podmanTest, tempdir)
containerStorageDir := filepath.Join(podmanTest.Root, podmanTest.ImageCacheFS+"-containers")

create := podmanTest.Podman([]string{"create", "--name", "test", BB})
Expand Down Expand Up @@ -561,6 +562,7 @@ var _ = Describe("Podman prune", func() {

It("podman system prune --external removes unreferenced containers", func() {
SkipIfRemote("Can't drop database while daemon running")
useCustomNetworkDir(podmanTest, tempdir)

containerStorageDir := filepath.Join(podmanTest.Root, podmanTest.ImageCacheFS+"-containers")

Expand Down
5 changes: 1 addition & 4 deletions test/e2e/system_reset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@ var _ = Describe("podman system reset", func() {
It("podman system reset", func() {
SkipIfRemote("system reset not supported on podman --remote")
// system reset will not remove additional store images, so need to grab length

// change the network dir so that we do not conflict with other tests
// that would use the same network dir and cause unnecessary flakes
podmanTest.NetworkConfigDir = tempdir
useCustomNetworkDir(podmanTest, tempdir)

session := podmanTest.Podman([]string{"rmi", "--force", "--all"})
session.WaitWithDefaultTimeout()
Expand Down

0 comments on commit dc9a65e

Please sign in to comment.