#359 Tweak the BUILDING/COMPLETE Event state reasons to contain more useful info.
Merged 2 months ago by jkaluza. Opened 2 months ago by jkaluza.
jkaluza/freshmaker better-state-reason  into  master

@@ -100,6 +100,10 @@ 

          self.log_info("Found following Docker repositories updated by the advisory: %r",

                        docker_repos.keys())

  

+         # Count the number of impacted builds to show them in state reason

+         # when moving the Event to COMPLETE.

+         num_impacted = None

+ 

          # Submit rebuild request to Bob :).

          for repo_name in docker_repos.keys():

              self.log_info("Requesting Bob rebuild of %s", repo_name)

@@ -120,10 +124,18 @@ 

              resp = r.json()

              self.log_info("Response: %r", resp)

              if "impacted" in resp:

+                 if num_impacted is None:

+                     num_impacted = 0

+                 num_impacted += len(resp["impacted"])

                  for external_repo_name in resp["impacted"]:

                      self.record_build(

                          db_event, external_repo_name, ArtifactType.IMAGE_REPOSITORY,

                          state=ArtifactBuildState.DONE.value, dep_on=parent_build)

  

-         db_event.transition(EventState.COMPLETE)

+         msg = "Advisory %s: Informed Bob about update of %d image repositories." % (

+             db_event.search_key, len(docker_repos))

+         if num_impacted is not None:

+             msg += " Bob is rebuilding %d impacted external image repositories." % (

+                 num_impacted)

+         db_event.transition(EventState.COMPLETE, msg)

          db.session.commit()

@@ -147,13 +147,13 @@ 

          if num_failed:

              db_event.transition(

                  EventState.COMPLETE,

-                 '%d of %d container image(s) failed to rebuild.' % (

-                     num_failed, len(db_event.builds),))

+                 'Advisory %s: %d of %d container image(s) failed to rebuild.' % (

+                     db_event.search_key, num_failed, len(db_event.builds),))

          else:

              db_event.transition(

                  EventState.COMPLETE,

-                 'All %s container images have been rebuilt.' % (

-                     len(db_event.builds),))

+                 'Advisory %s: All %s container images have been rebuilt.' % (

+                     db_event.search_key, len(db_event.builds),))

  

      def _verify_advisory_rpms_in_container_build(self, errata_id, container_build_id):

          """

@@ -123,8 +123,8 @@ 

          self.start_to_build_images(

              db_event.get_image_builds_in_first_batch(db.session))

  

-         msg = ('Waiting for composes to finish in order to start to '

-                'schedule images for rebuild.')

+         msg = 'Advisory %s: Rebuilding %d container images.' % (

+             db_event.search_key, len(db_event.builds))

          db_event.transition(EventState.BUILDING, msg)

  

          return []

@@ -161,7 +161,7 @@ 

  

          self.assertEqual(EventState.COMPLETE.value,

                           self.db_advisory_rpm_signed_event.state)

-         self.assertEqual("1 of 4 container image(s) failed to rebuild.",

+         self.assertEqual("Advisory 12345: 1 of 4 container image(s) failed to rebuild.",

                           self.db_advisory_rpm_signed_event.state_reason)

  

      @mock.patch('freshmaker.handlers.ContainerBuildHandler.build_image_artifact_build')