Skip to content

Commit

Permalink
Raise error for nonexistent source tag [CLOUDDST-24434] (#286)
Browse files Browse the repository at this point in the history
Source tag specified for removing tags should exist.
  • Loading branch information
emilyzheng authored Feb 10, 2025
1 parent 7a85ffd commit 7f2b4f8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/pubtools/_quay/tag_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,10 @@ def tag_remove_calculate_archs(
if push_item.metadata["tag_source"]:
source_image = "{0}:{1}".format(full_repo, push_item.metadata["tag_source"])
source_details = self.get_image_details(source_image, executor)
if not source_details:
raise BadPushItem(
"Source tag {0} doesn't exist".format(push_item.metadata["tag_source"])
)
else:
source_details = None

Expand Down
28 changes: 28 additions & 0 deletions tests/test_tag_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,34 @@ def test_tag_remove_calculate_archs_no_src(
assert ret == "something-other"


@mock.patch("pubtools._quay.tag_docker.LocalExecutor")
@mock.patch("pubtools._quay.tag_docker.TagDocker.get_image_details")
def test_tag_remove_calculate_archs_nonexistent_src(
mock_get_image_details,
mock_local_executor,
target_settings,
tag_docker_push_item_remove_src,
):
hub = mock.MagicMock()

mock_get_image_details.return_value = None
tag_docker_instance = tag_docker.TagDocker(
[tag_docker_push_item_remove_src],
hub,
"1",
"some-target",
target_settings,
)

with pytest.raises(exceptions.BadPushItem, match="Source tag v1.5 doesn't exist"):
tag_docker_instance.tag_remove_calculate_archs(
tag_docker_push_item_remove_src, "v1.8", mock_local_executor.return_value
)
mock_get_image_details.assert_called_once_with(
"quay.io/some-namespace/namespace----test_repo2:v1.5", mock_local_executor.return_value
)


@mock.patch("pubtools._quay.tag_docker.LocalExecutor")
@mock.patch("pubtools._quay.tag_docker.QuayClient")
@mock.patch("pubtools._quay.tag_docker.TagDocker.get_image_details")
Expand Down

0 comments on commit 7f2b4f8

Please sign in to comment.