#2802 Repo info with task id
Merged a year ago by tkopecek. Opened a year ago by jcupova.
jcupova/koji issue888  into  master

file modified
+1 -1
@@ -5374,7 +5374,7 @@ 

          # generate debuginfo repo if requested or if specified in sidetag's extra

          if debuginfo or tinfo['extra'].get('with_debuginfo'):

              kwargs['with_debuginfo'] = True

-         repo_id, event_id = self.session.host.repoInit(tinfo['id'], **kwargs)

+         repo_id, event_id = self.session.host.repoInit(tinfo['id'], task_id=self.id, **kwargs)

          path = koji.pathinfo.repo(repo_id, tinfo['name'])

          if not os.path.isdir(path):

              raise koji.GenericError("Repo directory missing: %s" % path)

@@ -0,0 +1,9 @@ 

+ -- upgrade script to migrate the Koji database schema

+ -- from version 1.24 to 1.25

+ 

+ 

+ BEGIN;

+ 

+ ALTER TABLE repo ADD COLUMN task_id INTEGER NULL REFERENCES task(id);

+ 

+ COMMIT;

file modified
+2 -1
@@ -454,7 +454,8 @@ 

  	create_event INTEGER NOT NULL REFERENCES events(id) DEFAULT get_event(),

  	tag_id INTEGER NOT NULL REFERENCES tag(id),

  	state INTEGER,

- 	dist BOOLEAN DEFAULT 'false'

+ 	dist BOOLEAN DEFAULT 'false',

+ 	task_id INTEGER NULL REFERENCES task(id)

  ) WITHOUT OIDS;

  

  -- external yum repos

file modified
+13 -9
@@ -2521,7 +2521,8 @@ 

      return _iter_archives()

  

  

- def repo_init(tag, with_src=False, with_debuginfo=False, event=None, with_separate_src=False):

+ def repo_init(tag, task_id=None, with_src=False, with_debuginfo=False, event=None,

+               with_separate_src=False):

      """Create a new repo entry in the INIT state, return full repo data

  

      Returns a dictionary containing
@@ -2532,7 +2533,7 @@ 

      tinfo = get_tag(tag, strict=True, event=event)

      koji.plugin.run_callbacks('preRepoInit', tag=tinfo, with_src=with_src,

                                with_debuginfo=with_debuginfo, event=event, repo_id=None,

-                               with_separate_src=with_separate_src)

+                               with_separate_src=with_separate_src, task_id=task_id)

      tag_id = tinfo['id']

      repo_arches = {}

      if with_separate_src:
@@ -2552,7 +2553,7 @@ 

          event_time = _singleValue(q, locals(), strict=True)

          event_id = event

      insert = InsertProcessor('repo')

-     insert.set(id=repo_id, create_event=event_id, tag_id=tag_id, state=state)

+     insert.set(id=repo_id, create_event=event_id, tag_id=tag_id, state=state, task_id=task_id)

      insert.execute()

      # Need to pass event_id because even though this is a single transaction,

      # it is possible to see the results of other committed transactions
@@ -2578,6 +2579,7 @@ 

          'id': repo_id,

          'tag': tinfo['name'],

          'tag_id': tinfo['id'],

+         'task_id': task_id,

          'event_id': event_id,

          'with_src': with_src,

          'with_separate_src': with_separate_src,
@@ -2671,7 +2673,7 @@ 

  

      koji.plugin.run_callbacks('postRepoInit', tag=tinfo, with_src=with_src,

                                with_debuginfo=with_debuginfo, event=event, repo_id=repo_id,

-                               with_separate_src=with_separate_src)

+                               with_separate_src=with_separate_src, task_id=task_id)

      return [repo_id, event_id]

  

  
@@ -2785,6 +2787,7 @@ 

      fields = (

          ('repo.id', 'id'),

          ('repo.state', 'state'),

+         ('repo.task_id', 'task_id'),

          ('repo.create_event', 'create_event'),

          ('events.time', 'creation_time'),  # for compatibility with getRepo

          ('EXTRACT(EPOCH FROM events.time)', 'create_ts'),
@@ -2874,6 +2877,7 @@ 

      fields = (

          ('repo.id', 'id'),

          ('repo.state', 'state'),

+         ('repo.task_id', 'task_id'),

          ('repo.create_event', 'create_event'),

          ('EXTRACT(EPOCH FROM events.time)', 'create_ts'),

          ('repo.tag_id', 'tag_id'),
@@ -12116,9 +12120,9 @@ 

          else:

              id = get_tag_id(tag, strict=True)

  

-         fields = ['repo.id', 'repo.state', 'repo.create_event', 'events.time',

+         fields = ['repo.id', 'repo.state', 'repo.task_id', 'repo.create_event', 'events.time',

                    'EXTRACT(EPOCH FROM events.time)', 'repo.dist']

-         aliases = ['id', 'state', 'create_event', 'creation_time', 'create_ts', 'dist']

+         aliases = ['id', 'state', 'task_id', 'create_event', 'creation_time', 'create_ts', 'dist']

          joins = ['events ON repo.create_event = events.id']

          clauses = ['repo.tag_id = %(id)i']

          if dist:
@@ -14585,13 +14589,13 @@ 

  

          return br.updateArchiveList(archives, project)

  

-     def repoInit(self, tag, with_src=False, with_debuginfo=False, event=None,

+     def repoInit(self, tag, task_id=None, with_src=False, with_debuginfo=False, event=None,

                   with_separate_src=False):

          """Initialize a new repo for tag"""

          host = Host()

          host.verify()

-         return repo_init(tag, with_src=with_src, with_debuginfo=with_debuginfo, event=event,

-                          with_separate_src=with_separate_src)

+         return repo_init(tag, task_id=task_id, with_src=with_src, with_debuginfo=with_debuginfo,

+                          event=event, with_separate_src=with_separate_src)

  

      def repoDone(self, repo_id, data, expire=False):

          """Finalize a repo

