Merge pull request #25946 from ninja-quokka/docker_compat_force_image_remove

bug: Correct Docker compat REST API image delete endpoint
This commit is contained in:
openshift-merge-bot[bot]
2025-04-28 11:03:41 +00:00
committed by GitHub
8 changed files with 72 additions and 20 deletions

View File

@ -231,6 +231,47 @@ t DELETE images/test1:latest 200
t GET "images/get?names=alpine" 200 '[POSIX tar archive]'
# START: Testing variance between Docker API and Podman API
# regarding force deleting images.
# Podman: Force deleting an image will force remove any
# container using the image.
# Docker: Force deleting an image will only remove non
# running containers using the image.
# Create new image
podman image build -t docker.io/library/test1:latest - <<EOF
from alpine
RUN >file4
EOF
# Create running container
podman run --rm -d --name test_container docker.io/library/test1:latest top
# When using the Docker Compat API, force deleting an image
# shouldn't force delete any container using the image, only
# containers in a non running state should be removed.
# https://github.com/containers/podman/issues/25871
t DELETE images/test1:latest?force=true 409
# When using the Podman Libpod API, deleting an image
# with a running container will fail.
t DELETE libpod/images/test1:latest 409
# When using the Podman Libpod API, force deleting an
# image will also force delete all containers using the image.
# Verify container exists.
t GET libpod/containers/test_container/exists 204
# Delete image with force.
t DELETE libpod/images/test1:latest?force=true 200
# Verify container also removed.
t GET libpod/containers/test_container/exists 404
# END: Testing variance between Docker API and Podman API
# regarding force deleting images.
podman pull busybox
t GET "images/get?names=alpine&names=busybox" 200 '[POSIX tar archive]'
img_cnt=$(tar xf "$WORKDIR/curl.result.out" manifest.json -O | jq "length")

View File

@ -66,9 +66,8 @@ class ImageTestCase(APITestCase):
self.assertIn("sha256:",image['Id'])
def test_delete(self):
r = requests.delete(self.podman_url + "/v1.40/images/alpine?force=true")
self.assertEqual(r.status_code, 200, r.text)
self.assertIsInstance(r.json(), list)
r = requests.delete(self.compat_uri("images/alpine?force=true"))
self.assertEqual(r.status_code, 409, r.text)
def test_pull(self):
r = requests.post(self.uri("/images/pull?reference=alpine"), timeout=15)