Skip to content

Commit

Permalink
Merge pull request #376 from umohnani8/vol
Browse files Browse the repository at this point in the history
Use volumes param for container rm
  • Loading branch information
openshift-merge-bot[bot] authored Feb 27, 2024
2 parents 4002fd1 + 3305b4f commit 6f5d07e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
6 changes: 2 additions & 4 deletions podman/domain/containers_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,8 @@ def remove(self, container_id: Union[Container, str], **kwargs):
if isinstance(container_id, Container):
container_id = container_id.id

params = {
"v": kwargs.get("v"),
"force": kwargs.get("force"),
}
# v is used for the compat endpoint while volumes is used for the libpod endpoint
params = {"v": kwargs.get("v"), "force": kwargs.get("force"), "volumes": kwargs.get("v")}

response = self.client.delete(f"/containers/{container_id}", params=params)
response.raise_for_status()
31 changes: 31 additions & 0 deletions podman/tests/integration/test_containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import random
import tarfile
import unittest
import tempfile

try:
# Python >= 3.10
Expand Down Expand Up @@ -158,6 +159,36 @@ def test_container_commit(self):
self.assertIn("localhost/busybox.local:unittest", image.attrs["RepoTags"])
busybox.remove(force=True)

def test_container_rm_anonymous_volume(self):
with self.subTest("Check anonymous volume is removed"):
container_file = """
FROM alpine
VOLUME myvol
ENV foo=bar
"""
tmp_file = tempfile.mktemp()
file = open(tmp_file, 'w')
file.write(container_file)
file.close()
self.client.images.build(dockerfile=tmp_file, tag="test-img", path=".")

# get existing number of containers and volumes
existing_containers = self.client.containers.list(all=True)
existing_volumes = self.client.volumes.list()

container = self.client.containers.create("test-img")
container_list = self.client.containers.list(all=True)
self.assertEqual(len(container_list), len(existing_containers) + 1)
volume_list = self.client.volumes.list()
self.assertEqual(len(volume_list), len(existing_volumes) + 1)

# remove the container with v=True
container.remove(v=True)
container_list = self.client.containers.list(all=True)
self.assertEqual(len(container_list), len(existing_containers))
volume_list = self.client.volumes.list()
self.assertEqual(len(volume_list), len(existing_volumes))


if __name__ == '__main__':
unittest.main()

0 comments on commit 6f5d07e

Please sign in to comment.