file modified
+3 -1
@@ -282,7 +282,8 @@ 

      address = 'repo.init'

      props = {'type': cbtype[4:],

               'tag': kws['tag']['name'],

-              'repo_id': kws['repo_id']}

+              'repo_id': kws['repo_id'],

+              'task_id': kws['task_id']}

      queue_msg(address, props, kws)

  

  
@@ -293,6 +294,7 @@ 

      props = {'type': cbtype[4:],

               'tag': kws['repo']['tag_name'],

               'repo_id': kws['repo']['id'],

+              'task_id': kws['repo']['task_id'],

               'expire': kws['expire']}

      queue_msg(address, props, kws)

  

@@ -32,9 +32,10 @@ 

          # make sure the following does not error

          str(query)

          self.assertEqual(query.tables, ['repo'])

-         columns = ['repo.id', 'repo.state', 'repo.create_event',

-                    'EXTRACT(EPOCH FROM events.time)', 'repo.tag_id',

-                    'repo.dist','tag.name']

+         columns = ['repo.id', 'repo.state', 'repo.task_id', 'repo.create_event',

+                    'EXTRACT(EPOCH FROM events.time)', 'repo.tag_id', 'repo.dist', 'tag.name']

          self.assertEqual(set(query.columns), set(columns))

          self.assertEqual(query.clauses, ['repo.state != %(st_deleted)s'])

+         self.assertEqual(query.joins, ['tag ON repo.tag_id=tag.id',

+                                        'events ON repo.create_event = events.id'])

          self.assertEqual(query.values['st_deleted'], koji.REPO_DELETED)

file modified
+35 -3
@@ -1,6 +1,8 @@ 

  import mock

  

  import unittest

+ import datetime

+ import psycopg2

  

  import koji

  import kojihub
@@ -15,15 +17,16 @@ 

  

      def setUp(self):

          self.QueryProcessor = mock.patch('kojihub.QueryProcessor',

-                 side_effect=self.getQuery).start()

+                                          side_effect=self.getQuery).start()

          self.queries = []

          self.InsertProcessor = mock.patch('kojihub.InsertProcessor',

-                 side_effect=self.getInsert).start()

+                                           side_effect=self.getInsert).start()

          self.inserts = []

          self.UpdateProcessor = mock.patch('kojihub.UpdateProcessor',

-                 side_effect=self.getUpdate).start()

+                                           side_effect=self.getUpdate).start()

          self.updates = []

          self._dml = mock.patch('kojihub._dml').start()

+         self.exports = kojihub.RootExports()

  

      def tearDown(self):

          mock.patch.stopall()
