#1869 limit distRepo tasks per tag
Merged 4 years ago by tkopecek. Opened 4 years ago by tkopecek.
tkopecek/koji issue1630  into  master

file modified
+8 -2
@@ -6952,8 +6952,14 @@ 

  

  def handle_dist_repo(options, session, args):

      """Create a yum repo with distribution options"""

-     usage = _("usage: %prog dist-repo [options] <tag> <key_id> [<key_id> ...]")

-     parser = OptionParser(usage=get_usage_str(usage))

+     usage = _("usage: %prog dist-repo [options] <tag> <key_id> [<key_id> ...]\n\n"

+               "In normal mode, dist-repo behaves like any other koji task.\n"

+               "Sometimes you want to limit running distRepo tasks per tag to only\n"

+               "one. For such behaviour admin (with 'tag' permission) needs to\n"

+               "modify given tag's extra field 'distrepo.cancel_others' to True'\n"

+               "via 'koji edit-tag -x distrepo.cancel_others=True'\n")

+     usage += _("\n(Specify the --help option for a list of other options)")

+     parser = OptionParser(usage=usage)

      parser.add_option('--allow-missing-signatures', action='store_true',

          default=False,

          help=_('For RPMs not signed with a desired key, fall back to the '

file modified
+14
@@ -11436,6 +11436,20 @@ 

          context.session.assertPerm('dist-repo')

          repo_id, event_id = dist_repo_init(tag, keys, task_opts)

          task_opts['event'] = event_id

+         # cancel potentially running distRepos

+         build_config = self.getBuildConfig(get_tag(tag, strict=True))

+         if build_config['extra'].get('distrepo.cancel_others', False):

+             tasks = self.listTasks(opts={

+                                        'state': [koji.TASK_STATES['FREE'],

+                                                  koji.TASK_STATES['OPEN'],

+                                                  koji.TASK_STATES['ASSIGNED']],

+                                        'method': 'distRepo',

+                                        'decode': True})

+             # filter only for this tag

+             task_ids = [t['id'] for t in tasks if t['request'][0] == tag]

+             for task_id in task_ids:

+                 logger.debug("Cancelling distRepo task %d" % task_id)

+                 Task(task_id).cancel(recurse=True)

          return make_task('distRepo', [tag, repo_id, keys, task_opts], priority=15, channel='createrepo')

  

      def newRepo(self, tag, event=None, src=False, debuginfo=False, separate_src=False):

@@ -45,7 +45,14 @@ 

          self.session.distRepo.return_value = self.task_id

  

          self.error_format = """Usage: %s dist-repo [options] <tag> <key_id> [<key_id> ...]

- (Specify the --help global option for a list of other help options)

+ 

+ In normal mode, dist-repo behaves like any other koji task.

+ Sometimes you want to limit running distRepo tasks per tag to only

+ one. For such behaviour admin (with 'tag' permission) needs to

+ modify given tag's extra field 'distrepo.cancel_others' to True'

+ via 'koji edit-tag -x distrepo.cancel_others=True'

+ 

+ (Specify the --help option for a list of other options)

  

  %s: error: {message}

  """ % (self.progname, self.progname)
@@ -249,7 +256,14 @@ 

          self.assert_help(

              handle_dist_repo,

              """Usage: %s dist-repo [options] <tag> <key_id> [<key_id> ...]

- (Specify the --help global option for a list of other help options)

+ 

+ In normal mode, dist-repo behaves like any other koji task.

+ Sometimes you want to limit running distRepo tasks per tag to only

+ one. For such behaviour admin (with 'tag' permission) needs to

+ modify given tag's extra field 'distrepo.cancel_others' to True'

+ via 'koji edit-tag -x distrepo.cancel_others=True'

+ 

+ (Specify the --help option for a list of other options)

  

  Options:

    -h, --help            show this help message and exit

@@ -85,22 +85,28 @@ 

  

  class TestDistRepo(unittest.TestCase):

  

+     @mock.patch('kojihub.get_tag')

      @mock.patch('kojihub.dist_repo_init')

      @mock.patch('kojihub.make_task')

-     def test_DistRepo(self, make_task, dist_repo_init):

+     def test_DistRepo(self, make_task, dist_repo_init, get_tag):

          session = kojihub.context.session = mock.MagicMock()

          # It seems MagicMock will not automatically handle attributes that

          # start with "assert"

          session.assertPerm = mock.MagicMock()

          dist_repo_init.return_value = ('repo_id', 'event_id')

          make_task.return_value = 'task_id'

- 

+         get_tag.return_value = {'id': 1, 'extra': {}}

          exports = kojihub.RootExports()

+         exports.getBuildConfig = mock.MagicMock()

+         exports.getBuildConfig.return_value = {'extra': {}}

+ 

          ret = exports.distRepo('tag', 'keys')

+ 

          session.assertPerm.assert_called_once_with('dist-repo')

          dist_repo_init.assert_called_once()

          make_task.assert_called_once()

          self.assertEquals(ret, make_task.return_value)

+         exports.getBuildConfig.assert_called_once_with(get_tag.return_value)

  

  

  class TestDistRepoMove(unittest.TestCase):
@@ -206,6 +212,7 @@ 

  

  

      def test_distRepoMove(self):

+         kojihub.context.session = mock.MagicMock()

          exports = kojihub.HostExports()

          exports.distRepoMove(self.rinfo['id'], self.uploadpath, self.arch)

          # check result

Introduces 'distrepo.cancel_others` extra flag for tags. If enabled, new
distRepo task will cancel previous non-finished ones leaving only new
one.

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

rebased onto ad251dd7ed7d9937517856afc0430f635fe93fe2

4 years ago

rebased onto 711683a945d38b2ef68aad7e08224877a613d78f

4 years ago

should extra follow inheritance like build tasks?

1 new commit added

  • use inherited data instead of top-level settings
4 years ago

rebased onto a8ac931

4 years ago

pretty please pagure-ci rebuild

4 years ago

pretty please pagure-ci rebuild

4 years ago

1 new commit added

  • use getBuildConfig
4 years ago

Previous commit got lost somehow. I've pushed it again.

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

4 years ago

Commit 74f525a fixes this pull-request

Pull-Request has been merged by tkopecek

4 years ago

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

4 years ago