#1151 Handle Koji communication errors
Merged 5 months ago by mprahl. Opened 5 months ago by vmaljulin.
vmaljulin/fm-orchestrator FACTORY-3651  into  master

@@ -35,11 +35,7 @@ 

  import string

  import kobo.rpmlib

  import threading

- try:

-     import xmlrpclib

- except ImportError:

-     import xmlrpc.client as xmlrpclib

- 

+ import six.moves.xmlrpc_client as xmlrpclib

  import munch

  from itertools import chain

  from OpenSSL.SSL import SysCallError

@@ -41,7 +41,7 @@ 

  from module_build_service.utils import to_text_type

  

  import koji

- 

+ import six.moves.xmlrpc_client as xmlrpclib

  import logging

  import os

  import time

@@ -145,6 +145,7 @@ 

              break

          time.sleep(1)

  

+     error_msg = ''

      try:

          mmd = build.mmd()

          record_component_builds(mmd, build, session=session)

@@ -155,18 +156,21 @@ 

      # Catch custom exceptions that we can expose to the user

      except (UnprocessableEntity, Forbidden, ValidationError, RuntimeError) as e:

          log.exception(str(e))

-         # Rollback changes underway

-         session.rollback()

-         build.transition(conf, models.BUILD_STATES["failed"], state_reason=str(e))

+         error_msg = str(e)

+     except (xmlrpclib.ProtocolError, koji.GenericError) as e:

+         log.exception(str(e))

+         error_msg = 'Koji communication error: "{0}"'.format(str(e))

      except Exception as e:

          log.exception(str(e))

-         # Rollback changes underway

-         session.rollback()

-         msg = "An unknown error occurred while validating the modulemd"

-         build.transition(conf, models.BUILD_STATES["failed"], state_reason=msg)

-     finally:

+         error_msg = "An unknown error occurred while validating the modulemd"

+     else:

          session.add(build)

          session.commit()

+     finally:

+         if error_msg:

+             # Rollback changes underway

+             session.rollback()

+             build.transition(conf, models.BUILD_STATES["failed"], state_reason=error_msg)

  

  

  def generate_module_build_koji_tag(build):

@@ -26,10 +26,7 @@ 

  import mock

  import koji

  

- try:

-     import xmlrpclib

- except ImportError:

-     import xmlrpc.client as xmlrpclib

+ import six.moves.xmlrpc_client as xmlrpclib

  from collections import OrderedDict

  from module_build_service.utils import to_text_type

  

This fixes #1105

Signed-off-by: Valerij Maljulin vmaljuli@redhat.com

P.S. Giving up creating a test for this :(

session.rollback() should be handled in a finally: clause.

1 new commit added

  • fixup! Handle Koji communication errors This fixes #1105
5 months ago

session.rollback() should be handled in a finally: clause.

Done

Is there an import from six that would do this for us? We already depend on it in this project so we might as well use it.

Is there an import from six that would do this for us? We already depend on it in this project so we might as well use it.

Done. Also replaced it everywhere.

pretty please pagure-ci rebuild

5 months ago

Pull-Request has been merged by mprahl

5 months ago