Skip to content

Commit

Permalink
pass userdata to osbs-client and also add it for source builds
Browse files Browse the repository at this point in the history
* CLOUDBLD-7986

Signed-off-by: Robert Cerven <[email protected]>
  • Loading branch information
rcerven committed Nov 19, 2021
1 parent 1937346 commit d6e1bec
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 4 deletions.
16 changes: 14 additions & 2 deletions koji_containerbuild/plugins/builder_containerbuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,8 @@ def createContainer(self, src=None, target_info=None, arches=None,
branch=None, push_url=None, koji_parent_build=None,
release=None, flatpak=False, signing_intent=None,
compose_ids=None, skip_build=False, triggered_after_koji_task=None,
dependency_replacements=None, operator_csv_modifications_url=None):
dependency_replacements=None, operator_csv_modifications_url=None,
userdata=None):
if not yum_repourls:
yum_repourls = []

Expand Down Expand Up @@ -795,6 +796,8 @@ def createContainer(self, src=None, target_info=None, arches=None,
create_build_args['triggered_after_koji_task'] = triggered_after_koji_task
if operator_csv_modifications_url:
create_build_args['operator_csv_modifications_url'] = operator_csv_modifications_url
if userdata:
create_build_args['userdata'] = userdata

orchestrator_create_build_args = create_build_args.copy()
orchestrator_create_build_args['platforms'] = arches
Expand Down Expand Up @@ -1024,6 +1027,7 @@ def handler(self, src, target, opts=None):
skip_build=skip_build,
triggered_after_koji_task=triggered_after_koji_task,
operator_csv_modifications_url=opts.get('operator_csv_modifications_url'),
userdata=opts.get('userdata', None),
)

result = self.createContainer(**kwargs)
Expand Down Expand Up @@ -1089,6 +1093,10 @@ class BuildSourceContainerTask(BaseContainerTask):
"possible names, see REACTOR_CONFIG in "
"orchestrator.log."
},
"userdata": {
"type": "object",
"description": "User defined dictionary containing custom metadata",
},
},
"anyOf": [
{"required": ["koji_build_nvr"]},
Expand All @@ -1108,7 +1116,8 @@ def __init__(self, id, method, params, session, options, workdir=None, demux=Fal
self.incremental_log_basename = 'orchestrator.log'

def createSourceContainer(self, target_info=None, scratch=None, component=None,
koji_build_id=None, koji_build_nvr=None, signing_intent=None):
koji_build_id=None, koji_build_nvr=None, signing_intent=None,
userdata=None):
this_task = self.session.getTaskInfo(self.id)
self.logger.debug("This task: %r", this_task)
owner_info = self.session.getUser(this_task['owner'])
Expand All @@ -1126,6 +1135,8 @@ def createSourceContainer(self, target_info=None, scratch=None, component=None,

if signing_intent:
create_build_args['signing_intent'] = signing_intent
if userdata:
create_build_args['userdata'] = userdata

try:
create_method = self.osbs().create_source_container_build
Expand Down Expand Up @@ -1195,6 +1206,7 @@ def handler(self, target, opts=None):
koji_build_id=build_id,
koji_build_nvr=build_nvr,
signing_intent=opts.get('signing_intent', None),
userdata=opts.get('userdata', None),
)

result = self.createSourceContainer(**kwargs)
Expand Down
6 changes: 5 additions & 1 deletion koji_containerbuild/plugins/cli_containerbuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ def parse_source_arguments(options, args):
parser.add_option("--koji-build-nvr",
help=_("Koji build nvr for sources, "
"is required or koji-build-id is provided"))
parser.add_option("--userdata",
help=_("JSON dictionary of user defined custom metadata"))

build_opts, args = parser.parse_args(args)

Expand All @@ -221,12 +223,14 @@ def parse_source_arguments(options, args):
parser.error(_("at least one of --koji-build-id and --koji-build-nvr has to be specified"))

opts = {}
keys = ('scratch', 'signing_intent', 'koji_build_id', 'koji_build_nvr')
keys = ('scratch', 'signing_intent', 'koji_build_id', 'koji_build_nvr', 'userdata')

for key in keys:
val = getattr(build_opts, key)
if val is not None:
opts[key] = val
if key == 'userdata':
opts[key] = json.loads(val)
# create the parser in this function and return it to
# simplify the unit test cases
return build_opts, args, opts, parser
Expand Down
7 changes: 7 additions & 0 deletions tests/test_builder_containerbuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,9 @@ def _mock_osbs(self, koji_build_id, src, koji_task_id, orchestrator=False, sourc
if not create_build_args.get('signing_intent'):
create_build_args.pop('signing_intent', None)

if not create_build_args.get('userdata'):
create_build_args.pop('userdata', None)

skip_build = True
if not create_build_args.get('skip_build'):
create_build_args.pop('skip_build', None)
Expand Down Expand Up @@ -987,6 +990,8 @@ def test_private_branch(self, tmpdir):
{'skip_build': False},
{'triggered_after_koji_task': 12345},
{'triggered_after_koji_task': 0},
{'userdata': {'custom': 'userdata'}},
{'userdata': {}},
))
def test_additional_args(self, tmpdir, log_upload_raises, orchestrator, additional_args):
koji_task_id = 123
Expand Down Expand Up @@ -1059,6 +1064,8 @@ def test_additional_args(self, tmpdir, log_upload_raises, orchestrator, addition
{'signing_intent': 'some intent', 'koji_build_nvr': 'build_nvr'},
{'signing_intent': 'some intent', 'koji_build_nvr': 'build_nvr', 'koji_build_id': 12345},
{'koji_build_nvr': 'build_nvr', 'koji_build_id': 12345},
{'userdata': {'custom': 'userdata'}, 'koji_build_id': 12345},
{'userdata': {}, 'koji_build_id': 12345},
))
def test_additional_args_source(self, log_upload_raises, additional_args):
koji_task_id = 123
Expand Down
8 changes: 7 additions & 1 deletion tests/test_cli_containerbuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,9 @@ def test_cli_container_args(self, tmpdir, scratch, wait, quiet,
(None, 12345, 'build_nvr'),
(True, 12345, 'build_nvr'),
))
@pytest.mark.parametrize('userdata', [None, {'custom': 'userdata'}])
def test_cli_source_args(self, wait, quiet, channel_override,
signing_intent, scratch, koji_build_id, koji_build_nvr):
signing_intent, scratch, koji_build_id, koji_build_nvr, userdata):
options = flexmock(allowed_scms='pkgs.example.com:/*:no')
options.quiet = False
test_args = ['test']
Expand Down Expand Up @@ -353,6 +354,11 @@ def test_cli_source_args(self, wait, quiet, channel_override,
test_args.append(signing_intent)
expected_opts['signing_intent'] = signing_intent

if userdata:
test_args.append('--userdata')
test_args.append(json.dumps(userdata))
expected_opts['userdata'] = userdata

build_opts, parsed_args, opts, _ = parse_source_arguments(options, test_args)
expected_quiet = quiet or options.quiet
expected_channel = channel_override or 'container'
Expand Down

0 comments on commit d6e1bec

Please sign in to comment.