Skip to content

Commit

Permalink
Merge pull request #12431 from matejvasek/fix-ctr-archive-ep
Browse files Browse the repository at this point in the history
fix: error reporting for archive endpoint
  • Loading branch information
openshift-merge-robot authored Nov 29, 2021
2 parents 7324d94 + cbda62d commit 3d19f1a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 3 additions & 1 deletion pkg/api/handlers/compat/containers_archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,10 @@ func handlePut(w http.ResponseWriter, r *http.Request, decoder *schema.Decoder,
return
}

w.WriteHeader(http.StatusOK)
if err := copyFunc(); err != nil {
logrus.Error(err.Error())
utils.Error(w, "Something went wrong.", http.StatusInternalServerError, err)
return
}
w.WriteHeader(http.StatusOK)
}
14 changes: 13 additions & 1 deletion test/python/docker/compat/test_containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from docker import DockerClient, errors
from docker.models.containers import Container
from docker.models.images import Image
from docker.models.volumes import Volume

from test.python.docker import Podman
from test.python.docker.compat import common, constant
Expand Down Expand Up @@ -207,9 +208,14 @@ def test_filters(self):

def test_copy_to_container(self):
ctr: Optional[Container] = None
vol: Optional[Volume] = None
try:
test_file_content = b"Hello World!"
ctr = self.client.containers.create(image="alpine", detach=True, command="top")
vol = self.client.volumes.create("test-volume")
ctr = self.client.containers.create(image="alpine",
detach=True,
command="top",
volumes=["test-volume:/test-volume-read-only:ro"])
ctr.start()

buff: IO[bytes] = io.BytesIO()
Expand All @@ -234,10 +240,16 @@ def test_copy_to_container(self):
ret, out = ctr.exec_run(["cat", "/tmp/a.txt"])
self.assertEqual(ret, 0)
self.assertEqual(out.rstrip(), test_file_content, "Content of copied file")

buff.seek(0)
with self.assertRaises(errors.APIError):
ctr.put_archive("/test-volume-read-only/", buff)
finally:
if ctr is not None:
ctr.stop()
ctr.remove()
if vol is not None:
vol.remove(force=True)

def test_mount_preexisting_dir(self):
dockerfile = (B'FROM quay.io/libpod/alpine:latest\n'
Expand Down

0 comments on commit 3d19f1a

Please sign in to comment.