#377 Do not treat ODCSComposeNotReady as error which fails ArtifactBuild.
Merged 4 years ago by jkaluza. Opened 4 years ago by jkaluza.
jkaluza/freshmaker errata-retry-kerberos  into  master

file modified
+34 -25
@@ -81,37 +81,46 @@ 

      return decorator

  

  

- def fail_artifact_build_on_handler_exception(func):

+ def fail_artifact_build_on_handler_exception(whitelist=None):

      """

      Decorator which marks the models.ArtifactBuild associated with handler by

      BaseHandler.set_context() as FAILED in case the `func` raises an

      exception.

  

      The exception is re-raised by this decorator once its finished.

-     """

-     @wraps(func)

-     def decorator(handler, *args, **kwargs):

-         try:

-             return func(handler, *args, **kwargs)

-         except Exception as e:

-             err = 'Could not process message handler. See the traceback.'

-             log.exception(err)

- 

-             # In case the exception interrupted the database transaction,

-             # rollback it.

-             db.session.rollback()

  

-             # Mark the event as failed.

-             build_id = handler.current_db_artifact_build_id

-             build = db.session.query(ArtifactBuild).filter_by(

-                 id=build_id).first()

-             if build:

-                 build.transition(

-                     ArtifactBuildState.FAILED.value, "Handling of "

-                     "build failed with traceback: %s" % (str(e)))

-                 db.session.commit()

-             raise

-     return decorator

+     :param list/set whitelist: When set, defines the whitelist of Exception

+         subclasses which do not cause the ArtifactBuild to fail but are instead

+         just re-raised.

+     """

+     def wrapper(func):

+         @wraps(func)

+         def decorator(handler, *args, **kwargs):

+             try:

+                 return func(handler, *args, **kwargs)

+             except Exception as e:

+                 if whitelist and type(e) in whitelist:

This if is the only code added here. Other changes are just in indentation.

+                     raise

+ 

+                 err = 'Could not process message handler. See the traceback.'

+                 log.exception(err)

+ 

+                 # In case the exception interrupted the database transaction,

+                 # rollback it.

+                 db.session.rollback()

+ 

+                 # Mark the event as failed.

+                 build_id = handler.current_db_artifact_build_id

+                 build = db.session.query(ArtifactBuild).filter_by(

+                     id=build_id).first()

+                 if build:

+                     build.transition(

+                         ArtifactBuildState.FAILED.value, "Handling of "

+                         "build failed with traceback: %s" % (str(e)))

+                     db.session.commit()

+                 raise

+         return decorator

+     return wrapper

  

  

  class BaseHandler(object):
@@ -445,7 +454,7 @@ 

                                             scratch=conf.koji_container_scratch_build,

                                             compose_ids=compose_ids)

  

-     @fail_artifact_build_on_handler_exception

+     @fail_artifact_build_on_handler_exception(whitelist=[ODCSComposeNotReady])

      def build_image_artifact_build(self, build, repo_urls=[]):

          """

          Submits ArtifactBuild of 'image' type to Koji.

file modified
+2
@@ -243,6 +243,8 @@ 

              handler = MyHandler()

              handler.build_image_artifact_build(self.build_1, ["http://localhost/x.repo"])

  

+         self.assertEqual(self.build_1.state, ArtifactBuildState.PLANNED.value)

+ 

  

  class TestAllowBuildBasedOnWhitelist(helpers.FreshmakerTestCase):

      """Test BaseHandler.allow_build"""

When compose is not done yet, the BaseHandler raises ODCSComposeNotReady
exception. This is supposed to be catched by the start_to_build_images,
which pauses the rebuild until the ODCS compose is ready.

The issue is that fail_artifact_build_on_handler_exception decorator
also catches this ODCSComposeNotReady exception and marks the ArtifactBuild
as FAILED. This is wrong, because ODCSComposeNotReady exception is expected
and should not mark the build as FAILED.

This commit fixes it by introducing the whitelist kwarg in the
fail_artifact_build_on_handler_exception decorator and whitelists
the ODCSComposeNotReady exception, so it does not move the build
to FAILED state, but instead just re-raises the exception so it
can be handled in start_to_build_images.

This if is the only code added here. Other changes are just in indentation.

Commit e0f1964 fixes this pull-request

Pull-Request has been merged by jkaluza

4 years ago

Pull-Request has been merged by jkaluza

4 years ago