From 310151cf93fe97b118746cacfdbe99deeef84150 Mon Sep 17 00:00:00 2001 From: Xibo Ning Date: Sep 12 2016 09:57:30 +0000 Subject: [PATCH 1/3] Expose assignTask via CLI --- diff --git a/cli/koji b/cli/koji index 9cfae79..2a7ba7e 100755 --- a/cli/koji +++ b/cli/koji @@ -559,6 +559,45 @@ def handle_add_group(options, session, args): session.groupListAdd(tag, group) +def handle_assign_task(options, session, args): + "[admin] Assign a task to a host" + usage = _('usage: %prog assign-task task_id hostname') + usage += _('\n(Specify the --help global option for a list of other help options)') + parser = OptionParser(usage=usage) + parser.add_option('-f', '--force', action='store_true', default=False, + help=_('force to assign a non-free task')) + (options, args) = parser.parse_args(args) + + if len(args) != 2: + parser.error(_('please specify a task id and a hostname')) + else: + task_id = int(args[0]) + hostname = args[1] + + taskinfo = session.getTaskInfo(task_id, request=False) + if taskinfo is None: + raise koji.GenericError, "No such task: %s" % task_id + + hostinfo = session.getHost(hostname) + if hostinfo is None: + raise koji.GenericError, "No such host: %s" % hostname + + force = False + if options.force: + force = True + + activate_session(session) + if not session.hasPerm('admin'): + print "This action requires admin privileges" + return 1 + + ret = session.assignTask(task_id, hostname, force) + if ret: + print 'assigned task %d to host %s' % (task_id, hostname) + else: + print 'failed to assign task %d to host %s' %s (task_id, hostname) + + def handle_add_host(options, session, args): "[admin] Add a host" usage = _("usage: %prog add-host [options] hostname arch [arch2 ...]") From c8e0ae4cf9c8480db977f82324313a8f97449913 Mon Sep 17 00:00:00 2001 From: Tomas Kopecek Date: Sep 15 2016 09:08:08 +0000 Subject: [PATCH 2/3] Update cli tests for assign-task command --- diff --git a/tests/test_cli/data/list-commands-admin.txt b/tests/test_cli/data/list-commands-admin.txt index f6f7db2..a6bb710 100644 --- a/tests/test_cli/data/list-commands-admin.txt +++ b/tests/test_cli/data/list-commands-admin.txt @@ -13,6 +13,7 @@ admin commands: add-target Create a new build target add-user Add a user add-volume Add a new storage volume + assign-task Assign a task to a host block-group-pkg Block a package from a group's package listing block-group-req Block a group's requirement listing block-pkg Block a package in the listing for tag diff --git a/tests/test_cli/data/list-commands.txt b/tests/test_cli/data/list-commands.txt index d2b991f..177849a 100644 --- a/tests/test_cli/data/list-commands.txt +++ b/tests/test_cli/data/list-commands.txt @@ -13,6 +13,7 @@ admin commands: add-target Create a new build target add-user Add a user add-volume Add a new storage volume + assign-task Assign a task to a host block-group-pkg Block a package from a group's package listing block-group-req Block a group's requirement listing block-pkg Block a package in the listing for tag From 8a7d33687e5be966bed3bcde31075a30cbdd80ef Mon Sep 17 00:00:00 2001 From: xning Date: Sep 18 2016 06:41:24 +0000 Subject: [PATCH 3/3] Merge pull request #1 from tkopecek/issue668-patch1 Update cli tests for assign-task command --- diff --git a/tests/test_cli/data/list-commands-admin.txt b/tests/test_cli/data/list-commands-admin.txt index f6f7db2..a6bb710 100644 --- a/tests/test_cli/data/list-commands-admin.txt +++ b/tests/test_cli/data/list-commands-admin.txt @@ -13,6 +13,7 @@ admin commands: add-target Create a new build target add-user Add a user add-volume Add a new storage volume + assign-task Assign a task to a host block-group-pkg Block a package from a group's package listing block-group-req Block a group's requirement listing block-pkg Block a package in the listing for tag diff --git a/tests/test_cli/data/list-commands.txt b/tests/test_cli/data/list-commands.txt index d2b991f..177849a 100644 --- a/tests/test_cli/data/list-commands.txt +++ b/tests/test_cli/data/list-commands.txt @@ -13,6 +13,7 @@ admin commands: add-target Create a new build target add-user Add a user add-volume Add a new storage volume + assign-task Assign a task to a host block-group-pkg Block a package from a group's package listing block-group-req Block a group's requirement listing block-pkg Block a package in the listing for tag