From 26674fd0cf437484f4049c5fb8bea80f2ba8cd05 Mon Sep 17 00:00:00 2001 From: Tulsi Chandwani Date: Mon, 13 Feb 2023 13:42:25 -0600 Subject: [PATCH] Fix setting binary_image for fbc-operations --- iib/web/api_v1.py | 1 + tests/test_web/test_api_v1.py | 81 +++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+) diff --git a/iib/web/api_v1.py b/iib/web/api_v1.py index 83d191925..1ca82d1dd 100644 --- a/iib/web/api_v1.py +++ b/iib/web/api_v1.py @@ -1134,6 +1134,7 @@ def fbc_operations() -> Tuple[flask.Response, int]: payload.get('overwrite_from_index_token'), payload.get('build_tags'), payload.get('add_arches'), + flask.current_app.config['IIB_BINARY_IMAGE_CONFIG'], ] safe_args = _get_safe_args(args, payload) error_callback = failed_request_callback.s(request.id) diff --git a/tests/test_web/test_api_v1.py b/tests/test_web/test_api_v1.py index 64d892881..5f2d5a9f0 100644 --- a/tests/test_web/test_api_v1.py +++ b/tests/test_web/test_api_v1.py @@ -2548,3 +2548,84 @@ def test_fbc_operations_overwrite_not_allowed(mock_smfsc, client, db): error_msg = 'You must set "overwrite_from_index_token" to use "overwrite_from_index"' assert error_msg == rv.json['error'] mock_smfsc.assert_not_called() + + +@pytest.mark.parametrize( + ('binary_image', 'binary_image_config'), + ( + ('from:variable', {'prod': {'v4.5': 'some_binary_image'}}), + ('', {'prod': {'v4.5': 'some_binary_image'}}), + (None, {'prod': {'v4.5': 'some_binary_image'}}), + ('from:variable', {}), + ('', {}), + (None, {}), + ), +) +@mock.patch('iib.web.api_v1.handle_fbc_operation_request.apply_async') +@mock.patch('iib.web.api_v1.messaging.send_message_for_state_change') +def test_fbc_operations( + mock_smfc, + mock_hfor, + app, + auth_env, + client, + db, + binary_image, + binary_image_config, +): + data = { + 'binary_image': binary_image, + 'from_index': 'from:index', + 'fbc_fragment': 'fbc:fragment', + } + response_json = { + 'arches': [], + 'batch': 1, + 'batch_annotations': None, + 'binary_image': binary_image, + 'binary_image_resolved': None, + 'build_tags': [], + 'distribution_scope': None, + 'fbc_fragment': 'fbc:fragment', + 'fbc_fragment_resolved': None, + 'from_index': 'from:index', + 'from_index_resolved': None, + 'id': 1, + 'index_image': None, + 'index_image_resolved': None, + 'internal_index_image_copy': None, + 'internal_index_image_copy_resolved': None, + 'request_type': 'fbc-operations', + 'state': 'in_progress', + 'logs': { + 'url': 'http://localhost/api/v1/builds/1/logs', + 'expiration': '2020-02-15T17:03:00Z', + }, + 'state_history': [ + { + 'state': 'in_progress', + 'state_reason': 'The request was initiated', + 'updated': '2020-02-12T17:03:00Z', + } + ], + 'state_reason': 'The request was initiated', + 'updated': '2020-02-12T17:03:00Z', + 'user': 'tbrady@DOMAIN.LOCAL', + } + app.config['IIB_BINARY_IMAGE_CONFIG'] = binary_image_config + rv = client.post('/api/v1/builds/fbc-operations', json=data, environ_base=auth_env) + rv_json = rv.json + if binary_image or binary_image_config: + rv_json['state_history'][0]['updated'] = '2020-02-12T17:03:00Z' + rv_json['updated'] = '2020-02-12T17:03:00Z' + rv_json['logs']['expiration'] = '2020-02-15T17:03:00Z' + response_json['binary_image'] = binary_image if binary_image else None + assert response_json == rv_json + assert 'overwrite_from_index_token' not in rv_json + mock_hfor.assert_called_once() + mock_smfc.assert_called_once_with(mock.ANY, new_batch_msg=True) + else: + assert rv.status_code == 400 + assert 'The "binary_image" value must be a non-empty string' == rv.json['error'] + mock_smfc.assert_not_called() + mock_hfor.assert_not_called()