#2831 Add wait/nowait to tag-build, image-build-indirection
Merged a year ago by tkopecek. Opened a year ago by jcupova.
jcupova/koji issue-2522  into  master

file modified
+47 -42
@@ -557,8 +557,9 @@ 

      "[build] Build one or more packages from source"

      usage = _("usage: %prog chain-build [options] <target> <URL> [<URL> [:] <URL> [:] <URL> ...]")

      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 @@ 

      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 @@ 

                        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 @@ 

      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 @@ 

      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 @@ 

      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 @@ 

                        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 @@ 

      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 @@ 

      """[build] Retry a canceled or failed task, using the same parameter as the original task."""

      usage = _("usage: %prog resubmit [options] <task_id>")

      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 @@ 

      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 @@ 

                        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 @@ 

      usage = _("usage: %prog tag-build [options] <tag> <pkg> [<pkg> ...]")

      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 @@ 

          # 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 @@ 

      usage = _("usage: %prog move-build [options] <tag1> <tag2> <pkg> [<pkg> ...]")

      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, <pkg>'s are package names"))

      (options, args) = parser.parse_args(args)
@@ -6737,9 +6739,7 @@ 

              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 @@ 

      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 @@ 

      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 @@ 

      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 @@ 

      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 @@ 

                               '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 @@ 

      }

      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)

@@ -9,6 +9,7 @@ 

  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 @@ 

  

  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 @@ 

  

      @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 @@ 

          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)

@@ -301,6 +301,8 @@ 

    --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)

@@ -342,7 +342,9 @@ 

    --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)

@@ -147,7 +147,7 @@ 

              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 @@ 

    --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))

  

@@ -12,7 +12,7 @@ 

  

  EMPTY_BUILD_OPTS = {

      'specfile': None,

-     'nowait': None,

+     'wait': None,

      'patches': None,

      'envs': [],

      'scratch': None,
@@ -215,6 +215,7 @@ 

                          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 @@ 

      @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_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 @@ 

          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)

@@ -181,6 +181,7 @@ 

    --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))

@@ -154,7 +154,8 @@ 

  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, <pkg>'s are package names

  """ % self.progname)

  

@@ -177,6 +177,8 @@ 

  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

@@ -126,10 +126,12 @@ 

  

  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()

@@ -73,7 +73,8 @@ 

      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 @@ 

  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)

  

@@ -205,7 +205,8 @@ 

  

          # 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 @@ 

                          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)

Add wait to tag-build
Add nowait to image-build-indirection

Fixes: https://pagure.io/koji/issue/2522

rebased onto 8888a52d38d26f0778cfcd3250a639e7c976c547

a year ago

image-build-indirection - added --nowait
tag-build - added --wait

and setup:
when run in FG without specify --wait/--nowait -> it is waiting
when run in BG without specify --wait/--nowait -> it isn't waiting
when run in FG/BG with --nowait -> it isn't waiting
when run in FG/BG with --wait -> it is waiting

After this fix these two CLIs should be with the same behaviour as in the other CLIs with --wait/--nowait.

I believe this is superior to my pull request PR#2520 because it unifies the behavior for these commands. Mine simply restores one behavior on one koji subcommand.

rebased onto baf79f1

a year ago

Metadata Update from @tkopecek:
- Pull-request tagged with: testing-ready

a year ago

Metadata Update from @jobrauer:
- Pull-request tagged with: testing-done

a year ago

Commit d707608 fixes this pull-request

Pull-Request has been merged by tkopecek

a year ago