summaryrefslogtreecommitdiff
path: root/test/e2e/prune_test.go
diff options
context:
space:
mode:
authorSujil02 <sushah@redhat.com>2020-04-29 22:41:56 -0400
committerSujil02 <sushah@redhat.com>2020-05-01 13:57:16 -0400
commitb94862171b29dbef4cd780e4b1746d97f62f7a94 (patch)
tree6d64486633a4ebc208f31431c81f1932ade979f4 /test/e2e/prune_test.go
parent2f3762eb911258016581187f072a24ac2724be3b (diff)
downloadpodman-b94862171b29dbef4cd780e4b1746d97f62f7a94.tar.gz
podman-b94862171b29dbef4cd780e4b1746d97f62f7a94.tar.bz2
podman-b94862171b29dbef4cd780e4b1746d97f62f7a94.zip
And system prune feature for v2.
Adds podman system prune for v2. Refactoring for code reuse from pods containers images and volume prune. Adds and enables testcases to support the added feature. Signed-off-by: Sujil02 <sushah@redhat.com>
Diffstat (limited to 'test/e2e/prune_test.go')
-rw-r--r--test/e2e/prune_test.go158
1 files changed, 156 insertions, 2 deletions
diff --git a/test/e2e/prune_test.go b/test/e2e/prune_test.go
index 466a4f739..a09b6f37a 100644
--- a/test/e2e/prune_test.go
+++ b/test/e2e/prune_test.go
@@ -148,7 +148,6 @@ var _ = Describe("Podman prune", func() {
It("podman system image prune unused images", func() {
SkipIfRemote()
- Skip(v2fail)
podmanTest.RestoreAllArtifacts()
podmanTest.BuildImage(pruneImage, "alpine_bash:latest", "true")
prune := podmanTest.PodmanNoCache([]string{"system", "prune", "-a", "--force"})
@@ -162,7 +161,6 @@ var _ = Describe("Podman prune", func() {
})
It("podman system prune pods", func() {
- Skip(v2fail)
session := podmanTest.Podman([]string{"pod", "create"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
@@ -193,4 +191,160 @@ var _ = Describe("Podman prune", func() {
Expect(pods.ExitCode()).To(Equal(0))
Expect(len(pods.OutputToStringArray())).To(Equal(2))
})
+
+ It("podman system prune - pod,container stopped", func() {
+ session := podmanTest.Podman([]string{"pod", "create"})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+
+ // Start and stop a pod to get it in exited state.
+ session = podmanTest.Podman([]string{"pod", "start", "-l"})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+
+ session = podmanTest.Podman([]string{"pod", "stop", "-l"})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+
+ // Create a container. This container should be pruned.
+ create := podmanTest.Podman([]string{"create", "--name", "test", BB})
+ create.WaitWithDefaultTimeout()
+ Expect(create.ExitCode()).To(Equal(0))
+
+ prune := podmanTest.Podman([]string{"system", "prune", "-f"})
+ prune.WaitWithDefaultTimeout()
+ Expect(prune.ExitCode()).To(Equal(0))
+
+ pods := podmanTest.Podman([]string{"pod", "ps"})
+ pods.WaitWithDefaultTimeout()
+ Expect(pods.ExitCode()).To(Equal(0))
+ Expect(podmanTest.NumberOfPods()).To(Equal(0))
+
+ Expect(podmanTest.NumberOfContainers()).To(Equal(0))
+ })
+
+ It("podman system prune with running, exited pod and volume prune set true", func() {
+
+ // Start and stop a pod to get it in exited state.
+ session := podmanTest.Podman([]string{"pod", "create"})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+
+ session = podmanTest.Podman([]string{"pod", "start", "-l"})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+
+ session = podmanTest.Podman([]string{"pod", "stop", "-l"})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+
+ // Start a pod and leave it running
+ session = podmanTest.Podman([]string{"pod", "create"})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+ session = podmanTest.Podman([]string{"pod", "start", "-l"})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+
+ // Number of pod should be 2. One exited one running.
+ Expect(podmanTest.NumberOfPods()).To(Equal(2))
+
+ // Create a container. This container should be pruned.
+ _, ec, _ := podmanTest.RunLsContainer("test1")
+ Expect(ec).To(Equal(0))
+
+ // Number of containers should be three now.
+ // Two as pods infra container and one newly created.
+ Expect(podmanTest.NumberOfContainers()).To(Equal(3))
+
+ // image list current count should not be pruned if all flag isnt enabled
+ session = podmanTest.Podman([]string{"images"})
+ session.WaitWithDefaultTimeout()
+ numberOfImages := len(session.OutputToStringArray())
+
+ // Adding unused volume should be pruned
+ session = podmanTest.Podman([]string{"volume", "create"})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+
+ session = podmanTest.Podman([]string{"create", "-v", "myvol:/myvol", ALPINE, "ls"})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+
+ session = podmanTest.Podman([]string{"volume", "ls"})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+ Expect(len(session.OutputToStringArray())).To(Equal(3))
+
+ session = podmanTest.Podman([]string{"system", "prune", "--force", "--volumes"})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+
+ // Volumes should be pruned.
+ session = podmanTest.Podman([]string{"volume", "ls"})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+ Expect(len(session.OutputToStringArray())).To(Equal(0))
+
+ // One Pod should not be pruned as it was running
+ Expect(podmanTest.NumberOfPods()).To(Equal(1))
+
+ // Running pods infra container should not be pruned.
+ Expect(podmanTest.NumberOfContainers()).To(Equal(1))
+
+ // Image should not be pruned and number should be same.
+ images := podmanTest.Podman([]string{"images"})
+ images.WaitWithDefaultTimeout()
+ Expect(len(images.OutputToStringArray())).To(Equal(numberOfImages))
+ })
+
+ It("podman system prune - with dangling images true", func() {
+ session := podmanTest.Podman([]string{"pod", "create"})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+
+ // Start and stop a pod to get it in exited state.
+ session = podmanTest.Podman([]string{"pod", "start", "-l"})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+
+ session = podmanTest.Podman([]string{"pod", "stop", "-l"})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+
+ // Create a container. This container should be pruned.
+ create := podmanTest.Podman([]string{"create", "--name", "test", BB})
+ create.WaitWithDefaultTimeout()
+ Expect(create.ExitCode()).To(Equal(0))
+
+ // Adding images should be pruned
+ podmanTest.BuildImage(pruneImage, "alpine_bash:latest", "true")
+
+ // Adding unused volume should not be pruned as volumes not set
+ session = podmanTest.Podman([]string{"volume", "create"})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+
+ prune := podmanTest.Podman([]string{"system", "prune", "-f", "-a"})
+ prune.WaitWithDefaultTimeout()
+ Expect(prune.ExitCode()).To(Equal(0))
+
+ pods := podmanTest.Podman([]string{"pod", "ps"})
+ pods.WaitWithDefaultTimeout()
+ Expect(pods.ExitCode()).To(Equal(0))
+ Expect(podmanTest.NumberOfPods()).To(Equal(0))
+
+ Expect(podmanTest.NumberOfContainers()).To(Equal(0))
+
+ // Volumes should not be pruned
+ session = podmanTest.Podman([]string{"volume", "ls"})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+ Expect(len(session.OutputToStringArray())).To(Equal(2))
+
+ images := podmanTest.PodmanNoCache([]string{"images", "-aq"})
+ images.WaitWithDefaultTimeout()
+ // all images are unused, so they all should be deleted!
+ Expect(len(images.OutputToStringArray())).To(Equal(0))
+ })
})