diff --git a/iiblib/iibclient.py b/iiblib/iibclient.py index 6662042..b0e22df 100644 --- a/iiblib/iibclient.py +++ b/iiblib/iibclient.py @@ -467,9 +467,9 @@ def _check_response(response): def add_bundles( self, index_image, - binary_image, bundles, arches, + binary_image=None, cnr_token=None, organization=None, overwrite_from_index=False, @@ -481,12 +481,12 @@ def add_bundles( Args: index_image (str) Index image ref used as source to rebuild - binary_image (str) - Image with binary used to rebuild existing index image bundles (list) List of references to bundle images to be added to index image arches (list) List of architectures supported in new index image + binary_image (str) + optional. Image with binary used to rebuild existing index image cnr_token (srt) optional. CNR token. organization (str) @@ -510,10 +510,12 @@ def add_bundles( post_data = { "from_index": index_image, - "binary_image": binary_image, "add_arches": arches, } + if binary_image: + post_data["binary_image"] = binary_image + if bundles: post_data["bundles"] = bundles @@ -548,9 +550,9 @@ def add_bundles( def remove_operators( self, index_image, - binary_image, operators, arches, + binary_image=None, overwrite_from_index=False, overwrite_from_index_token=None, raw=False, @@ -560,12 +562,12 @@ def remove_operators( Args: index_image (str) Index image ref used as source to rebuild - binary_image (str) - Image with binary used to rebuild existing index image operators (list) List of operators to be removed from existing index image arches (list) List of architectures supported in new index image + binary_image (str) + optional. Image with binary used to rebuild existing index image overwrite_from_index (bool) optional. Indicates if resulting index_image needs to be overwritten at the location of from_index. If this is provided, @@ -584,11 +586,13 @@ def remove_operators( """ post_data = { "from_index": index_image, - "binary_image": binary_image, "operators": operators, "add_arches": arches, } + if binary_image: + post_data["binary_image"] = binary_image + if overwrite_from_index: if overwrite_from_index_token: post_data["overwrite_from_index"] = overwrite_from_index diff --git a/tests/test_iib_client.py b/tests/test_iib_client.py index e7c7c0e..ed856a9 100644 --- a/tests/test_iib_client.py +++ b/tests/test_iib_client.py @@ -64,6 +64,29 @@ def fixture_build_details_json2(): return json +@pytest.fixture +def fixture_build_details_json3(): + json = { + "id": 1, + "state": "in_progress", + "state_reason": "state_reason", + "state_history": [], + "from_index": "from_index", + "from_index_resolved": "from_index_resolved", + "bundles": ["bundles1"], + "removed_operators": ["operator1"], + "organization": "organization", + "binary_image": "mapped_binary_image", + "binary_image_resolved": "mapped_binary_image_resolved", + "index_image": "index_image", + "request_type": "request_type", + "arches": ["x86_64"], + "bundle_mapping": {"bundle_mapping": "map"}, + "omps_operator_version": {"operator": "1.0"}, + } + return json + + @pytest.fixture def fixture_builds_page1_json(fixture_build_details_json): json = { @@ -148,14 +171,14 @@ def test_iib_client(fixture_build_details_json, fixture_builds_page1_json): iibc = IIBClient("fake-host") assert iibc.add_bundles( - "index-image", "binary", ["bundles-map"], [] + "index-image", ["bundles-map"], [], binary_image="binary" ) == IIBBuildDetailsModel.from_dict(fixture_build_details_json) assert ( iibc.add_bundles( "index-image", - "binary", ["bundles-map"], [], + binary_image="binary", cnr_token="cnr", organization="org", overwrite_from_index=True, @@ -164,22 +187,22 @@ def test_iib_client(fixture_build_details_json, fixture_builds_page1_json): == IIBBuildDetailsModel.from_dict(fixture_build_details_json) ) assert ( - iibc.add_bundles("index-image", "binary", ["bundles-map"], [], raw=True) + iibc.add_bundles("index-image", ["bundles-map"], [], binary_image="binary", raw=True) == fixture_build_details_json ) assert ( iibc.remove_operators( "index-image", - "binary", ["operator1"], [], + binary_image="binary", overwrite_from_index=True, overwrite_from_index_token="str", ) == IIBBuildDetailsModel.from_dict(fixture_build_details_json) ) assert ( - iibc.remove_operators("index-image", "binary", ["operator1"], [], raw=True) + iibc.remove_operators("index-image", ["operator1"], [], binary_image="binary", raw=True) == fixture_build_details_json ) assert iibc.get_build(1) == IIBBuildDetailsModel.from_dict( @@ -215,25 +238,25 @@ def test_iib_client_failure(fixture_build_details_json): with pytest.raises(ValueError, match=error_msg): iibc.remove_operators( "index-image", - "binary", ["operator1"], [], + binary_image="binary", overwrite_from_index=True, ) with pytest.raises(ValueError, match=error_msg): iibc.remove_operators( "index-image", - "binary", ["operator1"], [], + binary_image="binary", overwrite_from_index_token="str", ) with pytest.raises(ValueError, match=error_msg): iibc.add_bundles( "index-image", - "binary", ["bundles-map"], [], + binary_image="binary", cnr_token="cnr", organization="org", overwrite_from_index=True, @@ -241,13 +264,64 @@ def test_iib_client_failure(fixture_build_details_json): with pytest.raises(ValueError, match=error_msg): iibc.add_bundles( "index-image", - "binary", + ["bundles-map"], + [], + binary_image="binary", + cnr_token="cnr", + organization="org", + overwrite_from_index_token="str", + ) + + +def test_iib_client_no_binary_image(fixture_build_details_json3): + with requests_mock.Mocker() as m: + m.register_uri( + "POST", + "/api/v1/builds/add", + status_code=200, + json=fixture_build_details_json3, + ) + m.register_uri( + "POST", + "/api/v1/builds/rm", + status_code=200, + json=fixture_build_details_json3, + ) + + iibc = IIBClient("fake-host") + assert iibc.add_bundles( + "index-image", ["bundles-map"], [] + ) == IIBBuildDetailsModel.from_dict(fixture_build_details_json3) + assert ( + iibc.add_bundles( + "index-image", ["bundles-map"], [], cnr_token="cnr", organization="org", + overwrite_from_index=True, overwrite_from_index_token="str", ) + == IIBBuildDetailsModel.from_dict(fixture_build_details_json3) + ) + assert ( + iibc.add_bundles("index-image", ["bundles-map"], [], raw=True) + == fixture_build_details_json3 + ) + assert ( + iibc.remove_operators( + "index-image", + ["operator1"], + [], + overwrite_from_index=True, + overwrite_from_index_token="str", + ) + == IIBBuildDetailsModel.from_dict(fixture_build_details_json3) + ) + assert ( + iibc.remove_operators("index-image", ["operator1"], [], raw=True) + == fixture_build_details_json3 + ) def test_client_wait_for_build(fixture_build_details_json):