@@ -74,3 +77,32 @@ 

              self.assertEqual(update.values['dist'], dist)

              if 'dist = %(dist)s' not in update.clauses:

                  raise Exception('Missing dist condition')

+ 

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

+     def test_repo_info(self, _singleRow):

+         repo_row = {'id': 10,

+                     'state': 0,

+                     'task_id': 15,

+                     'create_event': 32,

+                     'creation_time': datetime.datetime(2021, 3, 30, 12, 34, 5, 204023, tzinfo=psycopg2.tz.FixedOffsetTimezone(offset=0, name=None)),

+                     'create_ts': 1617107645.204023,

+                     'tag_id': 3,

+                     'tag_name': 'test-tag',

+                     'dist': False}

+         _singleRow.return_value = repo_row

+         rv = kojihub.repo_info(3)

+         self.assertEqual(rv, repo_row)

+ 

+     def test_get_repo(self):

+         rv = self.exports.getRepo(2)

+         self.assertEqual(len(self.queries), 1)

+         query = self.queries[0]

+         # make sure the following does not error

+         str(query)

+         self.assertEqual(query.tables, ['repo'])

+         columns = ['repo.id', 'repo.state', 'repo.task_id', 'repo.create_event',

+                    'EXTRACT(EPOCH FROM events.time)', 'repo.dist', 'events.time']

+         self.assertEqual(set(query.columns), set(columns))

+         self.assertEqual(query.joins, ['events ON repo.create_event = events.id'])

+         self.assertEqual(query.clauses, ['repo.dist is false', 'repo.state = %(state)s',

+                                          'repo.tag_id = %(id)i'])

@@ -186,13 +186,15 @@ 

  

      def test_prep_repo_init(self):

          protonmsg.prep_repo_init('postRepoInit', tag={'name': 'test-tag',

-             'arches': set(['x86_64', 'i386'])}, repo_id=1234)

-         self.assertMsg('repo.init', type='RepoInit', tag='test-tag', repo_id=1234)

+             'arches': set(['x86_64', 'i386'])}, repo_id=1234, task_id=25)

+         self.assertMsg('repo.init', type='RepoInit', tag='test-tag', repo_id=1234, task_id=25)

  

      def test_prep_repo_done(self):

-         protonmsg.prep_repo_done('postRepoDone', repo={'tag_name': 'test-tag', 'id': 1234},

+         protonmsg.prep_repo_done('postRepoDone',

+                                  repo={'tag_name': 'test-tag', 'id': 1234, 'task_id': 25},

                                   expire=False)

-         self.assertMsg('repo.done', type='RepoDone', tag='test-tag', repo_id=1234, expire=False)

+         self.assertMsg('repo.done', type='RepoDone', tag='test-tag', repo_id=1234,

+                        task_id=25, expire=False)

  

      @patch('protonmsg.Container')

      def test_send_queued_msgs_none(self, Container):

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

  <table>

    <tr><th>ID</th><td>$repo.id</td><th></tr>

    <tr><th>Tag</th><td><a href="taginfo?tagID=$repo.tag_id">$repo.tag_name</a></td></tr>

+   #if $repo.task_id

+   <tr><th>Task ID</th><td><a href="taskinfo?taskID=$repo.task_id">$repo.task_id</a></td></tr>

+   #end if

    #set $state = $util.repoState($repo.state)

    <tr><th>State</th><td class="repo$state">$state</td></tr>

    <tr><th>Event</th><td>$repo.create_event ($util.formatTimeLong($repo.create_ts))</td></tr>

It should be a keyword argument to not break backward compatibility. E.g. some plugin can use it.

rebased onto 6c462cb389a720112aee1f5a9686f0378a6e701b

a year ago

rebased onto 2f5cc7fe9332ac53aa2a880d3802ffe2e30126a6

a year ago

@tkopecek fixed and added task_id into protonmsg messages related to repoInit and repoDone.

Please, update also schema.sql

rebased onto 27017930d8b5fd1a32a0774b9651c42cd3708b56

a year ago

rebased onto 411859bab8d262149bd30068ca5e4ec05e4ae436

a year ago

Link should be displayed only if task_id is not null.

rebased onto f2d9e6c

a year ago

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

a year ago

Commit 8ab1981 fixes this pull-request

Pull-Request has been merged by tkopecek

a year ago

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

a year ago