-
Notifications
You must be signed in to change notification settings - Fork 51
Enable DELETE on the Docker v2 blob endpoint #2380
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
gerrod3
wants to merge
1
commit into
pulp:main
Choose a base branch
from
gerrod3:issue-481-blob-delete
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Enable DELETE on the Docker v2 blob endpoint so users can delete blobs by digest. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
pulp_container/tests/functional/api/test_delete_blob.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| """Tests for deleting blobs via the Docker v2 API.""" | ||
|
|
||
| import time | ||
|
|
||
| import pytest | ||
|
|
||
| from pulp_container.tests.functional.constants import PULP_FIXTURE_1 | ||
|
|
||
|
|
||
| def _wait_for_blob(container_bindings, repository_href, digest, present, timeout=60): | ||
| for _ in range(timeout): | ||
| repository = container_bindings.RepositoriesContainerApi.read(repository_href) | ||
| blobs = container_bindings.ContentBlobsApi.list( | ||
| digest=digest, repository_version=repository.latest_version_href | ||
| ) | ||
| if bool(blobs.results) == present: | ||
| if present: | ||
| return blobs.results[0] | ||
| return None | ||
| time.sleep(1) | ||
| if present: | ||
| pytest.fail(f"Blob '{digest}' was not available in the repository") | ||
| pytest.fail(f"Blob '{digest}' was not removed from the repository") | ||
|
|
||
|
|
||
| class TestDeleteBlob: | ||
| """Tests for DELETE /v2/<name>/blobs/<digest>. | ||
|
|
||
| Tests are numbered so failure cases run before the success cases that modify | ||
| the shared class-scoped repository. | ||
| """ | ||
|
|
||
| repo_name = "delete/blob" | ||
| dest_repo_name = "delete/blob-pending" | ||
| tag_name = "manifest_a" | ||
|
|
||
| @pytest.fixture(scope="class") | ||
| def setup( | ||
| self, | ||
| add_to_cleanup, | ||
| container_bindings, | ||
| container_repository_factory, | ||
| container_remote_factory, | ||
| container_sync, | ||
| container_distribution_factory, | ||
| ): | ||
| """Sync an image once for all delete blob tests.""" | ||
| repository = container_repository_factory() | ||
| remote = container_remote_factory(upstream_name=PULP_FIXTURE_1, includes=[self.tag_name]) | ||
| container_sync(repository, remote) | ||
| repository = container_bindings.RepositoriesContainerApi.read(repository.pulp_href) | ||
|
|
||
| distribution = container_distribution_factory( | ||
| name=self.repo_name, | ||
| base_path=self.repo_name, | ||
| repository=repository.pulp_href, | ||
| ) | ||
| namespace = container_bindings.PulpContainerNamespacesApi.read(distribution.namespace) | ||
| add_to_cleanup(container_bindings.PulpContainerNamespacesApi, namespace.pulp_href) | ||
|
|
||
| dest_repository = container_repository_factory() | ||
| container_distribution_factory( | ||
| name=self.dest_repo_name, | ||
| base_path=self.dest_repo_name, | ||
| repository=dest_repository.pulp_href, | ||
| ) | ||
|
|
||
| blob = container_bindings.ContentBlobsApi.list( | ||
| repository_version=repository.latest_version_href | ||
| ).results[0] | ||
|
|
||
| return repository, blob.digest | ||
|
|
||
| def test_01_delete_invalid_digest(self, setup, local_registry, full_path): | ||
| """Delete requires a sha256 digest.""" | ||
| delete_path = f"/v2/{full_path(self.repo_name)}/blobs/not-a-digest" | ||
| response, _ = local_registry.get_response("DELETE", delete_path) | ||
| assert response.status_code == 400 | ||
| assert response.json()["errors"][0]["code"] == "INVALID_REQUEST" | ||
|
|
||
| def test_02_delete_not_found(self, setup, local_registry, full_path): | ||
| """Deleting a non-existent blob returns 404.""" | ||
| digest = f"sha256:{'0' * 64}" | ||
| delete_path = f"/v2/{full_path(self.repo_name)}/blobs/{digest}" | ||
| response, _ = local_registry.get_response("DELETE", delete_path) | ||
| assert response.status_code == 404 | ||
| assert response.json()["errors"][0]["code"] == "BLOB_UNKNOWN" | ||
|
|
||
| def test_03_delete_without_login(self, setup, gen_user, local_registry, full_path): | ||
| """Delete requires push permissions on the namespace.""" | ||
| _, digest = setup | ||
| delete_path = f"/v2/{full_path(self.repo_name)}/blobs/{digest}" | ||
| user_helpless = gen_user() | ||
| with user_helpless: | ||
| response, _ = local_registry.get_response("DELETE", delete_path) | ||
| assert response.status_code in (401, 403) | ||
|
|
||
| def test_04_delete_pending_blob(self, setup, local_registry, full_path): | ||
| """Delete a pending blob via DELETE /v2/<name>/blobs/<digest>.""" | ||
| _, digest = setup | ||
| mount_path = ( | ||
| f"/v2/{full_path(self.dest_repo_name)}/blobs/uploads/" | ||
| f"?from={full_path(self.repo_name)}&mount={digest}" | ||
| ) | ||
| response, _ = local_registry.get_response("POST", mount_path) | ||
| assert response.status_code == 201 | ||
|
|
||
| delete_path = f"/v2/{full_path(self.dest_repo_name)}/blobs/{digest}" | ||
| response, _ = local_registry.get_response("DELETE", delete_path) | ||
| assert response.status_code == 202 | ||
|
|
||
| head_path = f"/v2/{full_path(self.dest_repo_name)}/blobs/{digest}" | ||
| response, _ = local_registry.get_response("HEAD", head_path) | ||
| assert response.status_code == 404 | ||
|
|
||
| def test_05_delete_by_digest(self, setup, local_registry, container_bindings, full_path): | ||
| """Delete a committed blob by digest via DELETE /v2/<name>/blobs/<digest>.""" | ||
| repository, digest = setup | ||
| delete_path = f"/v2/{full_path(self.repo_name)}/blobs/{digest}" | ||
| response, _ = local_registry.get_response("DELETE", delete_path) | ||
| assert response.status_code == 202 | ||
|
|
||
| _wait_for_blob(container_bindings, repository.pulp_href, digest, present=False) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's up with these numbers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Run the tests in a specific order. The fail cases and then the success case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does pytest guarantee the order? Do the tests need that order?