Skip to content

Commit

Permalink
Fix index_image_resolved bug for merge-index-image endpoint
Browse files Browse the repository at this point in the history
index_image_resolved attribute is only valid for Add and Rm requests
and shouldn't be used for a merge-index-image request.
  • Loading branch information
yashvardhannanavati committed Mar 3, 2021
1 parent 63c45bf commit 46775ad
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 18 deletions.
14 changes: 10 additions & 4 deletions iib/workers/tasks/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ def _update_index_image_pull_spec(
overwrite_from_index=False,
overwrite_from_index_token=None,
resolved_prebuild_from_index=None,
add_or_rm=False,
):
"""
Update the request with the modified index image.
Expand All @@ -188,6 +189,7 @@ def _update_index_image_pull_spec(
:param str overwrite_from_index_token: the token used for overwriting the input
``from_index`` image.
:param str resolved_prebuild_from_index: resolved index image before starting the build.
:param bool add_or_rm: true if the request is an ``Add`` or ``Rm`` request. defaults to false
:raises IIBError: if the manifest list couldn't be created and pushed
"""
conf = get_worker_config()
Expand All @@ -212,14 +214,16 @@ def _update_index_image_pull_spec(
else:
index_image = output_pull_spec

with set_registry_token(overwrite_from_index_token, index_image):
index_image_resolved = get_resolved_image(index_image)

payload = {
'arches': list(arches),
'index_image': index_image,
'index_image_resolved': index_image_resolved,
}

if add_or_rm:
with set_registry_token(overwrite_from_index_token, index_image):
index_image_resolved = get_resolved_image(index_image)
payload['index_image_resolved'] = index_image_resolved

update_request(request_id, payload, exc_msg='Failed setting the index image on the request')


Expand Down Expand Up @@ -1128,6 +1132,7 @@ def handle_add_request(
overwrite_from_index,
overwrite_from_index_token,
from_index_resolved,
add_or_rm=True,
)
set_request_state(
request_id, 'complete', 'The operator bundle(s) were successfully added to the index image'
Expand Down Expand Up @@ -1223,6 +1228,7 @@ def handle_rm_request(
overwrite_from_index,
overwrite_from_index_token,
from_index_resolved,
add_or_rm=True,
)
set_request_state(
request_id, 'complete', 'The operator(s) were successfully removed from the index image'
Expand Down
47 changes: 33 additions & 14 deletions tests/test_workers/test_tasks/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,20 @@ def test_create_and_push_manifest_list(mock_run_cmd, mock_td, tmp_path):


@pytest.mark.parametrize(
'iib_index_image_output_registry, from_index, overwrite, expected, resolved_from_index',
'iib_index_image_output_registry, from_index, overwrite, expected, resolved_from_index,'
'add_or_rm',
(
(None, None, False, '{default}', None),
(None, None, False, '{default}', None, False),
(
'registry-proxy.domain.local',
None,
False,
'registry-proxy.domain.local/{default_no_registry}',
None,
False,
),
(None, 'quay.io/ns/iib:v4.5', True, 'quay.io/ns/iib:v4.5', 'quay.io/ns/iib:abcdef'),
(None, 'quay.io/ns/iib:v5.4', True, 'quay.io/ns/iib:v5.4', 'quay.io/ns/iib:fedcba'),
(None, 'quay.io/ns/iib:v4.5', True, 'quay.io/ns/iib:v4.5', 'quay.io/ns/iib:abcdef', True),
(None, 'quay.io/ns/iib:v5.4', True, 'quay.io/ns/iib:v5.4', 'quay.io/ns/iib:fedcba', True),
),
)
@mock.patch('iib.workers.tasks.build.get_worker_config')
Expand All @@ -99,6 +101,7 @@ def test_update_index_image_pull_spec(
overwrite,
expected,
resolved_from_index,
add_or_rm,
):
default_no_registry = 'namespace/some-image:3'
default = f'quay.io/{default_no_registry}'
Expand All @@ -112,19 +115,35 @@ def test_update_index_image_pull_spec(
'iib_index_image_output_registry': iib_index_image_output_registry,
'iib_registry': 'quay.io',
}
build._update_index_image_pull_spec(
default,
request_id,
arches,
from_index,
overwrite,
overwrite_token,
resolved_prebuild_from_index=resolved_from_index,
)

if add_or_rm:
build._update_index_image_pull_spec(
default,
request_id,
arches,
from_index,
overwrite,
overwrite_token,
resolved_prebuild_from_index=resolved_from_index,
add_or_rm=add_or_rm,
)
else:
build._update_index_image_pull_spec(
default,
request_id,
arches,
from_index,
overwrite,
overwrite_token,
resolved_prebuild_from_index=resolved_from_index,
)

mock_ur.assert_called_once()
update_request_payload = mock_ur.call_args[0][1]
assert update_request_payload.keys() == {'arches', 'index_image', 'index_image_resolved'}
if add_or_rm:
assert update_request_payload.keys() == {'arches', 'index_image', 'index_image_resolved'}
else:
assert update_request_payload.keys() == {'arches', 'index_image'}
assert update_request_payload['index_image'] == expected_pull_spec
if overwrite:
mock_ofi.assert_called_once_with(
Expand Down

0 comments on commit 46775ad

Please sign in to comment.