permissions
This commit is contained in:
parent
1a06b1b52e
commit
7b8fcd989f
3 changed files with 39 additions and 22 deletions
25
cli/koji
25
cli/koji
|
|
@ -7229,15 +7229,22 @@ def handle_save_failed_tree(options, session, args):
|
|||
try:
|
||||
task_id = session.saveFailedTree(taskID, opts.full)
|
||||
except koji.GenericError as e:
|
||||
if 'Invalid method' in str(e):
|
||||
print "* The save_failed_tree plugin appears to not be installed" \
|
||||
" on the koji hub. Please contact the administrator."
|
||||
raise
|
||||
|
||||
if type(task_id) != int:
|
||||
print 'Error: %s' % task_id
|
||||
return
|
||||
|
||||
m = str(e)
|
||||
if 'Only failed tasks can upload their buildroots.' in m:
|
||||
print _("Only failed tasks can upload their buildroots.")
|
||||
elif 'tasks can upload their buildroots (Task' in m:
|
||||
print _("Task of this type has disabled support for uploading" \
|
||||
" buildroot. (configurable on hub)")
|
||||
elif 'Invalid method' in m:
|
||||
print _("* The save_failed_tree plugin appears to not be installed" \
|
||||
" on the koji hub. Please contact the administrator.")
|
||||
if logger.isEnabledFor(logging.DEBUG):
|
||||
tb_str = ''.join(traceback.format_exception(*sys.exc_info()))
|
||||
logger.debug(tb_str)
|
||||
return 1
|
||||
except koji.ActionNotAllowed:
|
||||
print _("Only task owner or admin can run this task.")
|
||||
return 1
|
||||
if not opts.quiet:
|
||||
print "Created task:", task_id
|
||||
print "Task info: %s/taskinfo?taskID=%s" % (options.weburl, task_id)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import sys
|
||||
import ConfigParser
|
||||
import koji
|
||||
from koji.context import context
|
||||
from koji.plugin import export
|
||||
|
||||
sys.path.insert(0, '/usr/share/koji-hub/')
|
||||
|
|
@ -34,12 +35,12 @@ def saveFailedTree(taskID, full=False, **opts):
|
|||
|
||||
task_info = kojihub.Task(taskID).getInfo()
|
||||
if task_info['state'] != koji.TASK_STATES['FAILED']:
|
||||
return 'Task %s has not failed. Only failed tasks can upload their buildroots.' % taskID
|
||||
raise koji.PreBuildError, 'Task %s has not failed. Only failed tasks can upload their buildroots.' % taskID
|
||||
elif allowed_methods != '*' and task_info['method'] not in allowed_methods:
|
||||
return 'Only %s tasks can upload their buildroots (Task %s is %s).' % \
|
||||
raise koji.PreBuildError, 'Only %s tasks can upload their buildroots (Task %s is %s).' % \
|
||||
(', '.join(allowed_methods), task_info['id'], task_info['method'])
|
||||
# owner?
|
||||
# permissions?
|
||||
elif task_info["owner"] != context.session.user_id and not context.session.assertPerm('admin'):
|
||||
raise koji.ActionNotAllowed, "only owner of failed task or 'admin' can run this task"
|
||||
|
||||
args = koji.encode_args(taskID, full, **opts)
|
||||
taskopts = {
|
||||
|
|
|
|||
|
|
@ -110,19 +110,28 @@ class TestSaveFailedTree(unittest.TestCase):
|
|||
self.parser.parse_args.return_value = [options, arguments]
|
||||
self.assertRaises(Exception, cli.handle_save_failed_tree, self.options,
|
||||
self.session, self.args)
|
||||
cli.logger = mock.MagicMock()
|
||||
|
||||
# plugin not installed
|
||||
arguments = [123]
|
||||
self.parser.parse_args.return_value = [options, arguments]
|
||||
self.session.saveFailedTree.side_effect = koji.GenericError("Invalid method")
|
||||
self.assertRaises(koji.GenericError, cli.handle_save_failed_tree,
|
||||
self.options, self.session, self.args)
|
||||
|
||||
# something wrong happened in task
|
||||
stdout.seek(0)
|
||||
stdout.truncate()
|
||||
self.session.saveFailedTree.return_value = 'xyz'
|
||||
self.session.saveFailedTree.side_effect = None
|
||||
cli.handle_save_failed_tree(self.options, self.session, self.args)
|
||||
actual = stdout.getvalue()
|
||||
self.assertEqual(actual, 'Error: xyz\n')
|
||||
self.assertTrue('The save_failed_tree plugin appears to not be installed' in actual)
|
||||
|
||||
# Task which is not FAILED
|
||||
stdout.seek(0)
|
||||
stdout.truncate()
|
||||
self.session.saveFailedTree.side_effect = koji.PreBuildError('Only failed tasks can upload their buildroots.')
|
||||
cli.handle_save_failed_tree(self.options, self.session, self.args)
|
||||
actual = stdout.getvalue()
|
||||
self.assertTrue('Only failed tasks can upload their buildroots.' in actual)
|
||||
|
||||
# Disabled/unsupported task
|
||||
stdout.seek(0)
|
||||
stdout.truncate()
|
||||
self.session.saveFailedTree.side_effect = koji.PreBuildError('tasks can upload their buildroots (Task')
|
||||
cli.handle_save_failed_tree(self.options, self.session, self.args)
|
||||
actual = stdout.getvalue()
|
||||
self.assertTrue('Task of this type has disabled support for uploading' in actual)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue