Skip to content

Commit

Permalink
Do not remove index images signatures for fbc opted images
Browse files Browse the repository at this point in the history
  • Loading branch information
midnightercz committed May 17, 2024
1 parent a1afde8 commit 9ea318c
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 2 deletions.
8 changes: 6 additions & 2 deletions pubtools/_quay/operator_pusher.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ def iib_remove_operators(

def get_existing_index_images(self, quay_client: QuayClient) -> List[Tuple[str, str, str]]:
"""
Return existing index images for push items.
Return existing index images for non-fbc push items.
Args:
quay_client (QuayClient): quay_client_instance
Expand All @@ -409,7 +409,11 @@ def get_existing_index_images(self, quay_client: QuayClient) -> List[Tuple[str,
current_index_images = []

manifest_list: Any = {}
for version in sorted(self.version_items_mapping.keys()):
for version, items in sorted(self.version_items_mapping.items()):
items_opted_in, failed_items = self._get_fbc_opted_in_items()
if not self._get_non_fbc_items_for_version(items, version, items_opted_in):
continue

image_ref = "{0}:{1}".format(index_image_repo, version)
try:
manifest_list = quay_client.get_manifest(
Expand Down
10 changes: 10 additions & 0 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ def test_push_docker_multiarch_merge_ml_operator(
# pubtools-pyxis-get-repo-metadata
{"fbc_opt_in": False},
{"fbc_opt_in": False},
# pubtools-pyxis-get-repo-metadata in get_index_images
{"fbc_opt_in": False},
{"fbc_opt_in": False},
]
signer_wrapper_run_entry_point.side_effect = [
# fetch existing signatures
Expand Down Expand Up @@ -1710,7 +1713,9 @@ def test_remove_repo(
@mock.patch("pubtools._quay.command_executor.docker.APIClient")
@mock.patch("pubtools._quay.operator_pusher.run_entrypoint")
@mock.patch("pubtools._quay.command_executor.RemoteExecutor._run_cmd")
@mock.patch("pubtools._quay.operator_pusher.pyxis_get_repo_metadata")
def test_push_docker_operator_verify_bundle_fail(
mock_get_repo_metadata,
mock_run_cmd,
mock_run_entrypoint_operator_pusher,
mock_api_client,
Expand All @@ -1734,6 +1739,11 @@ def test_push_docker_operator_verify_bundle_fail(
# pubtools-pyxis-get-operator-indices
[{"ocp_version": "4.5"}, {"ocp_version": "4.6"}],
]
mock_get_repo_metadata.side_effect = [
{"fbc_opt_in": False},
{"fbc_opt_in": False},
{"fbc_opt_in": False},
]
mock_run_cmd.return_value = ("Login Succeeded", "err")
mock_api_client.return_value.exec_start.return_value = b"Login Succeeded"
mock_api_client.return_value.exec_inspect.return_value = {"ExitCode": 0}
Expand Down
73 changes: 73 additions & 0 deletions tests/test_operator_pusher.py
Original file line number Diff line number Diff line change
Expand Up @@ -1060,7 +1060,9 @@ def test_push_operators_prerelease_invalid_origin(
@mock.patch("pubtools._quay.push_docker.QuayClient")
@mock.patch("pubtools._quay.push_docker.QuayApiClient")
@mock.patch("pubtools._quay.operator_pusher.run_entrypoint")
@mock.patch("pubtools._quay.operator_pusher.pyxis_get_repo_metadata")
def test_get_existing_index_images(
mock_get_repo_metadata,
mock_run_entrypoint,
mock_quay_client,
mock_quay_api,
Expand All @@ -1069,6 +1071,10 @@ def test_get_existing_index_images(
manifest_list_data,
fake_cert_key_paths,
):
mock_get_repo_metadata.side_effect = [
{"fbc_opt_in": False},
{"fbc_opt_in": False},
]
mock_run_entrypoint.return_value = [{"ocp_version": "4.5"}, {"ocp_version": "4.6"}]
mock_quay_client.get_manifest.return_value = manifest_list_data

Expand Down Expand Up @@ -1147,7 +1153,62 @@ def test_get_existing_index_images(
@mock.patch("pubtools._quay.push_docker.QuayClient")
@mock.patch("pubtools._quay.push_docker.QuayApiClient")
@mock.patch("pubtools._quay.operator_pusher.run_entrypoint")
@mock.patch("pubtools._quay.operator_pusher.pyxis_get_repo_metadata")
def test_get_existing_index_images_fbc(
mock_get_repo_metadata,
mock_run_entrypoint,
mock_quay_client,
mock_quay_api,
target_settings,
operator_push_item_ok,
manifest_list_data,
fake_cert_key_paths,
):
mock_get_repo_metadata.side_effect = [
{"fbc_opt_in": True},
{"fbc_opt_in": False},
]
mock_run_entrypoint.return_value = [{"ocp_version": "4.11"}, {"ocp_version": "4.12"}]
mock_quay_client.get_manifest.return_value = manifest_list_data

pusher = operator_pusher.OperatorPusher([operator_push_item_ok], "3", target_settings)
existing_index_images = pusher.get_existing_index_images(mock_quay_client)
print(mock_quay_client.mock_calls)
assert sorted(existing_index_images) == [
(
"sha256:146ab6fa7ba3ab4d154b09c1c5522e4966ecd071bf23d1ba3df6c8b9fc33f8cb",
"v4.12",
"operators/index-image",
),
(
"sha256:2e8f38a0a8d2a450598430fa70c7f0b53aeec991e76c3e29c63add599b4ef7ee",
"v4.12",
"operators/index-image",
),
(
"sha256:496fb0ff2057c79254c9dc6ba999608a98219c5c93142569a547277c679e532c",
"v4.12",
"operators/index-image",
),
(
"sha256:b3f9218fb5839763e62e52ee6567fe331aa1f3c644f9b6f232ff23959257acf9",
"v4.12",
"operators/index-image",
),
(
"sha256:bbef1f46572d1f33a92b53b0ba0ed5a1d09dab7ffe64be1ae3ae66e76275eabd",
"v4.12",
"operators/index-image",
),
]


@mock.patch("pubtools._quay.push_docker.QuayClient")
@mock.patch("pubtools._quay.push_docker.QuayApiClient")
@mock.patch("pubtools._quay.operator_pusher.run_entrypoint")
@mock.patch("pubtools._quay.operator_pusher.pyxis_get_repo_metadata")
def test_get_existing_index_images_raises_401(
mock_get_repo_metadata,
mock_run_entrypoint,
mock_quay_client,
mock_quay_api,
Expand All @@ -1156,6 +1217,11 @@ def test_get_existing_index_images_raises_401(
manifest_list_data,
fake_cert_key_paths,
):
mock_get_repo_metadata.side_effect = [
{"fbc_opt_in": False},
{"fbc_opt_in": False},
{"fbc_opt_in": False},
]
mock_run_entrypoint.return_value = [{"ocp_version": "4.5"}, {"ocp_version": "4.6"}]
mock_quay_client.get_manifest.side_effect = [
requests.exceptions.HTTPError(response=mock.Mock(status_code=401)),
Expand Down Expand Up @@ -1213,7 +1279,9 @@ def test_get_existing_index_images_raises_401(
@mock.patch("pubtools._quay.push_docker.QuayClient")
@mock.patch("pubtools._quay.push_docker.QuayApiClient")
@mock.patch("pubtools._quay.operator_pusher.run_entrypoint")
@mock.patch("pubtools._quay.operator_pusher.pyxis_get_repo_metadata")
def test_get_existing_index_images_raises_500(
mock_get_repo_metadata,
mock_run_entrypoint,
mock_quay_client,
mock_quay_api,
Expand All @@ -1222,6 +1290,11 @@ def test_get_existing_index_images_raises_500(
manifest_list_data,
fake_cert_key_paths,
):
mock_get_repo_metadata.side_effect = [
{"fbc_opt_in": False},
{"fbc_opt_in": False},
{"fbc_opt_in": False},
]
mock_run_entrypoint.return_value = [{"ocp_version": "4.5"}, {"ocp_version": "4.6"}]
mock_quay_client.get_manifest.side_effect = [
requests.exceptions.HTTPError("500", response=mock.Mock(status_code=500)),
Expand Down

0 comments on commit 9ea318c

Please sign in to comment.