Skip to content

Commit

Permalink
Add support for providing "overwrite-from-index-token" while calling …
Browse files Browse the repository at this point in the history
…IIB[CLOUDDST-949]

IIB requires overwrite_from_index_token to be specified when user wants to overwrite an index
image in a custom private repository. This commit enables pubtools-iib to be able to support
that option while calling IIB.
  • Loading branch information
yashvardhannanavati committed Jun 10, 2020
1 parent c2cbf0b commit d28e029
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 12 deletions.
24 changes: 22 additions & 2 deletions pubtools/iib/iib_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,24 @@
},
("--overwrite-from-index",): {
"group": "IIB service",
"help": "overwrite from_index_image as output",
"help": (
"overwrite from_index_image as output. If this is true,"
" overwrite-from-index-token should also be specified."
),
"required": False,
"type": bool,
},
("--overwrite-from-index-token",): {
"group": "IIB service",
"help": (
"destination repo token to overwrite from_index_image"
"If this is specified, overwrite-from-index must be set to True."
"Or set the OVERWRITE_FROM_INDEX_TOKEN environment variable."
),
"required": False,
"type": str,
"env_variable": "OVERWRITE_FROM_INDEX_TOKEN",
},
("--skip-pulp",): {
"group": "IIB service",
"help": "Skip operations on pulp",
Expand Down Expand Up @@ -205,8 +219,14 @@ def _iib_op_main(args, operation=None, items_final_state="PUSHED"):
extra_args = {"cnr_token": args.iib_cnr_token}
if args.iib_legacy_org:
extra_args["organization"] = args.iib_legacy_org
if args.overwrite_from_index:
if args.overwrite_from_index and args.overwrite_from_index_token:
extra_args["overwrite_from_index"] = args.overwrite_from_index
extra_args["overwrite_from_index_token"] = args.overwrite_from_index_token
else:
raise ValueError(
"Either both or neither of overwrite-from-index and "
"overwrite-from-index-token should be specified."
)

build_details = bundle_op(
args.index_image,
Expand Down
88 changes: 78 additions & 10 deletions tests/test_iib_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ def add_bundles_mock_calls_tester(
cnr_token="cnr_token",
organization="legacy-org",
overwrite_from_index=True,
overwrite_from_index_token="overwrite_from_index_token",
)
fixture_iib_client.assert_called_once_with(
"iib-server", auth=fixture_iib_krb_auth.return_value, ssl_verify=False
Expand All @@ -185,6 +186,7 @@ def add_bundles_mock_calls_tester_not_called(
cnr_token="cnr_token",
organization="legacy-org",
overwrite_from_index=True,
overwrite_from_index_token="overwrite_from_index_token",
)
fixture_iib_client.assert_called_once_with(
"iib-server", auth=fixture_iib_krb_auth.return_value, ssl_verify=False
Expand All @@ -203,7 +205,12 @@ def remove_operators_mock_calls_tester_not_called(
"iib-server", auth=fixture_iib_krb_auth.return_value, ssl_verify=False
)
fixture_iib_client.return_value.remove_operators.assert_called_once_with(
"index-image", "binary-image", ["1"], ["arch"], overwrite_from_index=True
"index-image",
"binary-image",
["1"],
["arch"],
overwrite_from_index=True,
overwrite_from_index_token="overwrite_from_index_token",
)
fixture_pulplib_repo_sync.assert_not_called()
fixture_pulplib_repo_publish.assert_not_called()
Expand All @@ -219,7 +226,12 @@ def remove_operators_mock_calls_tester(
"iib-server", auth=fixture_iib_krb_auth.return_value, ssl_verify=False
)
fixture_iib_client.return_value.remove_operators.assert_called_once_with(
"index-image", "binary-image", ["1"], ["arch"], overwrite_from_index=True
"index-image",
"binary-image",
["1"],
["arch"],
overwrite_from_index=True,
overwrite_from_index_token="overwrite_from_index_token",
)
fixture_pulplib_repo_sync.assert_called_once()
assert fixture_pulplib_repo_sync.mock_calls[0].args[0].feed == "https://feed.com"
Expand Down Expand Up @@ -266,7 +278,11 @@ def test_add_bundles_cli(
fixture_common_iib_op_args
+ ["--bundle", "bundle1", "--iib-legacy-org", "legacy-org"]
+ extra_args,
{"PULP_PASSWORD": "pulp-password", "CNR_TOKEN": "cnr_token"},
{
"PULP_PASSWORD": "pulp-password",
"CNR_TOKEN": "cnr_token",
"OVERWRITE_FROM_INDEX_TOKEN": "overwrite_from_index_token",
},
) as entry_func:
entry_func()
assert fixture_pushcollector.items == push_items
Expand Down Expand Up @@ -303,7 +319,11 @@ def test_add_bundles_cli_error(
("pubtools_iib", "console_scripts", "pubtools-iib-add-bundles"),
"pubtools-iib-add-bundle",
fixture_common_iib_op_args + ["--bundle", "bundle1"],
{"PULP_PASSWORD": "pulp-password", "CNR_TOKEN": "cnr_token"},
{
"PULP_PASSWORD": "pulp-password",
"CNR_TOKEN": "cnr_token",
"OVERWRITE_FROM_INDEX_TOKEN": "overwrite_from_index_token",
},
) as entry_func:
try:
entry_func()
Expand All @@ -326,13 +346,16 @@ def test_add_bundles_py(
fixture_container_image_repo,
fixture_common_iib_op_args,
):

repo = fixture_container_image_repo
fixture_pulp_client.return_value.search_repository.return_value = [repo]
fixture_pulp_client.return_value.get_repository.return_value = repo
with setup_entry_point_py(
("pubtools_iib", "console_scripts", "pubtools-iib-add-bundles"),
{"PULP_PASSWORD": "pulp-password", "CNR_TOKEN": "cnr_token"},
{
"PULP_PASSWORD": "pulp-password",
"CNR_TOKEN": "cnr_token",
"OVERWRITE_FROM_INDEX_TOKEN": "overwrite_from_index_token",
},
) as entry_func:
retval = entry_func(
["cmd"] + fixture_common_iib_op_args + ["--bundle", "bundle1"]
Expand All @@ -350,6 +373,7 @@ def test_add_bundles_py(
["arch"],
cnr_token="cnr_token",
overwrite_from_index=True,
overwrite_from_index_token="overwrite_from_index_token",
)
fixture_pulplib_repo_sync.assert_called_once()
assert fixture_pulplib_repo_sync.mock_calls[0].args[0].feed == "https://feed.com"
Expand All @@ -372,7 +396,11 @@ def test_add_bundles_py_multiple_bundles(
fixture_pulp_client.return_value.get_repository.return_value = repo
with setup_entry_point_py(
("pubtools_iib", "console_scripts", "pubtools-iib-add-bundles"),
{"PULP_PASSWORD": "pulp-password", "CNR_TOKEN": "cnr_token"},
{
"PULP_PASSWORD": "pulp-password",
"CNR_TOKEN": "cnr_token",
"OVERWRITE_FROM_INDEX_TOKEN": "overwrite_from_index_token",
},
) as entry_func:
retval = entry_func(
["cmd"]
Expand All @@ -392,6 +420,7 @@ def test_add_bundles_py_multiple_bundles(
["arch"],
cnr_token="cnr_token",
overwrite_from_index=True,
overwrite_from_index_token="overwrite_from_index_token",
)
fixture_pulplib_repo_sync.assert_called_once()
assert fixture_pulplib_repo_sync.mock_calls[0].args[0].feed == "https://feed.com"
Expand Down Expand Up @@ -438,7 +467,10 @@ def test_remove_operators_cli(
("pubtools_iib", "console_scripts", "pubtools-iib-remove-operators"),
"pubtools-iib-remove-operators",
fixture_common_iib_op_args + ["--operator", "1"] + extra_args,
{"PULP_PASSWORD": "pulp-password"},
{
"PULP_PASSWORD": "pulp-password",
"OVERWRITE_FROM_INDEX_TOKEN": "overwrite_from_index_token",
},
) as entry_func:
entry_func()
assert fixture_pushcollector.items == push_items
Expand Down Expand Up @@ -477,7 +509,10 @@ def test_remove_operators_cli_error(
("pubtools_iib", "console_scripts", "pubtools-iib-remove-operators"),
"pubtools-iib-remove-operators",
fixture_common_iib_op_args + ["--operator", "1"],
{"PULP_PASSWORD": "pulp-password"},
{
"PULP_PASSWORD": "pulp-password",
"OVERWRITE_FROM_INDEX_TOKEN": "overwrite_from_index_token",
},
) as entry_func:
try:
entry_func()
Expand Down Expand Up @@ -506,7 +541,10 @@ def test_remove_operators_py(
fixture_pulp_client.return_value.get_repository.return_value = repo
with setup_entry_point_py(
("pubtools_iib", "console_scripts", "pubtools-iib-remove-operators"),
{"PULP_PASSWORD": "pulp-password"},
{
"PULP_PASSWORD": "pulp-password",
"OVERWRITE_FROM_INDEX_TOKEN": "overwrite_from_index_token",
},
) as entry_func:
retval = entry_func(["cmd"] + fixture_common_iib_op_args + ["--operator", "1"])

Expand All @@ -526,3 +564,33 @@ def test_invalid_op(fixture_common_iib_op_args):
assert False, "Should have raised"
except ValueError:
pass


def test_overwrite_from_index_token_missing(
fixture_iib_client,
fixture_pulp_client,
fixture_iib_krb_auth,
fixture_pulplib_repo_publish,
fixture_pulplib_repo_sync,
fixture_container_image_repo,
fixture_common_iib_op_args,
):
error_msg = (
"Either both or neither of overwrite-from-index "
"and overwrite-from-index-token should be specified."
)
repo = fixture_container_image_repo
fixture_pulp_client.return_value.search_repository.return_value = [repo]
fixture_pulp_client.return_value.get_repository.return_value = repo
with pytest.raises(ValueError, match=error_msg):
with setup_entry_point_py(
("pubtools_iib", "console_scripts", "pubtools-iib-add-bundles"),
{
"PULP_PASSWORD": "pulp-password",
"CNR_TOKEN": "cnr_token",
"OVERWRITE_FROM_INDEX_TOKEN": "",
},
) as entry_func:
retval = entry_func(
["cmd"] + fixture_common_iib_op_args + ["--bundle", "bundle1"]
)
1 change: 1 addition & 0 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def setup_task(
cnr_token=None,
organization=None,
overwrite_from_index=False,
overwrite_from_index_token=None,
state_seq=("in_progress", "finished"),
op_type="add",
):
Expand Down

0 comments on commit d28e029

Please sign in to comment.