Repository navigation
[core][sandbox] Pull from a local fake registry in test_image_utils - #66786
Conversation
test_pull_and_extract_remote_image and test_pull_and_extract_docker_io_prefixed_image pulled busybox from the real Docker Hub, so a Docker Hub rate limit or network error failed them, and with them the test_image_utils target. They were the only tests in the file that reached outside the test process. test_pull_nonexistent_image went to Docker Hub too, but passed either way. A fake_docker_hub fixture now serves library/busybox from 127.0.0.1, and RAY_SANDBOX_REGISTRY_MIRROR sends Docker Hub references to it. It answers each step of a pull: the bearer-token challenge, a multi-arch index that lists another platform first, the manifest and config, and blobs behind a redirect that rejects the registry token, as presigned object storage does. The tests still cover busybox:latest and docker.io/library/busybox:latest references, the token flow, platform selection, and dropping the token at the blob redirect, without the network. The nonexistent image now fails on the fake's 404. The gVisor backend tests still pull real images from Docker Hub. Signed-off-by: xyuzh <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request introduces a local registry fixture, fake_docker_hub, using http.server.ThreadingHTTPServer to mock Docker Hub registry pulls in test_image_utils.py, allowing tests to run without network dependencies. The reviewer identified a critical issue where accessing server_port on the ThreadingHTTPServer instance will raise an AttributeError, and suggested using server_address[1] instead to correctly retrieve the dynamically bound port.
| else: | ||
| self._reply(200, blob) | ||
| elif auth != f"Bearer {token}": | ||
| realm = f"http://127.0.0.1:{self.server.server_port}/token" |
There was a problem hiding this comment.
The ThreadingHTTPServer class does not have a server_port attribute. Accessing self.server.server_port will raise an AttributeError. Use self.server.server_address[1] instead to retrieve the dynamically bound port.
| realm = f"http://127.0.0.1:{self.server.server_port}/token" | |
| realm = f"http://127.0.0.1:{self.server.server_address[1]}/token" |
There was a problem hiding this comment.
Not changing this: ThreadingHTTPServer inherits HTTPServer.server_bind, which sets server_port right after binding (CPython Lib/http/server.py), so self.server.server_port is the port the fake registry got. The three tests that use the fixture pass in CI with it.
| server = http.server.ThreadingHTTPServer(("127.0.0.1", 0), Registry) | ||
| threading.Thread(target=server.serve_forever, daemon=True).start() | ||
| monkeypatch.setenv( | ||
| "RAY_SANDBOX_REGISTRY_MIRROR", f"http://127.0.0.1:{server.server_port}" |
There was a problem hiding this comment.
The ThreadingHTTPServer class does not have a server_port attribute. Accessing server.server_port will raise an AttributeError. Use server.server_address[1] instead to retrieve the dynamically bound port.
| "RAY_SANDBOX_REGISTRY_MIRROR", f"http://127.0.0.1:{server.server_port}" | |
| "RAY_SANDBOX_REGISTRY_MIRROR", f"http://127.0.0.1:{server.server_address[1]}" |
There was a problem hiding this comment.
Same as above: HTTPServer.server_bind sets server_port, so this is the bound port.
pcmoritz
left a comment
There was a problem hiding this comment.
The busybox image we serve through this is very fake right now :)
|
@pcmoritz good to merge? |
…ay-project#66786) ## Description `test_image_utils` is flaky in CI because three of its tests pull from the real Docker Hub. The two `busybox` pull tests fail whenever Docker Hub rate-limits the runner (100 anonymous pulls per 6 hours per IP) or the network blips. `test_pull_nonexistent_image` also goes to Docker Hub, but passes either way. This PR adds a `fake_docker_hub` fixture: a small registry on `127.0.0.1` that `RAY_SANDBOX_REGISTRY_MIRROR` points Docker Hub references at. It serves `library/busybox` through each step of a real pull: the bearer-token challenge, a multi-arch index that lists another platform first, the manifest and config, and blobs behind a redirect that rejects the registry token, as presigned object storage does. The tests still cover `busybox:latest` and `docker.io/library/busybox:latest`, and the nonexistent image now fails on the fake's 404. Only the test file changes. The gVisor backend tests still pull real images. ## Related issues Related to ray-project#65352. Follows ray-project#66675, which fixed the other `test_image_utils` failure in CI. ## Additional information - Not a duplicate: searches of open PRs and issues for `test_image_utils`, `sandbox flaky` and `sandbox docker hub` found nothing. - Tested on macOS with the Ray 2.58 wheel and this branch's sandbox package: `TEST_SANDBOX=1 pytest python/ray/experimental/sandbox/tests/test_image_utils.py` passed (26 tests) on Python 3.10 with pytest 7.4.4, CI's versions, and on Python 3.11 with pytest 8.0.2. With every non-loopback socket blocked, it passed 25 runs out of 25; master's file fails its two `busybox` tests that way. Making `image_utils.py` forward the token on the redirect, take the first index entry, or drop the token makes the pull tests fail. CI's sandbox job covers Linux. - I used Claude Code to help write and test this change. Signed-off-by: xyuzh <[email protected]> Signed-off-by: Pawel Beza <[email protected]> Co-authored-by: Copilot <[email protected]> Copilot-Session: 4b9df5c4-6ec3-4e1f-ac3e-54f320ebd8c4
Description
test_image_utilsis flaky in CI because three of its tests pull from the real Docker Hub. The twobusyboxpull tests fail whenever Docker Hub rate-limits the runner (100 anonymous pulls per 6 hours per IP) or the network blips.test_pull_nonexistent_imagealso goes to Docker Hub, but passes either way.This PR adds a
fake_docker_hubfixture: a small registry on127.0.0.1thatRAY_SANDBOX_REGISTRY_MIRRORpoints Docker Hub references at. It serveslibrary/busyboxthrough each step of a real pull: the bearer-token challenge, a multi-arch index that lists another platform first, the manifest and config, and blobs behind a redirect that rejects the registry token, as presigned object storage does. The tests still coverbusybox:latestanddocker.io/library/busybox:latest, and the nonexistent image now fails on the fake's 404.Only the test file changes. The gVisor backend tests still pull real images.
Related issues
Related to #65352. Follows #66675, which fixed the other
test_image_utilsfailure in CI.Additional information
test_image_utils,sandbox flakyandsandbox docker hubfound nothing.TEST_SANDBOX=1 pytest python/ray/experimental/sandbox/tests/test_image_utils.pypassed (26 tests) on Python 3.10 with pytest 7.4.4, CI's versions, and on Python 3.11 with pytest 8.0.2. With every non-loopback socket blocked, it passed 25 runs out of 25; master's file fails its twobusyboxtests that way. Makingimage_utils.pyforward the token on the redirect, take the first index entry, or drop the token makes the pull tests fail. CI's sandbox job covers Linux.