parent
c88c958f8c
commit
21427c0e2c
2 changed files with 76 additions and 2 deletions
|
|
@ -3,7 +3,8 @@ import time
|
|||
|
||||
import koji
|
||||
from koji.plugin import export_cli
|
||||
from koji_cli.lib import _, activate_session, OptionParser, list_task_output_all_volumes
|
||||
from koji_cli.lib import _, activate_session, OptionParser, watch_tasks, \
|
||||
_running_in_bg, list_task_output_all_volumes
|
||||
|
||||
@export_cli
|
||||
def handle_runroot(options, session, args):
|
||||
|
|
@ -25,11 +26,17 @@ def handle_runroot(options, session, args):
|
|||
parser.add_option("--new-chroot", action="store_true", default=False,
|
||||
help=_("Run command with the --new-chroot (systemd-nspawn) option to mock"))
|
||||
parser.add_option("--repo-id", type="int", help=_("ID of the repo to use"))
|
||||
parser.add_option("--nowait", action="store_false", dest="wait", help=_("Do not wait on task"))
|
||||
parser.add_option("--watch", action="store_true", help=_("Watch task instead of printing runroot.log"))
|
||||
parser.add_option("--quiet", action="store_true", default=options.quiet,
|
||||
help=_("Do not print the task information"))
|
||||
|
||||
(opts, args) = parser.parse_args(args)
|
||||
|
||||
if len(args) < 3:
|
||||
parser.error(_("Incorrect number of arguments"))
|
||||
return
|
||||
|
||||
activate_session(session, options)
|
||||
tag = args[0]
|
||||
arch = args[1]
|
||||
|
|
@ -59,6 +66,14 @@ def handle_runroot(options, session, args):
|
|||
if opts.task_id:
|
||||
print(task_id)
|
||||
|
||||
if not opts.wait:
|
||||
return
|
||||
|
||||
if opts.watch:
|
||||
session.logout()
|
||||
return watch_tasks(session, [task_id], quiet=opts.quiet,
|
||||
poll_interval=options.poll_interval)
|
||||
|
||||
try:
|
||||
while True:
|
||||
# wait for the task to finish
|
||||
|
|
@ -81,4 +96,3 @@ def handle_runroot(options, session, args):
|
|||
state = koji.TASK_STATES[info['state']]
|
||||
if state in ('FAILED', 'CANCELED'):
|
||||
sys.exit(1)
|
||||
return
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ class TestListCommands(unittest.TestCase):
|
|||
arguments = [tag, arch, command]
|
||||
options = mock.MagicMock()
|
||||
options.new_chroot = False
|
||||
options.watch = False
|
||||
self.parser.parse_args.return_value = [options, arguments]
|
||||
|
||||
# Mock out the xmlrpc server
|
||||
|
|
@ -54,3 +55,62 @@ class TestListCommands(unittest.TestCase):
|
|||
mounts=mock.ANY, packages=mock.ANY, skip_setarch=mock.ANY,
|
||||
channel=mock.ANY,
|
||||
)
|
||||
|
||||
def test_handle_runroot_watch(self):
|
||||
arguments = ['tag', 'arch', 'command']
|
||||
options = mock.MagicMock()
|
||||
options.new_chroot = True
|
||||
options.watch = True
|
||||
options.use_shell = False
|
||||
self.parser.parse_args.return_value = [options, arguments]
|
||||
runroot.watch_tasks = mock.MagicMock(name='watch_tasks')
|
||||
|
||||
# Mock out the xmlrpc server
|
||||
self.session.runroot.return_value = 1
|
||||
|
||||
# Run it and check immediate output
|
||||
runroot.handle_runroot(self.options, self.session, self.args)
|
||||
|
||||
# Finally, assert that things were called as we expected.
|
||||
runroot.watch_tasks.assert_called_once()
|
||||
self.session.getTaskInfo.assert_not_called()
|
||||
self.session.listTaskOutput.assert_not_called()
|
||||
self.session.downloadTaskOutput.assert_not_called()
|
||||
self.session.runroot.assert_called_once()
|
||||
|
||||
def test_invalid_arguments(self):
|
||||
arguments = ['tag', 'arch'] # just two
|
||||
options = mock.MagicMock()
|
||||
options.new_chroot = False
|
||||
options.watch = True
|
||||
options.use_shell = False
|
||||
self.parser.parse_args.return_value = [options, arguments]
|
||||
|
||||
# Run it and check immediate output
|
||||
runroot.handle_runroot(self.options, self.session, self.args)
|
||||
|
||||
# Finally, assert that things were called as we expected.
|
||||
self.session.getTaskInfo.assert_not_called()
|
||||
self.session.listTaskOutput.assert_not_called()
|
||||
self.session.downloadTaskOutput.assert_not_called()
|
||||
self.session.runroot.assert_not_called()
|
||||
|
||||
def test_nowait(self):
|
||||
arguments = ['tag', 'arch', 'command']
|
||||
options = mock.MagicMock()
|
||||
options.wait = False
|
||||
self.parser.parse_args.return_value = [options, arguments]
|
||||
runroot.watch_tasks = mock.MagicMock(name='watch_tasks')
|
||||
|
||||
# Mock out the xmlrpc server
|
||||
self.session.runroot.return_value = 1
|
||||
|
||||
# Run it and check immediate output
|
||||
runroot.handle_runroot(self.options, self.session, self.args)
|
||||
|
||||
# Finally, assert that things were called as we expected.
|
||||
runroot.watch_tasks.assert_not_called()
|
||||
self.session.getTaskInfo.assert_not_called()
|
||||
self.session.listTaskOutput.assert_not_called()
|
||||
self.session.downloadTaskOutput.assert_not_called()
|
||||
self.session.runroot.assert_called_once()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue