From 538d13fb379d6497d61ce8858341cba0e6d0d679 Mon Sep 17 00:00:00 2001 From: Mike McLean Date: May 24 2017 00:42:35 +0000 Subject: [PATCH 1/5] new command: clone-task --- diff --git a/cli/koji b/cli/koji index 05c3e93..88fbdf5 100755 --- a/cli/koji +++ b/cli/koji @@ -1338,6 +1338,43 @@ def handle_resubmit(options, session, args): session.logout() return watch_tasks(session, [newID], quiet=options.quiet) + +def handle_clone_task(options, session, args): + "[admin] Replicate an existing task" + usage = _("usage: %prog clone-task [options] ") + usage += _("\n(Specify the --help global option for a list of other help options)") + parser = OptionParser(usage=usage) + parser.add_option('--channel', help=_("Set the channel")) + (options, args) = parser.parse_args(args) + #parser.add_option('--scratch', action='store_true', + # help=_("Attempt to pass the scratch option to new task")) + + if len(args) < 1: + parser.error(_("Please provide a task id")) + try: + task_id = int(args[0]) + except ValueError: + parser.error(_("Invalid task id")) + activate_session(session) + taskinfo = session.getTaskInfo(task_id, request=True) + if not taskinfo: + print(_("No such task: %s") % task_id) + return 1 + print "Replicating task %i: %s" % (task_id, koji.taskLabel(taskinfo)) + method = taskinfo['method'] + req = taskinfo['request'] + # TODO: handle --scratch + taskopts = {} + if options.channel: + chan = session.getChannel(options.channel) + if not chan: + print(_("No such channel")) + return 1 + taskopts['channel'] = chan['id'] + new_task = session.makeTask(method , req, **taskopts) + watch_tasks(session, [new_task]) + + def handle_call(options, session, args): "Execute an arbitrary XML-RPC call" usage = _("usage: %prog call [options] name [arg...]") From 6c8ec1967220a966f2eee73ab5d968b74f7bbe4b Mon Sep 17 00:00:00 2001 From: Mike McLean Date: May 24 2017 00:58:15 +0000 Subject: [PATCH 2/5] clone-task --scratch --- diff --git a/cli/koji b/cli/koji index 88fbdf5..7be9917 100755 --- a/cli/koji +++ b/cli/koji @@ -1345,9 +1345,9 @@ def handle_clone_task(options, session, args): usage += _("\n(Specify the --help global option for a list of other help options)") parser = OptionParser(usage=usage) parser.add_option('--channel', help=_("Set the channel")) + parser.add_option('--scratch', action='store_true', + help=_("Attempt to pass the scratch option to new task")) (options, args) = parser.parse_args(args) - #parser.add_option('--scratch', action='store_true', - # help=_("Attempt to pass the scratch option to new task")) if len(args) < 1: parser.error(_("Please provide a task id")) @@ -1363,7 +1363,6 @@ def handle_clone_task(options, session, args): print "Replicating task %i: %s" % (task_id, koji.taskLabel(taskinfo)) method = taskinfo['method'] req = taskinfo['request'] - # TODO: handle --scratch taskopts = {} if options.channel: chan = session.getChannel(options.channel) @@ -1371,6 +1370,32 @@ def handle_clone_task(options, session, args): print(_("No such channel")) return 1 taskopts['channel'] = chan['id'] + if options.scratch: + # not applicable to all tasks, but we will try + if method == 'image': + if len(req) == 5: + # no opts specified + req.append({'scratch':True}) + elif len(req) == 6: + opts = req[5] or {} + opts['scratch'] = True + req[5] = opts + else: + print(_("Cannot add scratch option")) + return 1 + elif method in ['build', 'maven', 'chainbuild']: + if len(req) != 3: + print(_("Cannot add scratch option")) + return 1 + opts = req[2] or {} + opts['scratch'] = True + req[2] = opts + elif method == 'indirectionimage': + if len(req) != 1: + print(_("Cannot add scratch option")) + return 1 + req[0]['scratch'] = True + new_task = session.makeTask(method , req, **taskopts) watch_tasks(session, [new_task]) From 49af11602846f7a39bf8bec6a2476d8325d6f397 Mon Sep 17 00:00:00 2001 From: Mike McLean Date: May 24 2017 01:06:11 +0000 Subject: [PATCH 3/5] error if we don't know how to do --scratch for a method --- diff --git a/cli/koji b/cli/koji index 7be9917..723efa8 100755 --- a/cli/koji +++ b/cli/koji @@ -1395,6 +1395,9 @@ def handle_clone_task(options, session, args): print(_("Cannot add scratch option")) return 1 req[0]['scratch'] = True + else: + print(_("Cannot add scratch option")) + return 1 new_task = session.makeTask(method , req, **taskopts) watch_tasks(session, [new_task]) From 2328bc2a81382b4837450e2c465f872eb210abe6 Mon Sep 17 00:00:00 2001 From: Mike McLean Date: May 24 2017 01:18:54 +0000 Subject: [PATCH 4/5] add clone-task command in unit test data --- diff --git a/tests/test_cli/data/list-commands-admin.txt b/tests/test_cli/data/list-commands-admin.txt index 68114a3..bc35317 100644 --- a/tests/test_cli/data/list-commands-admin.txt +++ b/tests/test_cli/data/list-commands-admin.txt @@ -18,6 +18,7 @@ admin commands: block-group-req Block a group's requirement listing block-pkg Block a package in the listing for tag clone-tag Duplicate the contents of one tag onto another tag + clone-task Replicate an existing task disable-host Mark one or more hosts as disabled disable-user Disable logins by a user edit-external-repo Edit data for an external repo diff --git a/tests/test_cli/data/list-commands.txt b/tests/test_cli/data/list-commands.txt index 5db98c4..809de4f 100644 --- a/tests/test_cli/data/list-commands.txt +++ b/tests/test_cli/data/list-commands.txt @@ -18,6 +18,7 @@ admin commands: block-group-req Block a group's requirement listing block-pkg Block a package in the listing for tag clone-tag Duplicate the contents of one tag onto another tag + clone-task Replicate an existing task disable-host Mark one or more hosts as disabled disable-user Disable logins by a user edit-external-repo Edit data for an external repo From cdee54045088c269cd8b5f2f6f4e4c5fb5be2870 Mon Sep 17 00:00:00 2001 From: Mike McLean Date: Aug 07 2017 16:41:12 +0000 Subject: [PATCH 5/5] clone-task: arch override --- diff --git a/cli/koji b/cli/koji index 723efa8..91a13ca 100755 --- a/cli/koji +++ b/cli/koji @@ -1345,6 +1345,7 @@ def handle_clone_task(options, session, args): usage += _("\n(Specify the --help global option for a list of other help options)") parser = OptionParser(usage=usage) parser.add_option('--channel', help=_("Set the channel")) + parser.add_option('--arch', help=_("Override the arch")) parser.add_option('--scratch', action='store_true', help=_("Attempt to pass the scratch option to new task")) (options, args) = parser.parse_args(args) @@ -1370,6 +1371,11 @@ def handle_clone_task(options, session, args): print(_("No such channel")) return 1 taskopts['channel'] = chan['id'] + else: + # use original channel + taskopts['channel'] = taskinfo['channel_id'] + if options.arch: + taskopts['arch'] = options.arch if options.scratch: # not applicable to all tasks, but we will try if method == 'image':