summaryrefslogtreecommitdiff
path: root/pkg/bindings/test/system_test.go
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2020-12-22 11:02:19 -0500
committerGitHub <noreply@github.com>2020-12-22 11:02:19 -0500
commit07663f74c48d11732a3330248f837d5abf86fe9c (patch)
tree2446603ff11ddb7517fefee7c11fb5cf287fbbb7 /pkg/bindings/test/system_test.go
parentcfdb8fb29b34010206ea26f38e130d3e24403abf (diff)
parent5923656f321a9ca7b222c81cdb5f3387cc7cd3ad (diff)
downloadpodman-07663f74c48d11732a3330248f837d5abf86fe9c.tar.gz
podman-07663f74c48d11732a3330248f837d5abf86fe9c.tar.bz2
podman-07663f74c48d11732a3330248f837d5abf86fe9c.zip
Merge pull request #8724 from bblenard/support-volume-filters-in-system-prune
Add volume filters to system prune
Diffstat (limited to 'pkg/bindings/test/system_test.go')
-rw-r--r--pkg/bindings/test/system_test.go57
1 files changed, 57 insertions, 0 deletions
diff --git a/pkg/bindings/test/system_test.go b/pkg/bindings/test/system_test.go
index 5cb0f9125..25fda5575 100644
--- a/pkg/bindings/test/system_test.go
+++ b/pkg/bindings/test/system_test.go
@@ -158,4 +158,61 @@ var _ = Describe("Podman system", func() {
// Volume should be pruned now as flag set true
Expect(len(systemPruneResponse.VolumePruneReport)).To(Equal(1))
})
+
+ It("podman system prune running alpine container volume prune --filter", func() {
+ // Start a pod and leave it running
+ _, err := pods.Start(bt.conn, newpod, nil)
+ Expect(err).To(BeNil())
+
+ // Start and stop a container to enter in exited state.
+ var name = "top"
+ _, err = bt.RunTopContainer(&name, bindings.PFalse, nil)
+ Expect(err).To(BeNil())
+ err = containers.Stop(bt.conn, name, nil)
+ Expect(err).To(BeNil())
+
+ // Start second container and leave in running
+ var name2 = "top2"
+ _, err = bt.RunTopContainer(&name2, bindings.PFalse, nil)
+ Expect(err).To(BeNil())
+
+ // Adding an unused volume should work
+ _, err = volumes.Create(bt.conn, entities.VolumeCreateOptions{}, nil)
+ Expect(err).To(BeNil())
+
+ // Adding an unused volume with label should work
+ _, err = volumes.Create(bt.conn, entities.VolumeCreateOptions{Label: map[string]string{
+ "label1": "value1",
+ }}, nil)
+ Expect(err).To(BeNil())
+
+ f := make(map[string][]string)
+ f["label"] = []string{"label1=idontmatch"}
+
+ options := new(system.PruneOptions).WithAll(true).WithVolumes(true).WithFilters(f)
+ systemPruneResponse, err := system.Prune(bt.conn, options)
+ Expect(err).To(BeNil())
+ Expect(len(systemPruneResponse.PodPruneReport)).To(Equal(0))
+ // TODO fix system filter handling so all components can handle filters
+ // This check **should** be "Equal(0)" since we are passing label
+ // filters however the Prune function doesn't seem to pass filters
+ // to each component.
+ Expect(len(systemPruneResponse.ContainerPruneReport.ID)).To(Equal(1))
+ Expect(len(systemPruneResponse.ImagePruneReport.Report.Id)).
+ To(BeNumerically(">", 0))
+ // Alpine image should not be pruned as used by running container
+ Expect(systemPruneResponse.ImagePruneReport.Report.Id).
+ ToNot(ContainElement("docker.io/library/alpine:latest"))
+ // Volume shouldn't be pruned because the PruneOptions filters doesn't match
+ Expect(len(systemPruneResponse.VolumePruneReport)).To(Equal(0))
+
+ // Fix filter and re prune
+ f["label"] = []string{"label1=value1"}
+ options = new(system.PruneOptions).WithAll(true).WithVolumes(true).WithFilters(f)
+ systemPruneResponse, err = system.Prune(bt.conn, options)
+ Expect(err).To(BeNil())
+
+ // Volume should be pruned because the PruneOptions filters now match
+ Expect(len(systemPruneResponse.VolumePruneReport)).To(Equal(1))
+ })
})