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 2e60dd3
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 11 deletions.
20 changes: 19 additions & 1 deletion 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,9 +219,13 @@ 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:
extra_args["overwrite_from_index"] = args.overwrite_from_index

if args.overwrite_from_index_token:
extra_args["overwrite_from_index_token"] = args.overwrite_from_index_token

build_details = bundle_op(
args.index_image,
args.binary_image,
Expand Down
59 changes: 49 additions & 10 deletions tests/test_iib_ops.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import contextlib
from copy import deepcopy
import mock
import pkg_resources
import pytest
Expand Down Expand Up @@ -162,6 +163,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 +187,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 +206,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 +227,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 +279,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 +320,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 +347,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 +374,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 +397,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 +421,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 +468,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 +510,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 +542,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 Down
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 2e60dd3

Please sign in to comment.