#4285 Improve min_event handling in RepoWatcher
Merged a month ago by tkopecek. Opened 2 months ago by mikem.
mikem/koji min_event_tweaks  into  master

file modified
+11 -5
@@ -152,13 +152,13 @@ 

          elif at_event is not None:

              raise koji.ParameterError('Cannot specify both min_event and at_event')

          elif min_event == "last":

-             # TODO pass through?

              self.min_event = session.tagLastChangeEvent(self.taginfo['id'])

          else:

              self.min_event = int(min_event)

          # if opts is None we'll get the default opts

          self.opts = opts

          self.logger = logger or logging.getLogger('koji')

+         self._task_request = None

  

      def get_start(self):

          # we don't want necessarily want to start the clock in init
@@ -191,7 +191,8 @@ 

              if self.check_repo(repoinfo):

                  return repoinfo

  

-         # TODO save our request to avoid duplication later

+         # save our request for use in task_args(), the builder code will call that next

+         self._task_request = check['request']

          # otherwise

          return None

  
@@ -199,12 +200,18 @@ 

          """Return args for a waitrepo task matching our data"""

          tag = self.taginfo['name']

          newer_than = None  # this legacy arg doesn't make sense for us

+         min_event = self.min_event

          if self.at_event:

              raise koji.GenericError('at_event not supported by waitrepo task')

+         if min_event is None:

+             # see if we can use value from request

+             req = self._task_request

+             if req:

+                 min_event = req['min_event']

          if self.opts:

              # TODO?

              raise koji.GenericError('opts not supported by waitrepo task')

-         return [tag, newer_than, self.nvrs, self.min_event]

+         return [tag, newer_than, self.nvrs, min_event]

  

      def waitrepo(self, anon=False):

          self.logger.info('Waiting on repo for %s', self.taginfo['name'])
@@ -227,9 +234,8 @@ 

                      # we should have waited for builds before creating the request

                      # this could indicate further tagging/untagging, or a bug

                      self.logger.error('Repo request did not satisfy conditions')

-             else:

+             elif anon:

                  # check for repo directly

-                 # either first pass or anon mode

                  repoinfo = self.session.repo.get(self.taginfo['id'], min_event=min_event,

                                                   at_event=self.at_event, opts=self.opts)

                  if repoinfo and self.check_repo(repoinfo):

@@ -93,6 +93,19 @@ 

          args = watcher.task_args()

          params = koji.tasks.parse_task_params('waitrepo', args)

  

+     def test_getRepo_task_req(self):

+         # make sure task_args reports expected min_event

+         req = {'id': 999, 'min_event': 54321}

+         self.session.repo.request.return_value = {'repo': None, 'request': req}

+         watcher = RepoWatcher(self.session, self.TAG)

+         result = watcher.getRepo()

+         self.assertEqual(result, None)

+ 

+         args = watcher.task_args()

+         # [tag, newer_than, nvrs, min_event]

+         expected = ['MY-TAG', None, [], 54321]

+         self.assertEqual(args, expected)

+ 

      def test_waitrepo_build_wait(self):

          self.session.repo.get.return_value = None

          # we'll pass with nvrs, so we should wait for builds before making request

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

2 months ago

Testing notes. To observe this issue, you'll need an existing state=ready repo for the build tag that is older than the hub's RepoLag setting. In that situation, the old code will report the old repo rather than creating a new request, e.g. using the koji request-repo command. This PR should fix that issue, so that the client waits for a new repo rather than using one that is older than the configured lag.

Addendum to the testing notes

you'll need an existing state=ready repo for the build tag that is older than the hub's RepoLag setting

Here I meant "older" in the sense of repo validity range. Every repo has a range of events where it accurately represents the tag contents. That is from begin_event until end_event. A still-valid repo will have end_event=None. Once there is a change to the tag, the repo will be marked with the appropriate end_event.

So, as far as lag is concerned, the age we're concerned about is how long it has been since the repo became invalid. I.e. the time since the end event (or now - end_ts).

To create this situation, you'll need to make a change to the tag and make sure that the end events have been updated (kojira triggers this normally, but an admin can also call repo.updateEndEvents directly)

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

a month ago

Commit 5e1584e fixes this pull-request

Pull-Request has been merged by tkopecek

a month ago