From baf79f10e441a8cccaa06e05c77a74aba4370395 Mon Sep 17 00:00:00 2001 From: Jana Cupova Date: Apr 28 2021 10:53:26 +0000 Subject: Consistent wait/nowait in all related functions Fixes: https://pagure.io/koji/issue/2522 --- diff --git a/cli/koji_cli/commands.py b/cli/koji_cli/commands.py index ba871d6..30efc7d 100644 --- a/cli/koji_cli/commands.py +++ b/cli/koji_cli/commands.py @@ -557,8 +557,9 @@ def handle_chain_build(options, session, args): "[build] Build one or more packages from source" usage = _("usage: %prog chain-build [options] [ [:] [:] ...]") parser = OptionParser(usage=get_usage_str(usage)) - parser.add_option("--nowait", action="store_true", - help=_("Don't wait on build")) + parser.add_option("--wait", action="store_true", + help=_("Wait on build, even if running in the background")) + parser.add_option("--nowait", action="store_false", dest="wait", help=_("Don't wait on build")) parser.add_option("--quiet", action="store_true", help=_("Do not print the task information"), default=options.quiet) parser.add_option("--background", action="store_true", @@ -619,9 +620,7 @@ def handle_chain_build(options, session, args): if not build_opts.quiet: print("Created task: %d" % task_id) print("Task info: %s/taskinfo?taskID=%s" % (options.weburl, task_id)) - if _running_in_bg() or build_opts.nowait: - return - else: + if build_opts.wait or (build_opts.wait is None and not _running_in_bg()): session.logout() return watch_tasks(session, [task_id], quiet=build_opts.quiet, poll_interval=options.poll_interval, topurl=options.topurl) @@ -669,8 +668,9 @@ def handle_maven_build(options, session, args): help=_("Do not attempt to tag package")) parser.add_option("--scratch", action="store_true", help=_("Perform a scratch build")) - parser.add_option("--nowait", action="store_true", - help=_("Don't wait on build")) + parser.add_option("--wait", action="store_true", + help=_("Wait on build, even if running in the background")) + parser.add_option("--nowait", action="store_false", dest="wait", help=_("Don't wait on build")) parser.add_option("--quiet", action="store_true", help=_("Do not print the task information"), default=options.quiet) parser.add_option("--background", action="store_true", @@ -720,9 +720,7 @@ def handle_maven_build(options, session, args): if not build_opts.quiet: print("Created task: %d" % task_id) print("Task info: %s/taskinfo?taskID=%s" % (options.weburl, task_id)) - if _running_in_bg() or build_opts.nowait: - return - else: + if build_opts.wait or (build_opts.wait is None and not _running_in_bg()): session.logout() return watch_tasks(session, [task_id], quiet=build_opts.quiet, poll_interval=options.poll_interval, topurl=options.topurl) @@ -742,7 +740,9 @@ def handle_wrapper_rpm(options, session, args): parser.add_option("--skip-tag", action="store_true", help=_("If creating a new build, don't tag it")) parser.add_option("--scratch", action="store_true", help=_("Perform a scratch build")) - parser.add_option("--nowait", action="store_true", help=_("Don't wait on build")) + parser.add_option("--wait", action="store_true", + help=_("Wait on build, even if running in the background")) + parser.add_option("--nowait", action="store_false", dest="wait", help=_("Don't wait on build")) parser.add_option("--background", action="store_true", help=_("Run the build at a lower priority")) @@ -792,9 +792,7 @@ def handle_wrapper_rpm(options, session, args): task_id = session.wrapperRPM(build_id, url, target, priority, opts=opts) print("Created task: %d" % task_id) print("Task info: %s/taskinfo?taskID=%s" % (options.weburl, task_id)) - if _running_in_bg() or build_opts.nowait: - return - else: + if build_opts.wait or (build_opts.wait is None and not _running_in_bg()): session.logout() return watch_tasks(session, [task_id], quiet=options.quiet, poll_interval=options.poll_interval, topurl=options.topurl) @@ -812,8 +810,9 @@ def handle_maven_chain(options, session, args): help=_("Run Maven build in debug mode")) parser.add_option("--force", action="store_true", help=_("Force rebuilds of all packages")) - parser.add_option("--nowait", action="store_true", - help=_("Don't wait on build")) + parser.add_option("--wait", action="store_true", + help=_("Wait on build, even if running in the background")) + parser.add_option("--nowait", action="store_false", dest="wait", help=_("Don't wait on build")) parser.add_option("--background", action="store_true", help=_("Run the build at a lower priority")) (build_opts, args) = parser.parse_args(args) @@ -844,9 +843,7 @@ def handle_maven_chain(options, session, args): task_id = session.chainMaven(builds, target, opts, priority=priority) print("Created task: %d" % task_id) print("Task info: %s/taskinfo?taskID=%s" % (options.weburl, task_id)) - if _running_in_bg() or build_opts.nowait: - return - else: + if build_opts.wait or (build_opts.wait is None and not _running_in_bg()): session.logout() return watch_tasks(session, [task_id], quiet=options.quiet, poll_interval=options.poll_interval, topurl=options.topurl) @@ -856,7 +853,9 @@ def handle_resubmit(goptions, session, args): """[build] Retry a canceled or failed task, using the same parameter as the original task.""" usage = _("usage: %prog resubmit [options] ") parser = OptionParser(usage=get_usage_str(usage)) - parser.add_option("--nowait", action="store_true", help=_("Don't wait on task")) + parser.add_option("--wait", action="store_true", + help=_("Wait on task, even if running in the background")) + parser.add_option("--nowait", action="store_false", dest="wait", help=_("Don't wait on task")) parser.add_option("--nowatch", action="store_true", dest="nowait", help=_("An alias for --nowait")) parser.add_option("--quiet", action="store_true", default=goptions.quiet, @@ -872,9 +871,7 @@ def handle_resubmit(goptions, session, args): newID = session.resubmitTask(taskID) if not options.quiet: print("Resubmitted task %s as new task %s" % (taskID, newID)) - if _running_in_bg() or options.nowait: - return - else: + if options.wait or (options.wait is None and not _running_in_bg()): session.logout() return watch_tasks(session, [newID], quiet=options.quiet, poll_interval=goptions.poll_interval, topurl=goptions.topurl) @@ -5903,6 +5900,8 @@ def handle_image_build_indirection(options, session, args): help=_("Create a scratch image")) parser.add_option("--wait", action="store_true", help=_("Wait on the image creation, even if running in the background")) + parser.add_option("--nowait", action="store_false", dest="wait", + help=_("Do not wait on the image creation")) parser.add_option("--noprogress", action="store_true", help=_("Do not display progress of the upload")) @@ -6673,7 +6672,9 @@ def handle_tag_build(opts, session, args): usage = _("usage: %prog tag-build [options] [ ...]") parser = OptionParser(usage=get_usage_str(usage)) parser.add_option("--force", action="store_true", help=_("force operation")) - parser.add_option("--nowait", action="store_true", help=_("Do not wait on task")) + parser.add_option("--wait", action="store_true", + help=_("Wait on task, even if running in the background")) + parser.add_option("--nowait", action="store_false", dest="wait", help=_("Do not wait on task")) (options, args) = parser.parse_args(args) if len(args) < 2: parser.error( @@ -6686,9 +6687,7 @@ def handle_tag_build(opts, session, args): # XXX - wait on task tasks.append(task_id) print("Created task %d" % task_id) - if _running_in_bg() or options.nowait: - return - else: + if options.wait or (options.wait is None and not _running_in_bg()): session.logout() return watch_tasks(session, tasks, quiet=opts.quiet, poll_interval=opts.poll_interval, topurl=opts.topurl) @@ -6699,7 +6698,10 @@ def handle_move_build(opts, session, args): usage = _("usage: %prog move-build [options] [ ...]") parser = OptionParser(usage=get_usage_str(usage)) parser.add_option("--force", action="store_true", help=_("force operation")) - parser.add_option("--nowait", action="store_true", help=_("do not wait on tasks")) + parser.add_option("--wait", action="store_true", + help=_("Wait on tasks, even if running in the background")) + parser.add_option("--nowait", action="store_false", dest="wait", + help=_("Do not wait on tasks")) parser.add_option("--all", action="store_true", help=_("move all instances of a package, 's are package names")) (options, args) = parser.parse_args(args) @@ -6737,9 +6739,7 @@ def handle_move_build(opts, session, args): task_id = session.moveBuild(args[0], args[1], build['id'], options.force) tasks.append(task_id) print("Created task %d, moving %s" % (task_id, koji.buildLabel(build))) - if _running_in_bg() or options.nowait: - return - else: + if options.wait or (options.wait is None and not _running_in_bg()): session.logout() return watch_tasks(session, tasks, quiet=opts.quiet, poll_interval=opts.poll_interval, topurl=opts.topurl) @@ -7079,7 +7079,10 @@ def anon_handle_download_task(options, session, args): parser.add_option("--noprogress", action="store_true", help=_("Do not display progress meter")) parser.add_option("--wait", action="store_true", - help=_("Wait for running tasks to finish")) + help=_("Wait for running tasks to finish, " + "even if running in the background")) + parser.add_option("--nowait", action="store_false", dest="wait", + help=_("Do not wait for running tasks to finish")) parser.add_option("-q", "--quiet", action="store_true", help=_("Suppress output"), default=options.quiet) @@ -7101,7 +7104,8 @@ def anon_handle_download_task(options, session, args): if not base_task: error(_('No such task: %d') % base_task_id) - if suboptions.wait and base_task['state'] not in ( + if (suboptions.wait or (suboptions.wait is None and not _running_in_bg())) and \ + base_task['state'] not in ( koji.TASK_STATES['CLOSED'], koji.TASK_STATES['CANCELED'], koji.TASK_STATES['FAILED']): @@ -7264,7 +7268,10 @@ def handle_regen_repo(options, session, args): parser = OptionParser(usage=get_usage_str(usage)) parser.add_option("--target", action="store_true", help=_("Interpret the argument as a build target name")) - parser.add_option("--nowait", action="store_true", help=_("Don't wait on for regen to finish")) + parser.add_option("--wait", action="store_true", + help=_("Wait on for regen to finish, even if running in the background")) + parser.add_option("--nowait", action="store_false", dest="wait", + help=_("Don't wait on for regen to finish")) parser.add_option("--debuginfo", action="store_true", help=_("Include debuginfo rpms in repo")) parser.add_option("--source", "--src", action="store_true", help=_("Include source rpms in each of repos")) @@ -7307,9 +7314,7 @@ def handle_regen_repo(options, session, args): print("Regenerating repo for tag: %s" % tag) print("Created task: %d" % task_id) print("Task info: %s/taskinfo?taskID=%s" % (options.weburl, task_id)) - if _running_in_bg() or suboptions.nowait: - return - else: + if suboptions.wait or (suboptions.wait is None and not _running_in_bg()): session.logout() return watch_tasks(session, [task_id], quiet=options.quiet, poll_interval=options.poll_interval, topurl=options.topurl) @@ -7352,8 +7357,10 @@ def handle_dist_repo(options, session, args): 'config file')) parser.add_option("--noinherit", action='store_true', default=False, help=_('Do not consider tag inheritance')) - parser.add_option("--nowait", action='store_true', default=False, - help=_('Do not wait for the task to complete')) + parser.add_option("--wait", action="store_true", + help=_("Wait for the task to complete, even if running in the background")) + parser.add_option("--nowait", action="store_false", dest="wait", + help=_("Do not wait for the task to complete")) parser.add_option('--skip-missing-signatures', action='store_true', default=False, help=_('Skip RPMs not signed with the desired key(s)')) parser.add_option('--zck', action='store_true', default=False, @@ -7448,9 +7455,7 @@ def handle_dist_repo(options, session, args): } task_id = session.distRepo(tag, keys, **opts) print("Creating dist repo for tag " + tag) - if _running_in_bg() or task_opts.nowait: - return - else: + if task_opts.wait or (task_opts.wait is None and not _running_in_bg()): session.logout() return watch_tasks(session, [task_id], quiet=options.quiet, poll_interval=options.poll_interval, topurl=options.topurl) diff --git a/tests/test_cli/test_chain_build.py b/tests/test_cli/test_chain_build.py index 3e29901..d82d39f 100644 --- a/tests/test_cli/test_chain_build.py +++ b/tests/test_cli/test_chain_build.py @@ -9,6 +9,7 @@ import unittest from koji_cli.commands import handle_chain_build from . import utils + class TestChainBuild(utils.CliTestCase): # Show long diffs in error output... maxDiff = None @@ -148,6 +149,7 @@ Task info: weburl/taskinfo?taskID=1 Options: -h, --help show this help message and exit + --wait Wait on build, even if running in the background --nowait Don't wait on build --quiet Do not print the task information --background Run the build at a lower priority @@ -655,12 +657,10 @@ Task info: weburl/taskinfo?taskID=1 @mock.patch('sys.stdout', new_callable=six.StringIO) @mock.patch('koji_cli.commands.activate_session') - @mock.patch('koji_cli.commands._running_in_bg', return_value=False) @mock.patch('koji_cli.commands.watch_tasks', return_value=0) def test_handle_chain_build_nowait( self, watch_tasks_mock, - running_in_bg_mock, activate_session_mock, stdout): target = 'target' @@ -710,7 +710,6 @@ Task info: weburl/taskinfo?taskID=1 self.session.getFullInheritance.assert_called_once_with(build_tag_id) self.session.chainBuild.assert_called_once_with( sources, target, priority=priority) - running_in_bg_mock.assert_called_once() self.session.logout.assert_not_called() watch_tasks_mock.assert_not_called() self.assertIsNone(rv) diff --git a/tests/test_cli/test_dist_repo.py b/tests/test_cli/test_dist_repo.py index b1dd87d..be3baad 100644 --- a/tests/test_cli/test_dist_repo.py +++ b/tests/test_cli/test_dist_repo.py @@ -301,6 +301,8 @@ Options: --multilib=CONFIG Include multilib packages in the repository using the given config file --noinherit Do not consider tag inheritance + --wait Wait for the task to complete, even if running in the + background --nowait Do not wait for the task to complete --skip-missing-signatures Skip RPMs not signed with the desired key(s) diff --git a/tests/test_cli/test_download_task.py b/tests/test_cli/test_download_task.py index 382c350..e4d0362 100644 --- a/tests/test_cli/test_download_task.py +++ b/tests/test_cli/test_download_task.py @@ -342,7 +342,9 @@ Options: --logs Also download build logs --topurl=URL URL under which Koji files are accessible --noprogress Do not display progress meter - --wait Wait for running tasks to finish + --wait Wait for running tasks to finish, even if running in the + background + --nowait Do not wait for running tasks to finish -q, --quiet Suppress output """ % progname self.assertMultiLineEqual(actual, expected) diff --git a/tests/test_cli/test_image_build_indirection.py b/tests/test_cli/test_image_build_indirection.py index d00c7ba..89a12cb 100644 --- a/tests/test_cli/test_image_build_indirection.py +++ b/tests/test_cli/test_image_build_indirection.py @@ -147,7 +147,7 @@ class TestBuildImageIndirection(utils.CliTestCase): expected = "Missing the following required options: " expected += "--" + r.replace('_', '-') + "\n" with self.assertRaises(koji.GenericError) as cm: - with mock.patch('sys.stdout', new_callable=six.StringIO) as stdout: + with mock.patch('sys.stdout', new_callable=six.StringIO) as stdout: _build_image_indirection( self.options, self.task_opts, self.session, []) self.assert_console_message(stdout, expected) @@ -255,6 +255,7 @@ Options: --scratch Create a scratch image --wait Wait on the image creation, even if running in the background + --nowait Do not wait on the image creation --noprogress Do not display progress of the upload """ % (self.progname, self.progname)) diff --git a/tests/test_cli/test_maven_build.py b/tests/test_cli/test_maven_build.py index c89adbe..840b35f 100644 --- a/tests/test_cli/test_maven_build.py +++ b/tests/test_cli/test_maven_build.py @@ -12,7 +12,7 @@ from . import utils EMPTY_BUILD_OPTS = { 'specfile': None, - 'nowait': None, + 'wait': None, 'patches': None, 'envs': [], 'scratch': None, @@ -215,6 +215,7 @@ Options: wrapper RPMs --skip-tag Do not attempt to tag package --scratch Perform a scratch build + --wait Wait on build, even if running in the background --nowait Don't wait on build --quiet Do not print the task information --background Run the build at a lower priority @@ -726,12 +727,10 @@ Task info: weburl/taskinfo?taskID=1 @mock.patch('koji_cli.commands.activate_session') @mock.patch('koji.util.parse_maven_param') @mock.patch('koji.util.maven_opts', return_value={}) - @mock.patch('koji_cli.commands._running_in_bg', return_value=False) @mock.patch('koji_cli.commands.watch_tasks', return_value=0) def test_handle_maven_build_nowait( self, watch_tasks_mock, - running_in_bg_mock, maven_opts_mock, parse_maven_param_mock, activate_session_mock, @@ -745,7 +744,7 @@ Task info: weburl/taskinfo?taskID=1 task_id = 1 args = ['--nowait', target, source] build_opts = EMPTY_BUILD_OPTS.copy() - build_opts['nowait'] = True + build_opts['wait'] = False opts = {} priority = None scratch = None @@ -770,7 +769,6 @@ Task info: weburl/taskinfo?taskID=1 maven_opts_mock.assert_called_once_with(build_opts, scratch=scratch) self.session.mavenBuild.assert_called_once_with( source, target, opts, priority=priority) - running_in_bg_mock.assert_called_once() self.session.logout.assert_not_called() watch_tasks_mock.assert_not_called() self.assertIsNone(rv) diff --git a/tests/test_cli/test_maven_chain.py b/tests/test_cli/test_maven_chain.py index fab8fe8..b87078f 100644 --- a/tests/test_cli/test_maven_chain.py +++ b/tests/test_cli/test_maven_chain.py @@ -181,6 +181,7 @@ Options: --scratch Perform scratch builds --debug Run Maven build in debug mode --force Force rebuilds of all packages + --wait Wait on build, even if running in the background --nowait Don't wait on build --background Run the build at a lower priority """ % (self.progname)) diff --git a/tests/test_cli/test_move_build.py b/tests/test_cli/test_move_build.py index 28861cd..c836edb 100644 --- a/tests/test_cli/test_move_build.py +++ b/tests/test_cli/test_move_build.py @@ -154,7 +154,8 @@ class TestMoveBuild(utils.CliTestCase): Options: -h, --help show this help message and exit --force force operation - --nowait do not wait on tasks + --wait Wait on tasks, even if running in the background + --nowait Do not wait on tasks --all move all instances of a package, 's are package names """ % self.progname) diff --git a/tests/test_cli/test_regen_repo.py b/tests/test_cli/test_regen_repo.py index 59c318e..e2beffc 100644 --- a/tests/test_cli/test_regen_repo.py +++ b/tests/test_cli/test_regen_repo.py @@ -177,6 +177,8 @@ class TestRegenRepo(utils.CliTestCase): Options: -h, --help show this help message and exit --target Interpret the argument as a build target name + --wait Wait on for regen to finish, even if running in the + background --nowait Don't wait on for regen to finish --debuginfo Include debuginfo rpms in repo --source, --src Include source rpms in each of repos diff --git a/tests/test_cli/test_resubmit.py b/tests/test_cli/test_resubmit.py index 4a9d9d0..75a6222 100644 --- a/tests/test_cli/test_resubmit.py +++ b/tests/test_cli/test_resubmit.py @@ -126,10 +126,12 @@ Log Files: Options: -h, --help show this help message and exit + --wait Wait on task, even if running in the background --nowait Don't wait on task --nowatch An alias for --nowait --quiet Do not print the task information """ % self.progname) + if __name__ == '__main__': unittest.main() diff --git a/tests/test_cli/test_tag_build.py b/tests/test_cli/test_tag_build.py index c991663..f7efef0 100644 --- a/tests/test_cli/test_tag_build.py +++ b/tests/test_cli/test_tag_build.py @@ -73,7 +73,8 @@ class TestTagBuild(utils.CliTestCase): def test_handle_tag_build_argument_error(self): """Test handle_tag_build function with error argument""" expected = self.format_error_message( - "This command takes at least two arguments: a tag name/ID and one or more package n-v-r's") + "This command takes at least two arguments: a tag name/ID and one or " + "more package n-v-r's") for arg in [[], ['tag']]: self.assert_system_exit( handle_tag_build, @@ -92,6 +93,7 @@ class TestTagBuild(utils.CliTestCase): Options: -h, --help show this help message and exit --force force operation + --wait Wait on task, even if running in the background --nowait Do not wait on task """ % self.progname) diff --git a/tests/test_cli/test_wrapper_rpm.py b/tests/test_cli/test_wrapper_rpm.py index 2129d13..bb40cb2 100644 --- a/tests/test_cli/test_wrapper_rpm.py +++ b/tests/test_cli/test_wrapper_rpm.py @@ -205,7 +205,8 @@ class TestWrapperRpm(utils.CliTestCase): # Run it and check immediate output expected = self.format_error_message( - "You must provide a build target, a build ID or NVR, and a SCM URL to a specfile fragment") + "You must provide a build target, a build ID or NVR, and a SCM URL to " + "a specfile fragment") self.assert_system_exit( handle_wrapper_rpm, options, @@ -233,6 +234,7 @@ Options: Get build parameters from this section of the .ini --skip-tag If creating a new build, don't tag it --scratch Perform a scratch build + --wait Wait on build, even if running in the background --nowait Don't wait on build --background Run the build at a lower priority """ % self.progname)