Skip to content

Commit

Permalink
Make binary image an optional parameter [CLOUDDST-2762]
Browse files Browse the repository at this point in the history
Binary image is no longer a mandatory parameter for adding bundles
and removing operators. If not specified, IIB request payload
is constructed without a binary image.
  • Loading branch information
querti committed Sep 24, 2020
1 parent 1301328 commit 221aacf
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 17 deletions.
20 changes: 12 additions & 8 deletions iiblib/iibclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand All @@ -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

Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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
Expand Down
92 changes: 83 additions & 9 deletions tests/test_iib_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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,
Expand All @@ -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(
Expand Down Expand Up @@ -215,39 +238,90 @@ 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,
)
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):
Expand Down

0 comments on commit 221aacf

Please sign in to comment.